]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13811 reworked unsetting of preferences and minor tweaks
authorskodak <skodak>
Sat, 5 Jul 2008 22:46:31 +0000 (22:46 +0000)
committerskodak <skodak>
Sat, 5 Jul 2008 22:46:31 +0000 (22:46 +0000)
lang/en_utf8/auth.php
user/edit.php
user/editlib.php
user/emailupdate.php

index 2a3c1651fd8440041704d31db98014abed91dab1..da55ac5e48969e1322fb643b9c886906a25725ab 100644 (file)
@@ -128,7 +128,7 @@ You have requested a change of your email address for your user account at $a->s
 $a->url';
 $string['auth_emailupdatetitle'] = 'Confirmation of email update at $a->site';
 $string['auth_invalidnewemailkey'] = 'Error: if you are trying to confirm a change of email address, you may have made a mistake in copying the URL we sent you by email. Please copy the address and try again.';
-$string['auth_emailupdatesuccess'] = 'Your email address was successfully updated to $a->email.';
+$string['auth_emailupdatesuccess'] = 'Email address of user <em>$a->fullname</em> was successfully updated to <em>$a->email</em>.';
 $string['auth_outofnewemailupdateattempts'] = 'You have run out of allowed attempts to update your email address. Your update request has been cancelled.';
 $string['auth_emailupdate'] = 'Email address update';
 $string['auth_changingemailaddress'] = 'You have requested a change of email address, from $a->oldemail to $a->newemail. For security reasons, we are sending you an email message at the new address to confirm that it belongs to you. Your email address will be updated as soon as you open the URL sent to you in that message.';
index 79814bc4cff57eac20d16080b73e261d00097e83..b88fdd0c2fa74cc35fa66b591acfb3c5c8a56d0d 100644 (file)
         print_error('invaliduserid');
     }
 
-    // Process email change cancellation
-    if ($cancelemailchange) {
-        useredit_load_preferences($user);
-        $user->preference_newemail = null;
-        $user->preference_newemailkey = null;
-        $user->preference_newemailattemptsleft = null;
-        useredit_update_user_preference($user);
-    }
-
-
     // Guest can not be edited
     if (isguestuser($user)) {
         print_error('guestnoeditprofile');
         die;
     }
 
+    // Process email change cancellation
+    if ($cancelemailchange) {
+        cancel_email_update($user->id);
+    }
+
     //load user preferences
     useredit_load_preferences($user);
 
index d67d17865049c075eb1d76612d905294e451620c..1c97f65d2cbf10d9a926b041d188e77c034c7dfe 100644 (file)
@@ -1,10 +1,24 @@
 <?php  //$Id$
 
+function cancel_email_update($userid) {
+    unset_user_preference('newemail', $userid);
+    unset_user_preference('newemailkey', $userid);
+    unset_user_preference('newemailattemptsleft', $userid);
+}
+
+function useredit_load_preferences(&$user, $reload=true) {
+    global $USER;
 
-function useredit_load_preferences(&$user) {
-    if (!empty($user->id) and $preferences = get_user_preferences(null, null, $user->id)) {
-        foreach($preferences as $name=>$value) {
-            $user->{'preference_'.$name} = $value;
+    if (!empty($user->id)) {
+        if ($reload and $USER->id == $user->id) {
+            // reload preferences in case it was changed in other session
+            unset($USER->preference);
+        }
+        
+        if ($preferences = get_user_preferences(null, null, $user->id)) {
+            foreach($preferences as $name=>$value) {
+                $user->{'preference_'.$name} = $value;
+            }
         }
     }
 }
@@ -62,7 +76,7 @@ function useredit_shared_definition(&$mform) {
     global $CFG, $USER, $DB;
 
     $user = $DB->get_record('user', array('id' => $USER->id));
-    useredit_load_preferences($user);
+    useredit_load_preferences($user, false);
 
     $strrequired = get_string('required');
 
index 93da578fc43ef0d641a5c70961b20db1ca4f8eaa..6a6801349c6c23f606d9e7db21aa60c739b7d946 100755 (executable)
@@ -1,6 +1,7 @@
 <?php // $Id$
 require_once('../config.php');
 require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->dirroot.'/user/editlib.php');
 
 $key = required_param('key', PARAM_ALPHANUM);
 $id  = required_param('id', PARAM_INT);
@@ -9,30 +10,28 @@ if (!$user = $DB->get_record('user', array('id' => $id))) {
     error("Unknown user ID");
 }
 
-$preferences = get_user_preferences(null, null, $id);
+$preferences = get_user_preferences(null, null, $user->id);
 $a = new stdClass();
 $a->fullname = fullname($user, true);
 $stremailupdate = get_string('auth_emailupdate', 'auth', $a);
 print_header(format_string($SITE->fullname) . ": $stremailupdate", format_string($SITE->fullname) . ": $stremailupdate");
 
-$cancel_email_update = false;
-
 if (empty($preferences['newemailattemptsleft'])) {
     redirect("$CFG->wwwroot/user/view.php?id=$user->id");
 
 } elseif ($preferences['newemailattemptsleft'] < 1) {
-    $cancel_email_update = true;
+    cancel_email_update($user->id);
     $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
     print_box($stroutofattempts, 'center');
 
 } elseif ($key == $preferences['newemailkey']) {
+    cancel_email_update($user->id);
     $user->email = $preferences['newemail'];
 
     // Detect duplicate before saving
     if ($DB->get_record('user', array('email' => $user->email))) {
         $stremailnowexists = get_string('auth_emailnowexists', 'auth');
         print_box($stremailnowexists, 'center');
-        $cancel_email_update = true;
         print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
     } else {
         // update user email
@@ -41,11 +40,10 @@ if (empty($preferences['newemailattemptsleft'])) {
 
         } else {
             events_trigger('user_updated', $user);
-            $stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $user);
+            $a->email = $user->email;
+            $stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $a);
             print_box($stremailupdatesuccess, 'center');
             print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
-
-            $cancel_email_update = true;
         }
     }
 
@@ -56,10 +54,4 @@ if (empty($preferences['newemailattemptsleft'])) {
     print_box($strinvalidkey, 'center');
 }
 
-if ($cancel_email_update) {
-    require_once($CFG->dirroot . '/user/editlib.php');
-    $user->preference_newemail = null;
-    $user->preference_newemailkey = null;
-    $user->preference_newemailattemptsleft = null;
-    useredit_update_user_preference($user);
-}
+print_footer('none');