MDL-13811 reworked unsetting of preferences and minor tweaks

This commit is contained in:
skodak
2008-07-05 22:46:31 +00:00
parent 4692da473f
commit 05c38e2b7c
4 changed files with 32 additions and 31 deletions
+1 -1
View 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.';
+5 -10
View File
@@ -35,16 +35,6 @@
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');
@@ -96,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, $DB;
$user = $DB->get_record('user', array('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 = $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');