add HOOK_VALIDATE_SESSION

This commit is contained in:
Andrew Dolgov 2024-02-21 22:13:23 +03:00
parent fc95c988cf
commit 81f3139992
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
3 changed files with 25 additions and 0 deletions

View File

@ -706,4 +706,11 @@ abstract class Plugin {
function hook_loginform_additional_buttons() {
user_error("Dummy method invoked.", E_USER_ERROR);
}
/** Returns false if session is considered invalid, true cascades to next handler */
function hook_validate_session(): bool {
user_error("Dummy method invoked.", E_USER_ERROR);
return false;
}
}

View File

@ -199,6 +199,9 @@ class PluginHost {
/** @see Plugin::hook_loginform_additional_buttons() */
const HOOK_LOGINFORM_ADDITIONAL_BUTTONS = "hook_loginform_additional_buttons";
/** @see Plugin::hook_validate_session() */
const HOOK_VALIDATE_SESSION = "hook_validate_session";
const KIND_ALL = 1;
const KIND_SYSTEM = 2;
const KIND_USER = 3;

View File

@ -49,6 +49,21 @@
$_SESSION["login_error_msg"] = __("Session failed to validate (account is disabled)");
return false;
}
// default to true because there might not be any hooks and this is our last check
$hook_result = true;
\PluginHost::getInstance()->chain_hooks_callback(\PluginHost::HOOK_VALIDATE_SESSION,
function ($result) use (&$hook_result) {
$hook_result = $result;
if (!$result) {
return true;
}
});
return $hook_result;
} else {
$_SESSION["login_error_msg"] = __("Session failed to validate (user not found)");
return false;