Commit 8228bbcb authored by Francois Marier's avatar Francois Marier
Browse files

Allow auth plugins to provide extra login form javascript



Some authentication plugins need to inject some more Javascript
into the login form. This adds a function to the API to enable this.

Bug #905081

Change-Id: Icf1018558fe9210261c4f758169fd30afb4f89ab
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent d939148f
......@@ -1092,7 +1092,7 @@ function get_login_form_js($form) {
$form = str_replace('/', '\/', str_replace("'", "\'", (str_replace(array("\n", "\t"), '', $form))));
$strcookiesnotenabled = json_encode(get_string('cookiesnotenabled'));
$cookiename = get_config('cookieprefix') . 'ctest';
return <<<EOF
$js = <<< EOF
<script type="text/javascript">
var loginbox = $('loginform_container');
document.cookie = "$cookiename=1";
......@@ -1105,6 +1105,47 @@ else {
}
</script>
EOF;
$authplugins = auth_get_enabled_auth_plugins();
foreach ($authplugins as $plugin) {
$classname = 'PluginAuth' . ucfirst(strtolower($plugin));
$pluginjs = call_static_method($classname, 'login_form_js');
if (!empty($pluginjs)) {
$js .= $pluginjs;
}
}
return $js;
}
/**
* Return a list of all enabled and usable auth plugins.
*/
function auth_get_enabled_auth_plugins() {
$sql = 'SELECT
DISTINCT(authname)
FROM
{auth_instance} ai
JOIN
{institution} i ON ai.institution = i.name
JOIN
{auth_installed} inst ON inst.name = ai.authname
WHERE
i.suspended = 0 AND
inst.active = 1';
$authplugins = get_column_sql($sql);
$usableplugins = array();
foreach ($authplugins as $plugin) {
safe_require('auth', strtolower($plugin));
$classname = 'PluginAuth' . ucfirst(strtolower($plugin));
if (call_static_method($classname, 'is_usable')) {
$usableplugins[] = $plugin;
}
}
return $usableplugins;
}
......@@ -1745,4 +1786,12 @@ class PluginAuth extends Plugin {
public static function can_be_disabled() {
return false;
}
/**
* Can be overridden by plugins that need to inject more
* Javascript to make the login form work.
*/
public static function login_form_js() {
return false;
}
}
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