$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.';
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);
<?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;
+ }
}
}
}
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');
<?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);
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
} 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;
}
}
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');