Add some comments
This commit is contained in:
parent
acb3ffd66d
commit
f9ad660379
1 changed files with 6 additions and 0 deletions
6
auth.php
6
auth.php
|
@ -134,11 +134,14 @@ class auth_plugin_userkey extends auth_plugin_base {
|
||||||
/**
|
/**
|
||||||
* Logs a user in using userkey and redirects after.
|
* Logs a user in using userkey and redirects after.
|
||||||
*
|
*
|
||||||
|
* @TODO: refactor this method to make it easy to read.
|
||||||
|
*
|
||||||
* @throws \moodle_exception If something went wrong.
|
* @throws \moodle_exception If something went wrong.
|
||||||
*/
|
*/
|
||||||
public function user_login_userkey() {
|
public function user_login_userkey() {
|
||||||
global $SESSION, $CFG, $USER;
|
global $SESSION, $CFG, $USER;
|
||||||
|
|
||||||
|
|
||||||
$keyvalue = required_param('key', PARAM_ALPHANUM);
|
$keyvalue = required_param('key', PARAM_ALPHANUM);
|
||||||
$wantsurl = optional_param('wantsurl', '', PARAM_URL);
|
$wantsurl = optional_param('wantsurl', '', PARAM_URL);
|
||||||
|
|
||||||
|
@ -151,6 +154,7 @@ class auth_plugin_userkey extends auth_plugin_base {
|
||||||
try {
|
try {
|
||||||
$key = $this->userkeymanager->validate_key($keyvalue);
|
$key = $this->userkeymanager->validate_key($keyvalue);
|
||||||
} catch (moodle_exception $exception) {
|
} catch (moodle_exception $exception) {
|
||||||
|
// If user is logged in and key is not valid, we'd like to logout a user.
|
||||||
if (isloggedin()) {
|
if (isloggedin()) {
|
||||||
require_logout();
|
require_logout();
|
||||||
}
|
}
|
||||||
|
@ -159,8 +163,10 @@ class auth_plugin_userkey extends auth_plugin_base {
|
||||||
|
|
||||||
if (isloggedin()) {
|
if (isloggedin()) {
|
||||||
if ($USER->id != $key->userid) {
|
if ($USER->id != $key->userid) {
|
||||||
|
// Logout the current user if it's different to one that associated to the valid key.
|
||||||
require_logout();
|
require_logout();
|
||||||
} else {
|
} else {
|
||||||
|
// Don't process further if the user is already logged in.
|
||||||
$this->userkeymanager->delete_keys($key->userid);
|
$this->userkeymanager->delete_keys($key->userid);
|
||||||
$this->redirect($redirecturl);
|
$this->redirect($redirecturl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue