Witam,
jestem tutaj nowy i początkujący więc proszę o wyrozumiałość.Mam problem ponieważ mam skrypty php które pochodzą z moodli wer.1.9.12 i chciałbym zrobić coś takiego żeby przy każdym wylogowaniu zostało automatycznie generowane nowe hasło dla wszystkich użytkowników(z wyjątkiem admina) i wysyłane na maila.Czy może mi ktoś pomóc bo zupełnie nie mogę ogarnąć tego kodu-moodle jest potężną platformą.
Czy to w pliku logout.php trzebaby dopisać taką funkcę i w którym miejscu?Jak ta funkcja miałaby wyglądać?Może jakieś linki ktoś mógłby podać jako przykład?!Bardzo serdecznie proszę o pomoc.pozdrawiam
logout.php
<?php // $Id: logout.php,v 1.25 2007/05/15 21:13:23 skodak Exp $
// Logs the user out and sends them to the home page
require_once("../config.php");
// can be overriden by auth plugins
$redirect = $CFG->wwwroot.'/';
$sesskey = optional_param('sesskey', '__notpresent__', PARAM_RAW); // we want not null default to prevent required sesskey warning
if (!isloggedin()) {
// no confirmation, user has already logged out
require_logout();
redirect($redirect);
} else if (!confirm_sesskey($sesskey)) {
print_header($SITE->fullname, $SITE->fullname, 'home');
notice_yesno
(get_string
('logoutconfirm'), 'logout.php', $CFG->wwwroot.'/', array('sesskey'=>sesskey
()), null, 'post', 'get'); print_footer();
}
$authsequence = get_enabled_auth_plugins(); // auths, in sequence
foreach($authsequence as $authname) {
$authplugin = get_auth_plugin($authname);
$authplugin->logoutpage_hook();
}
require_logout();
redirect($redirect);
?>
forgot_password.php
<?php
// $Id: forgot_password.php,v 1.45.2.4 2008/12/01 22:37:12 skodak Exp $
// forgot password routine.
// find the user and call the appropriate routine for their authentication
// type.
require_once('../config.php');
require_once('forgot_password_form.php');
$p_secret = optional_param('p', false, PARAM_RAW);
$p_username = optional_param('s', false, PARAM_RAW);
httpsrequired();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
// setup text strings
$strforgotten = get_string('passwordforgotten');
$strlogin = get_string('login');
$navigation = build_navigation
(array(array('name' => $strlogin, 'link' => "$CFG->wwwroot/login/index.php", 'type' => 'misc'), array('name' => $strforgotten, 'link' => null, 'type' => 'misc')));
// if alternatepasswordurl is defined, then we'll just head there
if (!empty($CFG->forgottenpasswordurl)) { redirect($CFG->forgottenpasswordurl);
}
// if you are logged in then you shouldn't be here!
if (isloggedin() and !isguestuser()) {
redirect($CFG->wwwroot.'/index.php', get_string('loginalready'), 5);
}
if ($p_secret !== false) {
///=====================
/// user clicked on link in email message
///=====================
update_login_count();
$user = get_complete_user_data('username', $p_username);
if (!empty($user) and
$user->secret === '') { print_header($strforgotten, $strforgotten, $navigation);
print_error('secretalreadyused');
// make sure that url relates to a valid user
// check this isn't guest user
if (isguestuser($user)) {
error('You cannot reset the guest password');
}
// make sure user is allowed to change password
require_capability('moodle/user:changeownpassword', $systemcontext, $user->id);
// override email stop and mail new password
$user->emailstop = 0;
if (!reset_password_and_mail($user)) {
error('Error resetting password and mailing you');
}
// Clear secret so that it can not be used again
$user->secret = '';
if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
error('Error resetting user secret string');
}
reset_login_count();
$changepasswordurl = "{$CFG->httpswwwroot}/login/change_password.php";
$a = new object();
$a->email = $user->email;
$a->link = $changepasswordurl;
print_header($strforgotten, $strforgotten, $navigation);
notice(get_string('emailpasswordsent', '', $a), $changepasswordurl);
} else {
// somebody probably tries to hack in by guessing secret - stop them!
set_field('user', 'secret', '', 'id', $user->id);
}
print_header($strforgotten, $strforgotten, $navigation);
print_error('forgotteninvalidurl');
}
}
$mform = new login_forgot_password_form();
if ($mform->is_cancelled()) {
redirect($CFG->httpswwwroot.'/login/index.php');
} else if ($data = $mform->get_data()) {
/// find the user in the database and mail info
// first try the username
if (!empty($data->username)) { $user = get_complete_user_data('username', $data->username);
} else {
$user = get_complete_user_data('email', $data->email);
}
if ($user and
!empty($user->confirmed)) {
$userauth = get_auth_plugin($user->auth);
if (has_capability('moodle/user:changeownpassword', $systemcontext, $user->id)) {
// send email (make sure mail block is off)
$user->emailstop = 0;
}
if ($userauth->can_reset_password() and is_enabled_auth($user->auth)
and has_capability('moodle/user:changeownpassword', $systemcontext, $user->id)) {
// send reset password confirmation
// set 'secret' string
$user->secret = random_string(15);
if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
error('error setting user secret string');
}
if (!send_password_change_confirmation_email($user)) {
error('error sending password change confirmation email');
}
} else {
if (!send_password_change_info($user)) {
error('error sending password change confirmation email');
}
}
}
print_header($strforgotten, $strforgotten, $navigation);
if (empty($user->email) or
!empty($CFG->protectusernames)) { // Print general confirmation message
notice(get_string('emailpasswordconfirmmaybesent'), $CFG->wwwroot.'/index.php');
} else {
// Confirm email sent
$protectedemail = preg_replace('/([^@]*)@(.*)/', '******@$2', $user->email); // obfuscate the email address to protect privacy $stremailpasswordconfirmsent = get_string('emailpasswordconfirmsent', '', $protectedemail);
notice($stremailpasswordconfirmsent, $CFG->wwwroot.'/index.php');
}
}
/// DISPLAY FORM
print_header($strforgotten, $strforgotten, $navigation, 'id_email');
print_box(get_string('passwordforgotteninstructions'), 'generalbox boxwidthnormal boxaligncenter');
$mform->display();
print_footer();
?>
forgot_password_form.php
<?php //$Id: forgot_password_form.php,v 1.7.2.1 2007/11/23 22:12:35 skodak Exp $
require_once $CFG->libdir.'/formslib.php';
class login_forgot_password_form extends moodleform {
function definition() {
$mform =& $this->_form;
$renderer =& $mform->defaultRenderer();
$mform->addElement('header', '', get_string('passwordforgotten'), '');
$mform->addElement('text', 'username', get_string('username'));
$mform->setType('username', PARAM_RAW);
$mform->addElement('text', 'email', get_string('email'));
$mform->setType('email', PARAM_RAW);
$this->add_action_buttons(true, get_string('ok'));
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
if ((!empty($data['username']) and
!empty($data['email'])) or
(empty($data['username']) and
empty($data['email']))) { $errors['username'] = get_string('usernameoremail');
$errors['email'] = get_string('usernameoremail');
} else if (!empty($data['email'])) { if (!validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else if (count_records('user', 'email', $data['email']) > 1) {
$errors['email'] = get_string('forgottenduplicate');
} else {
if ($user = get_complete_user_data('email', $data['email'])) {
if (empty($user->confirmed)) { $errors['email'] = get_string('confirmednot');
}
}
if (!$user and
empty($CFG->protectusernames)) { $errors['email'] = get_string('emailnotfound');
}
}
} else {
if ($user = get_complete_user_data('username', $data['username'])) {
if (empty($user->confirmed)) { $errors['email'] = get_string('confirmednot');
}
}
if (!$user and
empty($CFG->protectusernames)) { $errors['username'] = get_string('usernamenotfound');
}
}
return $errors;
}
}
?>