summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-07-24 16:33:28 +0300
committerAndrew Dolgov <[email protected]>2022-07-24 16:33:28 +0300
commit7c45b3f789d94ddf670025ca64de9279952604fa (patch)
tree917392b4b57f9f9715d12b5d3e31697969a849dc
parentc0385c2098ccc831105c4fe83f3d30065ec58f91 (diff)
* add HOOK_LOGINFORM_ADDITIONAL_BUTTONS
* allow plugins to inject JS code into login form
-rw-r--r--classes/plugin.php14
-rwxr-xr-xclasses/pluginhost.php3
-rwxr-xr-xinclude/login_form.php22
3 files changed, 39 insertions, 0 deletions
diff --git a/classes/plugin.php b/classes/plugin.php
index 39af6a9a1..f47ab1882 100644
--- a/classes/plugin.php
+++ b/classes/plugin.php
@@ -50,6 +50,11 @@ abstract class Plugin {
}
/** @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);
+ }
}
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index 952d4df77..6ab4ac806 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -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;
diff --git a/include/login_form.php b/include/login_form.php
index 2e0eb077f..a26a58cc9 100755
--- a/include/login_form.php
+++ b/include/login_form.php
@@ -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>