From e58269e4fafbfb1cc89185028eea916b466bb6dd Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Wed, 18 Nov 2009 01:05:58 +0000 Subject: [PATCH] MDL-20846 creating users on restore - part2 - hack login to inform and allow 'restored' users to reset their password. Merged from 19_STABLE --- lib/moodlelib.php | 17 +++++++++++++++++ login/index.php | 17 ++++++++++++++++- login/restored_password_form.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 login/restored_password_form.php diff --git a/lib/moodlelib.php b/lib/moodlelib.php index f0b43b7d82..438485b76e 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3214,6 +3214,23 @@ function is_internal_auth($auth) { return $authplugin->is_internal(); } +/** + * Returns true if the user is a 'restored' one + * + * Used in the login process to inform the user + * and allow him/her to reset the password + * + * @uses $CFG + * @uses $DB + * @param string $username username to be checked + * @return bool + */ +function is_restored_user($username) { + global $CFG, $DB; + + return $DB->record_exists('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id, 'password'=>'restored')); +} + /** * Returns an array of user fields * diff --git a/login/index.php b/login/index.php index 2f102694ba..52ac5b5a92 100644 --- a/login/index.php +++ b/login/index.php @@ -133,6 +133,21 @@ if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) { / $user = authenticate_user_login($frm->username, $frm->password); } } + + // Intercept 'restored' users to provide them with info & reset password + if (!$user and $frm and is_restored_user($frm->username)) { + $PAGE->set_title(get_string('restoredaccount')); + $PAGE->set_heading($site->fullname); + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('restoredaccount')); + echo $OUTPUT->box(get_string('restoredaccountinfo'), 'generalbox boxaligncenter'); + require_once('restored_password_form.php'); // Use our "supplanter" login_forgot_password_form. MDL-20846 + $form = new login_forgot_password_form('forgot_password.php', array('username' => $frm->username)); + $form->display(); + echo $OUTPUT->footer(); + die; + } + update_login_count(); if ($user) { @@ -149,7 +164,7 @@ if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) { / if (empty($user->confirmed)) { // This account was never confirmed $PAGE->set_title(get_string("mustconfirm")); - $PAGE->set_heading(get_string("mustconfirm")); + $PAGE->set_heading($site->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string("mustconfirm")); echo $OUTPUT->box(get_string("emailconfirmsent", "", $user->email), "generalbox boxaligncenter"); diff --git a/login/restored_password_form.php b/login/restored_password_form.php new file mode 100644 index 0000000000..76ecd5186d --- /dev/null +++ b/login/restored_password_form.php @@ -0,0 +1,29 @@ +libdir.'/formslib.php'; + +class login_forgot_password_form extends moodleform { + + function definition() { + $mform =& $this->_form; + + $username = $this->_customdata['username']; + + $mform->addElement('hidden', 'username', $username); + $mform->setType('username', PARAM_RAW); + + $this->add_action_buttons(false, get_string('continue')); + } + +} -- 2.39.5