mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-20846 creating users on restore - part2 - hack login to inform and
allow 'restored' users to reset their password. Merged from 19_STABLE
This commit is contained in:
parent
2871c45070
commit
e58269e4fa
@ -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
|
||||
*
|
||||
|
@ -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");
|
||||
|
29
login/restored_password_form.php
Normal file
29
login/restored_password_form.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// This is one "supplanter" form that generates
|
||||
// one correct forgot_password.php request in
|
||||
// order to get the mailout for 'restored' users
|
||||
// working automatically without having to
|
||||
// fill the form manually (the user already has
|
||||
// filled the username and it has been detected
|
||||
// as a 'restored' one. Surely, some day this will
|
||||
// be out, with the forgot_password utility being
|
||||
// part of each plugin, but now now. See MDL-20846
|
||||
// for the rationale for this implementation.
|
||||
|
||||
require_once $CFG->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'));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user