From d74030410c833aa16cdc7a19bcc792c884413bd6 Mon Sep 17 00:00:00 2001 From: Dashamir Hoxha Date: Sat, 18 Feb 2017 22:53:04 +0000 Subject: [PATCH] To be able to login even if the auth method is different (fix https://github.com/mouneyrac/moodle-auth_googleoauth2/issues/79) --- auth.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/auth.php b/auth.php index 9b06144..ce49332 100644 --- a/auth.php +++ b/auth.php @@ -269,6 +269,10 @@ public function loginpage_hook() { create_user_record($username, '', 'googleoauth2'); } else { $username = $user->username; + // To be able to login even if the auth method is different. + $old_authmethod = $user->auth; + $old_password = $user->password; + $DB->set_field('user', 'auth', 'googleoauth2', array('id'=>$user->id)); } // Authenticate the user. @@ -277,6 +281,11 @@ public function loginpage_hook() { $userid = empty($user) ? 'new user' : $user->id; oauth_add_to_log(SITEID, 'auth_googleoauth2', '', '', $username . '/' . $useremail . '/' . $userid); $user = authenticate_user_login($username, null); + // To be able to login even if the auth method is different. + if (isset($old_authmethod)) { + $DB->set_field('user', 'auth', $old_authmethod, array('id'=>$userid)); + $DB->set_field('user', 'password', $old_password, array('id'=>$userid)); + } if ($user) { // Set a cookie to remember what auth provider was selected.