Commit c40b75f6 authored by Francois Marier's avatar Francois Marier
Browse files

Enable auth plugins to supply extra login form elements



This will ensure that we don't need to hack core to add links to
the bottom of the main login form for example.

Bug #905081

Change-Id: I44d1b335660dda89c55e2cdee1cd7b59484accfe
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 8228bbcb
......@@ -1032,6 +1032,16 @@ function auth_get_login_form() {
),
);
// Get any extra elements from the enabled auth plugins
$authplugins = auth_get_enabled_auth_plugins();
foreach ($authplugins as $plugin) {
$classname = 'PluginAuth' . ucfirst(strtolower($plugin));
$pluginelements = call_static_method($classname, 'login_form_elements');
if (!empty($pluginelements)) {
$elements = array_merge($elements, $pluginelements);
}
}
// The login page is completely transient, and it is smart because it
// remembers the GET and POST data sent to it and resends that on
// afterwards.
......@@ -1610,6 +1620,49 @@ function auth_generate_login_form() {
else {
$registerlink = '';
}
$elements = array(
'login_username' => array(
'type' => 'text',
'title' => get_string('username') . ':',
'description' => get_string('usernamedescription'),
'defaultvalue' => (isset($_POST['login_username'])) ? $_POST['login_username'] : '',
'rules' => array(
'required' => true
)
),
'login_password' => array(
'type' => 'password',
'title' => get_string('password') . ':',
'description' => get_string('passworddescription'),
'defaultvalue' => '',
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('login')
),
'register' => array(
'value' => '<div id="login-helplinks">' . $registerlink
. '<a href="' . get_config('wwwroot') . 'forgotpass.php" tabindex="2">' . get_string('lostusernamepassword') . '</a></div>'
),
'loginsaml' => array(
'value' => ((count_records('auth_instance', 'authname', 'saml') == 0) ? '' : '<a href="' . get_config('wwwroot') . 'auth/saml/" tabindex="2">' . get_string('login', 'auth.saml') . '</a>')
),
);
// Get any extra elements from the enabled auth plugins
$authplugins = auth_get_enabled_auth_plugins();
foreach ($authplugins as $plugin) {
$classname = 'PluginAuth' . ucfirst(strtolower($plugin));
$pluginelements = call_static_method($classname, 'login_form_elements');
if (!empty($pluginelements)) {
$elements = array_merge($elements, $pluginelements);
}
}
$loginform = get_login_form_js(pieform(array(
'name' => 'login',
'renderer' => 'div',
......@@ -1617,37 +1670,7 @@ function auth_generate_login_form() {
'plugintype' => 'auth',
'pluginname' => 'internal',
'autofocus' => false,
'elements' => array(
'login_username' => array(
'type' => 'text',
'title' => get_string('username') . ':',
'description' => get_string('usernamedescription'),
'defaultvalue' => (isset($_POST['login_username'])) ? $_POST['login_username'] : '',
'rules' => array(
'required' => true
)
),
'login_password' => array(
'type' => 'password',
'title' => get_string('password') . ':',
'description' => get_string('passworddescription'),
'defaultvalue' => '',
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('login')
),
'register' => array(
'value' => '<div id="login-helplinks">' . $registerlink
. '<a href="' . get_config('wwwroot') . 'forgotpass.php" tabindex="2">' . get_string('lostusernamepassword') . '</a></div>'
),
'loginsaml' => array(
'value' => ((count_records('auth_instance', 'authname', 'saml') == 0) ? '' : '<a href="' . get_config('wwwroot') . 'auth/saml/" tabindex="2">' . get_string('login', 'auth.saml') . '</a>')
),
)
'elements' => $elements,
)));
return $loginform;
......@@ -1787,6 +1810,14 @@ class PluginAuth extends Plugin {
return false;
}
/**
* Can be overridden by plugins that need to inject more
* pieform elements into the login form.
*/
public static function login_form_elements() {
return false;
}
/**
* Can be overridden by plugins that need to inject more
* Javascript to make the login form work.
......
......@@ -1260,6 +1260,9 @@ div.sideblock ul li {
line-height: 1.333em;
padding-left: 5px;
}
.login-externallink {
clear: left;
}
#login_login_username_container input, #login_login_password_container input {
margin: 0 0 5px 0;
display: block;
......
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