From b6f28f4f63304023a1aadcdeb258269f18276e1a Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Fri, 8 Dec 2017 12:15:50 +0100 Subject: [PATCH] authYubiKey: move to Twig-template --- .../authYubiKey/templates/yubikeylogin.twig | 25 +++++++++++++++ modules/authYubiKey/www/yubikeylogin.php | 31 ++++++++----------- 2 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 modules/authYubiKey/templates/yubikeylogin.twig diff --git a/modules/authYubiKey/templates/yubikeylogin.twig b/modules/authYubiKey/templates/yubikeylogin.twig new file mode 100644 index 000000000..c55a71af1 --- /dev/null +++ b/modules/authYubiKey/templates/yubikeylogin.twig @@ -0,0 +1,25 @@ +{% set pagetitle = '{authYubiKey:yubikey:header}'|trans %} +{% extends "base.twig" %} + +{% block content %} + {% if errorCode != null %} + <div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5"> + <img src="{{ baseurlpath }}resources/icons/experience/gtk-dialog-error.48x48.png" class="float-l" style="margin: 15px;" alt="" /> + <h2>{{ '{login:error_header}'|trans }}</h2> + <p><span style="text-decoration: bold;">{{ errorTitle }}</p> + <p>{{ errorDesc }}</p> + </div> + {% endif %} + + <img style="float: right" src="{{ logoUrl }}" alt="" /> + <img style="clear: right; float: right" src="{{ devicepicUrl }}" alt="YubiKey" /> + + <h2>{{ '{authYubiKey:yubikey:header}'|trans }}</h2> + <form action="?" method="post" name="f"> + <p>{{ '{authYubiKey:yubikey:intro}'|trans }}</p> + <p><input id="otp" style="border: 1px solid #ccc; background: #eee; padding: .5em; font-size: medium; width: 70%; color: #aaa" type="text" tabindex="2" name="otp" /></p> + {% for key, value in stateParams %} + <input type="hidden" name="{{ key|escape('html') }}" value="{{ value|escape('html') }}"/> + {% endfor %} + </form> +{% endblock %} diff --git a/modules/authYubiKey/www/yubikeylogin.php b/modules/authYubiKey/www/yubikeylogin.php index 1d0c7597a..42a418a8f 100644 --- a/modules/authYubiKey/www/yubikeylogin.php +++ b/modules/authYubiKey/www/yubikeylogin.php @@ -12,27 +12,22 @@ if (!array_key_exists('AuthState', $_REQUEST)) { throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.'); } -$authStateId = $_REQUEST['AuthState']; +$globalConfig = SimpleSAML_Configuration::getInstance(); +$t = new SimpleSAML_XHTML_Template($globalConfig, 'authYubiKey:yubikeylogin.php'); + +$errorCode = null; if (array_key_exists('otp', $_REQUEST)) { - $otp = $_REQUEST['otp']; -} else { - $otp = ''; -} + // attempt to log in + $errorCode = sspmod_authYubiKey_Auth_Source_YubiKey::handleLogin($authStateId, $_REQUEST['otp']); -if (!empty($otp)) { - // attempt to log in - $errorCode = sspmod_authYubiKey_Auth_Source_YubiKey::handleLogin($authStateId, $otp); -} else { - $errorCode = NULL; + $errorCodes = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages(); + $t->data['errorTitle'] = $errorCodes['title'][$errorCode]; + $t->data['errorDesc'] = $errorCodes['desc'][$errorCode]; } -$globalConfig = SimpleSAML_Configuration::getInstance(); -$t = new SimpleSAML_XHTML_Template($globalConfig, 'authYubiKey:yubikeylogin.php'); -$t->data['stateparams'] = array('AuthState' => $authStateId); -$t->data['errorcode'] = $errorCode; -$t->data['errorcodes'] = SimpleSAML\Error\ErrorCodes::getAllErrorCodeMessages(); -$t->data['logo_url'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/logo.jpg'); -$t->data['devicepic_url'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/yubikey.jpg'); +$t->data['errorCode'] = $errorCode; +$t->data['stateParams'] = array('AuthState' => $_REQUEST['authStateId']); +$t->data['logoUrl'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/logo.jpg'); +$t->data['devicepicUrl'] = SimpleSAML\Module::getModuleURL('authYubiKey/resources/yubikey.jpg'); $t->show(); -exit(); -- GitLab