From 05c38e2b7c17d9a41b4d0321216a2f14d72f4565 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 5 Jul 2008 22:46:31 +0000 Subject: [PATCH] MDL-13811 reworked unsetting of preferences and minor tweaks --- lang/en_utf8/auth.php | 2 +- user/edit.php | 15 +++++---------- user/editlib.php | 24 +++++++++++++++++++----- user/emailupdate.php | 22 +++++++--------------- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/lang/en_utf8/auth.php b/lang/en_utf8/auth.php index 2a3c1651fd..da55ac5e48 100644 --- a/lang/en_utf8/auth.php +++ b/lang/en_utf8/auth.php @@ -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 $a->fullname was successfully updated to $a->email.'; $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.'; diff --git a/user/edit.php b/user/edit.php index 79814bc4cf..b88fdd0c2f 100644 --- a/user/edit.php +++ b/user/edit.php @@ -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); diff --git a/user/editlib.php b/user/editlib.php index d67d178650..1c97f65d2c 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -1,10 +1,24 @@ 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'); diff --git a/user/emailupdate.php b/user/emailupdate.php index 93da578fc4..6a6801349c 100755 --- a/user/emailupdate.php +++ b/user/emailupdate.php @@ -1,6 +1,7 @@ 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'); -- 2.39.5