Skip to content

Commit

Permalink
Passwordless authentication with WebAuthn
Browse files Browse the repository at this point in the history
Add support for extra login buttons to the backend
login module.
  • Loading branch information
Nicholas K. Dionysopoulos committed Jul 25, 2019
1 parent bfa31de commit 9f015a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
1 change: 1 addition & 0 deletions administrator/modules/mod_login/mod_login.php
Expand Up @@ -15,6 +15,7 @@

$langs = LoginHelper::getLanguageList();
$twofactormethods = AuthenticationHelper::getTwoFactorMethods();
$extraButtons = AuthenticationHelper::getLoginButtons('form-login');
$return = LoginHelper::getReturnUri();

require ModuleHelper::getLayoutPath('mod_login', $params->get('layout', 'default'));
19 changes: 19 additions & 0 deletions administrator/modules/mod_login/tmpl/default.php
Expand Up @@ -96,6 +96,25 @@ class="form-control input-full"
<?php echo $langs; ?>
</div>
<?php endif; ?>
<?php foreach($extraButtons as $button): ?>
<div class="form-group">
<button type="button"
class="btn btn-secondary btn-block mt-4 <?= $button['class'] ?? '' ?>"
onclick="<?= $button['onclick'] ?>"
title="<?= Text::_($button['label']) ?>"
id="<?= $button['id'] ?>"
>
<?php if (!empty($button['icon'])): ?>
<span class="<?= $button['icon'] ?>"></span>
<?php elseif (!empty($button['image'])): ?>
<?= HTMLHelper::_('image', $button['image'], Text::_('PLG_SYSTEM_WEBAUTHN_LOGIN_DESC'), [
'class' => 'icon',
], true) ?>
<?php endif; ?>
<?= Text::_($button['label']) ?>
</button>
</div>
<?php endforeach; ?>
<div class="form-group">
<button class="btn btn-primary btn-block btn-lg mt-4" id="btn-login-submit"><?php echo Text::_('JLOGIN'); ?></button>
</div>
Expand Down
10 changes: 4 additions & 6 deletions modules/mod_login/mod_login.php
Expand Up @@ -9,22 +9,20 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Helper\AuthenticationHelper;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Module\Login\Site\Helper\LoginHelper;

$params->def('greeting', 1);

// HTML IDs
$moduleId = "login-form-{$module->id}";
$usernameId = "modlgn-username-{$module->id}";
$passwordId = "modlgn-passwd-{$module->id}";
$secretKeyId = "modlgn-secretkey-{$module->id}";
$formId = "login-form-{$module->id}";
$type = LoginHelper::getType();
$return = LoginHelper::getReturnUrl($params, $type);
$twofactormethods = AuthenticationHelper::getTwoFactorMethods();
$extraButtons = AuthenticationHelper::getLoginButtons($moduleId, $usernameId);
$user = $app->getIdentity();
$extraButtons = AuthenticationHelper::getLoginButtons($formId);
$user = Factory::getUser();
$layout = $params->get('layout', 'default');

// Logged users must load the logout sublayout
Expand Down
32 changes: 16 additions & 16 deletions modules/mod_login/tmpl/default.php
Expand Up @@ -22,7 +22,7 @@
Text::script('JSHOW');
Text::script('JHIDE');
?>
<form id="<?= $moduleId ?>" class="mod-login" action="<?= Route::_('index.php', true); ?>" method="post">
<form id="<?= $formId ?>" class="mod-login" action="<?= Route::_('index.php', true); ?>" method="post">

<?php if ($params->get('pretext')) : ?>
<div class="mod-login__pretext pretext">
Expand All @@ -34,30 +34,30 @@
<div class="mod-login__username form-group">
<?php if (!$params->get('usetext', 0)) : ?>
<div class="input-group">
<input id="<?= $usernameId ?>" type="text" name="username" class="form-control" placeholder="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>">
<input id="modlgn-username-<?= $module->id ?>" type="text" name="username" class="form-control" placeholder="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>">
<span class="input-group-append">
<label for="<?= $usernameId ?>" class="sr-only"><?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?></label>
<span class="input-group-text icon-user" title="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>"></span>
<label for="modlgn-username-<?= $module->id ?>" class="sr-only"><?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?></label>
<span class="input-group-text icon-user hasTooltip" title="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>"></span>
</span>
</div>
<?php else : ?>
<label for="<?= $usernameId ?>"><?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?></label>
<input id="<?= $usernameId ?>" type="text" name="username" class="form-control" placeholder="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>">
<label for="modlgn-username-<?= $module->id ?>"><?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?></label>
<input id="modlgn-username-<?= $module->id ?>" type="text" name="username" class="form-control" placeholder="<?= Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>">
<?php endif; ?>
</div>

<div class="mod-login__password form-group">
<?php if (!$params->get('usetext', 0)) : ?>
<div class="input-group">
<input id="<?= $passwordId ?>" type="password" name="password" class="form-control" placeholder="<?= Text::_('JGLOBAL_PASSWORD'); ?>">
<input id="modlgn-passwd-<?= $module->id ?>" type="password" name="password" class="form-control" placeholder="<?= Text::_('JGLOBAL_PASSWORD'); ?>">
<span class="input-group-append">
<span class="sr-only"><?= Text::_('JSHOW'); ?></span>
<span class="input-group-text icon-eye" aria-hidden="true"></span>
</span>
</div>
<?php else : ?>
<label for="<?= $passwordId ?>"><?= Text::_('JGLOBAL_PASSWORD'); ?></label>
<input id="<?= $passwordId ?>" type="password" name="password" class="form-control" placeholder="<?= Text::_('JGLOBAL_PASSWORD'); ?>">
<label for="modlgn-passwd-<?= $module->id ?>"><?= Text::_('JGLOBAL_PASSWORD'); ?></label>
<input id="modlgn-passwd-<?= $module->id ?>" type="password" name="password" class="form-control" placeholder="<?= Text::_('JGLOBAL_PASSWORD'); ?>">
<?php endif; ?>
</div>

Expand All @@ -66,18 +66,18 @@
<?php if (!$params->get('usetext', 0)) : ?>
<div class="input-group">
<span class="input-group-prepend">
<span class="input-group-text icon-star" title="<?= Text::_('JGLOBAL_SECRETKEY'); ?>"></span>
<label for="<?= $secretKeyId ?>" class="sr-only"><?= Text::_('JGLOBAL_SECRETKEY'); ?></label>
<span class="input-group-text icon-star hasTooltip" title="<?= Text::_('JGLOBAL_SECRETKEY'); ?>"></span>
<label for="modlgn-secretkey-<?= $module->id ?>" class="sr-only"><?= Text::_('JGLOBAL_SECRETKEY'); ?></label>
</span>
<input id="<?= $secretKeyId ?>" autocomplete="off" type="text" name="secretkey" class="form-control" placeholder="<?= Text::_('JGLOBAL_SECRETKEY'); ?>">
<span class="input-group-append" title="<?= Text::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<input id="modlgn-secretkey-<?= $module->id ?>" autocomplete="off" type="text" name="secretkey" class="form-control" placeholder="<?= Text::_('JGLOBAL_SECRETKEY'); ?>">
<span class="input-group-append hasTooltip" title="<?= Text::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<span class="input-group-text icon-help"></span>
</span>
</div>
<?php else : ?>
<label for="<?= $secretKeyId ?>"><?= Text::_('JGLOBAL_SECRETKEY'); ?></label>
<input id="<?= $secretKeyId ?>" autocomplete="off" type="text" name="secretkey" class="form-control" placeholder="<?= Text::_('JGLOBAL_SECRETKEY'); ?>">
<span class="btn width-auto" title="<?= Text::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<label for="modlgn-secretkey-<?= $module->id ?>"><?= Text::_('JGLOBAL_SECRETKEY'); ?></label>
<input id="modlgn-secretkey-<?= $module->id ?>" autocomplete="off" type="text" name="secretkey" class="form-control" placeholder="<?= Text::_('JGLOBAL_SECRETKEY'); ?>">
<span class="btn width-auto hasTooltip" title="<?= Text::_('JGLOBAL_SECRETKEY_HELP'); ?>">
<span class="icon-help"></span>
</span>
<?php endif; ?>
Expand Down

0 comments on commit 9f015a6

Please sign in to comment.