* add HOOK_LOGINFORM_ADDITIONAL_BUTTONS

* allow plugins to inject JS code into login form
This commit is contained in:
Andrew Dolgov 2022-07-24 16:33:28 +03:00
parent c0385c2098
commit 7c45b3f789
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
3 changed files with 39 additions and 0 deletions

View File

@ -49,6 +49,11 @@ abstract class Plugin {
return "";
}
/** @return string */
function get_login_js() {
return "";
}
/** @return string */
function get_css() {
return "";
@ -690,6 +695,15 @@ abstract class Plugin {
* @return array<mixed> - [0] - if set, url to redirect to
*/
function hook_post_logout($login, $user_id) {
user_error("Dummy method invoked.", E_USER_ERROR);
return [""];
}
/** Adds buttons to the right of default Login button
* @return void
*/
function hook_loginform_additional_buttons() {
user_error("Dummy method invoked.", E_USER_ERROR);
}
}

View File

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

View File

@ -32,6 +32,27 @@
<script type="text/javascript">
require({cache:{}});
</script>
<script type="text/javascript">
/* exported Plugins */
const Plugins = {};
<?php
foreach (PluginHost::getInstance()->get_plugins() as $n => $p) {
if (method_exists($p, "get_login_js")) {
$script = $p->get_login_js();
if ($script) {
echo "try {
$script
} catch (e) {
console.warn('failed to initialize plugin JS: $n', e);
}";
}
}
}
?>
</script>
</head>
<body class="flat ttrss_utility ttrss_login css_loading">
@ -175,6 +196,7 @@
<fieldset class="align-right">
<label> </label>
<?= \Controls\submit_tag(__('Log in')) ?>
<?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_LOGINFORM_ADDITIONAL_BUTTONS) ?>
</fieldset>
</form>