MDL-13811 reworked unsetting of preferences and minor tweaks; backported from HEAD

This commit is contained in:
skodak
2008-07-05 22:46:58 +00:00
parent 9a6741db31
commit 73db4aa6f3
4 changed files with 32 additions and 30 deletions
+1 -1
View File
@@ -130,7 +130,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.';
+5 -9
View File
@@ -35,15 +35,6 @@
error('User ID was incorrect');
}
// 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');
@@ -95,6 +86,11 @@
die;
}
// Process email change cancellation
if ($cancelemailchange) {
cancel_email_update($user->id);
}
//load user preferences
useredit_load_preferences($user);
+19 -5
View 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) {
if (!empty($user->id) and $preferences = get_user_preferences(null, null, $user->id)) {
foreach($preferences as $name=>$value) {
$user->{'preference_'.$name} = $value;
function useredit_load_preferences(&$user, $reload=true) {
global $USER;
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;
$user = get_record('user', 'id', $USER->id);
useredit_load_preferences($user);
useredit_load_preferences($user, false);
$strrequired = get_string('required');
+7 -15
View File
@@ -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 = get_record('user', '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 (get_record('user', 'email', addslashes($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');