mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-58774-master-fix' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
3227ac8374
2 changed files with 26 additions and 3 deletions
|
@ -105,7 +105,7 @@ class api {
|
||||||
$userid = $USER->id;
|
$userid = $USER->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linked_login::count_records(['username' => $userinfo['username']]) > 0) {
|
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
|
||||||
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class api {
|
||||||
$record->issuerid = $issuer->get('id');
|
$record->issuerid = $issuer->get('id');
|
||||||
$record->username = $userinfo['username'];
|
$record->username = $userinfo['username'];
|
||||||
$record->userid = $userid;
|
$record->userid = $userid;
|
||||||
if (linked_login::count_records(['username' => $userinfo['username']]) > 0) {
|
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
|
||||||
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
||||||
}
|
}
|
||||||
$record->email = $userinfo['email'];
|
$record->email = $userinfo['email'];
|
||||||
|
@ -242,7 +242,7 @@ class api {
|
||||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||||
require_once($CFG->dirroot.'/user/lib.php');
|
require_once($CFG->dirroot.'/user/lib.php');
|
||||||
|
|
||||||
if (linked_login::count_records(['username' => $userinfo['username']]) > 0) {
|
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
|
||||||
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
throw new moodle_exception('alreadylinked', 'auth_oauth2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,4 +65,27 @@ class linked_login extends persistent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether there are any valid linked accounts for this issuer
|
||||||
|
* and username combination.
|
||||||
|
*
|
||||||
|
* @param \core\oauth2\issuer $issuer The issuer
|
||||||
|
* @param string $username The username to check
|
||||||
|
*/
|
||||||
|
public static function has_existing_issuer_match(\core\oauth2\issuer $issuer, $username) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$where = "issuerid = :issuerid
|
||||||
|
AND username = :username
|
||||||
|
AND (confirmtokenexpires = 0 OR confirmtokenexpires > :maxexpiry)";
|
||||||
|
|
||||||
|
$count = $DB->count_records_select(static::TABLE, $where, [
|
||||||
|
'issuerid' => $issuer->get('id'),
|
||||||
|
'username' => $username,
|
||||||
|
'maxexpiry' => (new \DateTime('NOW'))->getTimestamp(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue