Commit 222681d4 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1749339: Add pre_loginpage_hooks"

parents 6b06c240 bfdba337
......@@ -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