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
*
$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) {
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");
--- /dev/null
+<?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'));
+ }
+
+}