Skip to content

Commit

Permalink
Merge branch 'eugene-auth-email-wantsurl' of https://github.com/bynar…
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Apr 3, 2018
2 parents f16b871 + feb23f1 commit 73582bd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions auth/email/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function user_signup($user, $notify=true) {
* @since Moodle 3.2
*/
public function user_signup_with_confirmation($user, $notify=true, $confirmationurl = null) {
global $CFG, $DB;
global $CFG, $DB, $SESSION;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');

Expand All @@ -130,6 +130,11 @@ public function user_signup_with_confirmation($user, $notify=true, $confirmation
// Save any custom profile field information.
profile_save_data($user);

// Save wantsurl against user's profile, so we can return them there upon confirmation.
if (!empty($SESSION->wantsurl)) {
set_user_preference('auth_email_wantsurl', $SESSION->wantsurl, $user);
}

// Trigger event.
\core\event\user_created::create_from_userid($user->id)->trigger();

Expand Down Expand Up @@ -166,7 +171,7 @@ function can_confirm() {
* @param string $confirmsecret
*/
function user_confirm($username, $confirmsecret) {
global $DB;
global $DB, $SESSION;
$user = get_complete_user_data('username', $username);

if (!empty($user)) {
Expand All @@ -178,6 +183,13 @@ function user_confirm($username, $confirmsecret) {

} else if ($user->secret == $confirmsecret) { // They have provided the secret key to get in
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));

if ($wantsurl = get_user_preferences('auth_email_wantsurl', false, $user)) {
// Ensure user gets returned to page they were trying to access before signing up.
$SESSION->wantsurl = $wantsurl;
unset_user_preference('auth_email_wantsurl', $user);
}

return AUTH_CONFIRM_OK;
}
} else {
Expand Down

0 comments on commit 73582bd

Please sign in to comment.