Commit bfdba337 authored by Daniel Thee Roperto's avatar Daniel Thee Roperto Committed by Robert Lyon
Browse files

Bug 1749339: Add pre_loginpage_hooks

 Add a pre-login hook to check if user is already logged in,
 giving each auth plugin the chance to authenticate or redirect the user as
 needed.

behatnotneeded

Change-Id: I690fd174a02e9ffd26b8e3c8f3efad041b54d3da
parent df539084
......@@ -523,6 +523,11 @@ function auth_setup () {
return;
}
// Allow auth plugins to try logging in the user.
if (auth_plugins_call_pre_loginpage_hook()) {
return;
}
// Check if the page is public or the site is configured to be public.
if (defined('PUBLIC') && !param_exists('login')) {
return;
......@@ -538,6 +543,39 @@ function auth_setup () {
}
}
/**
* Allow auth plugins a chance to authenticate or redirect as needed.
*
* It will call the 'pre_loginpage_hook' for each auth plugin available,
* if any of them completes the login it returns immediately.
*
* Similar to: https://tracker.moodle.org/browse/MDL-48887
*
* @return bool If any plugin authenticated the user.
*/
function auth_plugins_call_pre_loginpage_hook() {
global $USER;
$methodname = 'pre_loginpage_hook';
$instances = auth_get_auth_instances();
foreach ($instances as $instance) {
$auth = AuthFactory::create($instance->id);
if ($auth === false) {
continue;
}
if (!method_exists($auth, $methodname)) {
continue;
}
$auth->$methodname();
if ($USER->is_logged_in()) {
return true;
}
}
return false;
}
/**
*
* Returns all auth instances
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment