From 027a69e9b3eaf22c9ed53f5edf8f6f37c171498d Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Fri, 8 Dec 2017 13:46:27 +0100 Subject: [PATCH] Twigify multiauth module --- modules/multiauth/templates/selectsource.twig | 24 ++++++++ modules/multiauth/www/selectsource.php | 56 +++++++++++-------- 2 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 modules/multiauth/templates/selectsource.twig diff --git a/modules/multiauth/templates/selectsource.twig b/modules/multiauth/templates/selectsource.twig new file mode 100644 index 000000000..81fc1a6a9 --- /dev/null +++ b/modules/multiauth/templates/selectsource.twig @@ -0,0 +1,24 @@ +{% set pagetitle = '{multiauth:multiauth:select_source_header}'|trans %} +{% extends "base.twig" %} + +{% block content %} + <h2>{{ '{multiauth:multiauth:select_source_header}'| trans }}</h2> + <p>{{ '{multiauth:multiauth:select_source_text}'| trans }}</p> + + <form action="{{ selfUrl|escape('html') }}" method="get"> + <input type="hidden" name="AuthState" value="{{ authstate|escape('html') }} " /> + <ul> + {% for key, source in sources %} + {% set name = ('src-' ~ source.source64) %} + {% set button = ('button-' ~ source.source) %} + <li class="{{ source.css_class|escape('html') }} authsource"> + {% if source.source == preferred %} + <input type="submit" name="{{ name|escape('html') }}" autofocus="autofocus" id="{{ button|escape('html') }}" value="{{ source.text|escape('html') }}" /> + {% else %} + <input type="submit" name="{{ name|escape('html') }}" id="{{ button|escape('html') }}" value="{{ source.text|escape('html') }}" /> + {% endif %} + </li> + {% endfor %} + </ul> + </form> +{% endblock %} diff --git a/modules/multiauth/www/selectsource.php b/modules/multiauth/www/selectsource.php index db09029f8..1736263be 100644 --- a/modules/multiauth/www/selectsource.php +++ b/modules/multiauth/www/selectsource.php @@ -12,49 +12,59 @@ // Retrieve the authentication state if (!array_key_exists('AuthState', $_REQUEST)) { - throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.'); + throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.'); } $authStateId = $_REQUEST['AuthState']; $state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID); if (array_key_exists("SimpleSAML_Auth_Source.id", $state)) { - $authId = $state["SimpleSAML_Auth_Source.id"]; - $as = SimpleSAML_Auth_Source::getById($authId); + $authId = $state["SimpleSAML_Auth_Source.id"]; + $as = SimpleSAML_Auth_Source::getById($authId); } else { - $as = NULL; + $as = null; } -$source = NULL; +$source = null; if (array_key_exists('source', $_REQUEST)) { - $source = $_REQUEST['source']; + $source = $_REQUEST['source']; } else { - foreach ($_REQUEST as $k => $v) { - $k = explode('-', $k, 2); - if (count($k) === 2 && $k[0] === 'src') { - $source = base64_decode($k[1]); - } - } + foreach ($_REQUEST as $k => $v) { + $k = explode('-', $k, 2); + if (count($k) === 2 && $k[0] === 'src') { + $source = base64_decode($k[1]); + } + } } -if ($source !== NULL) { - if ($as !== NULL) { - $as->setPreviousSource($source); - } - sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state); +if ($source !== null) { + if ($as !== null) { + $as->setPreviousSource($source); + } + sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state); } if (array_key_exists('multiauth:preselect', $state)) { - $source = $state['multiauth:preselect']; - sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state); + $source = $state['multiauth:preselect']; + sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state); } $globalConfig = SimpleSAML_Configuration::getInstance(); $t = new SimpleSAML_XHTML_Template($globalConfig, 'multiauth:selectsource.php'); +$language = $t->getLanguage(); + +$sources = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID]; +foreach ($sources as $key => $source){ + $sources[$key]['source64'] = base64_encode($sources[$key]['source']); + $sources[$key]['text'] = $sources[$key]['text'][$language]; +} + $t->data['authstate'] = $authStateId; -$t->data['sources'] = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID]; -if ($as !== NULL) { - $t->data['preferred'] = $as->getPreviousSource(); +$t->data['sources'] = $sources; +$t->data['selfUrl'] = $_SERVER['PHP_SELF']; + +if ($as !== null) { + $t->data['preferred'] = $as->getPreviousSource(); } else { - $t->data['preferred'] = NULL; + $t->data['preferred'] = null; } $t->show(); exit(); -- GitLab