]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20846 creating users on restore - part2 - hack login to inform and
authorEloy Lafuente <stronk7@moodle.org>
Wed, 18 Nov 2009 01:05:58 +0000 (01:05 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Wed, 18 Nov 2009 01:05:58 +0000 (01:05 +0000)
allow 'restored' users to reset their password. Merged from 19_STABLE

lib/moodlelib.php
login/index.php
login/restored_password_form.php [new file with mode: 0644]

index f0b43b7d82fc1afd3aed26ac17ca164bda9421aa..438485b76eeeb89973e183579ce8e5c7c52f255e 100644 (file)
@@ -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
  *
index 2f102694ba12471efb0d8b5c3323e4cd3df29670..52ac5b5a92e24459665e9a980277787dfb0e09f3 100644 (file)
@@ -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 (file)
index 0000000..76ecd51
--- /dev/null
@@ -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'));
+    }
+
+}