MDL-58220 auth_oauth2: Fix for login via linked login

This was broken by the refactoring to always link logins. Some of the static
variables could also be removed but I'll do that in a later issue to keep this patch small.
This commit is contained in:
Damyon Wiese 2017-04-05 15:54:20 +08:00
parent a647e7d762
commit f331513347

View File

@ -518,28 +518,15 @@ class auth extends \auth_plugin_base {
$message = get_string('emailconfirmsent', '', $userinfo['email']); $message = get_string('emailconfirmsent', '', $userinfo['email']);
$this->print_confirm_required($emailconfirm, $message); $this->print_confirm_required($emailconfirm, $message);
exit(); exit();
} }
} }
// If we got to here - we must have found a real user account that is confirmed. // We used to call authenticate_user - but that won't work if the current user has a different default authentication
$this->set_static_user_info($userinfo); // method. Since we now ALWAYS link a login - if we get to here we can directly allow the user in.
$user = authenticate_user_login($userinfo['username'], ''); $user = (object) $userinfo;
complete_user_login($user);
if ($user) { $this->update_picture($user);
complete_user_login($user); redirect($redirecturl);
$this->update_picture($user);
redirect($redirecturl);
}
// Trigger login failed event.
$failurereason = AUTH_LOGIN_FAILED;
$event = \core\event\user_login_failed::create(['other' => ['username' => $userinfo['username'],
'reason' => $failurereason]]);
$event->trigger();
$errormsg = get_string('notloggedindebug', 'auth_oauth2', get_string('loginerror_authenticationfailed', 'auth_oauth2'));
$SESSION->loginerrormsg = $errormsg;
redirect(new moodle_url($CFG->httpswwwroot . '/login/index.php'));
} }
} }