From 547058c5307c5e48d8d93ea1ab3434a32f3cedb1 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sun, 10 Dec 2017 23:00:57 +0100 Subject: [PATCH] expirycheck: Add Twig templates --- .../expirycheck/templates/about2expire.php | 44 ----------------- .../expirycheck/templates/about2expire.twig | 13 +++++ modules/expirycheck/templates/expired.twig | 9 ++++ modules/expirycheck/www/about2expire.php | 47 +++++++++++++++++-- modules/expirycheck/www/expired.php | 7 +-- 5 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 modules/expirycheck/templates/about2expire.twig create mode 100644 modules/expirycheck/templates/expired.twig diff --git a/modules/expirycheck/templates/about2expire.php b/modules/expirycheck/templates/about2expire.php index e2be96973..f8749fdf6 100644 --- a/modules/expirycheck/templates/about2expire.php +++ b/modules/expirycheck/templates/about2expire.php @@ -16,50 +16,6 @@ * @package SimpleSAMLphp */ -# netid will expire today -if ($this->data['daysleft'] == 0) { - $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header_today}', array( - '%NETID%' => htmlspecialchars($this->data['netId']) - )); - - $warning = $this->t('{expirycheck:expwarning:warning_today}', array( - '%NETID%' => htmlspecialchars($this->data['netId']) - )); - -} -# netid will expire in one day -elseif ($this->data['daysleft'] == 1) { - - $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header}', array( - '%NETID%' => htmlspecialchars($this->data['netId']), - '%DAYS%' => $this->t('{expirycheck:expwarning:day}'), - '%DAYSLEFT%' => htmlspecialchars($this->data['daysleft']), - )); - - $warning = $this->t('{expirycheck:expwarning:warning}', array( - '%NETID%' => htmlspecialchars($this->data['netId']), - '%DAYS%' => $this->t('{expirycheck:expwarning:day}'), - '%DAYSLEFT%' => htmlspecialchars($this->data['daysleft']), - )); - -} -# netid will expire in next <daysleft> days -else { - $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header}', array( - '%NETID%' => htmlspecialchars($this->data['netId']), - '%DAYS%' => $this->t('{expirycheck:expwarning:days}'), - '%DAYSLEFT%' => htmlspecialchars($this->data['daysleft']), - )); - - $warning = $this->t('{expirycheck:expwarning:warning}', array( - '%NETID%' => htmlspecialchars($this->data['netId']), - '%DAYS%' => $this->t('{expirycheck:expwarning:days}'), - '%DAYSLEFT%' => htmlspecialchars($this->data['daysleft']), - )); - - -} - $this->data['autofocus'] = 'yesbutton'; $this->includeAtTemplateBase('includes/header.php'); diff --git a/modules/expirycheck/templates/about2expire.twig b/modules/expirycheck/templates/about2expire.twig new file mode 100644 index 000000000..c60788051 --- /dev/null +++ b/modules/expirycheck/templates/about2expire.twig @@ -0,0 +1,13 @@ +{% set pagetitle = 'SimpleSAMLphp'|trans %} +{% extends "base.twig" %} + +{% block content %} + <form style="display: inline; margin: 0px; padding: 0px" action="{{ yesTarget|escape('html') }}"> + {% for name, value in yesData %} + <input type="hidden" name="{{ name|escape('html') }}" value="{{ value|escape('html') }}" /> + {% endfor %} + <h3>{{ warning }}</h3> + <p>{{ '{expirycheck:expwarning:expiry_date_text}'|trans }} {{ expireOnDate }}</p> + <input type="submit" name="yes" id="yesbutton" value="{{ '{expirycheck:expwarning:btn_continue}'|trans }}" /> + </form> +{% endblock %} diff --git a/modules/expirycheck/templates/expired.twig b/modules/expirycheck/templates/expired.twig new file mode 100644 index 000000000..8c0cecbc1 --- /dev/null +++ b/modules/expirycheck/templates/expired.twig @@ -0,0 +1,9 @@ +{% set pagetitle = 'SimpleSAMLphp'|trans %} +{% extends "base.twig" %} + +{% block content %} + <h2>{{ '{expirycheck:expwarning:access_denied}'|trans }})</h2> + <p>{{ '{expirycheck:expwarning:no_access_to}'|trans({'%NETID%': netId}, "app") }}</p> + <p>{{ '{expirycheck:expwarning:expiry_date_text}'|trans }} <b>{{ expireOnDate }}</b></p> + <p>{{ '{expirycheck:expwarning:contact_home}'|trans }}</p> +{% endblock %} diff --git a/modules/expirycheck/www/about2expire.php b/modules/expirycheck/www/about2expire.php index 089d82985..ddb438b17 100644 --- a/modules/expirycheck/www/about2expire.php +++ b/modules/expirycheck/www/about2expire.php @@ -9,22 +9,61 @@ SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.'); if (!array_key_exists('StateId', $_REQUEST)) { - throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.'); + throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.'); } $id = $_REQUEST['StateId']; $state = SimpleSAML_Auth_State::loadState($id, 'expirywarning:about2expire'); if (array_key_exists('yes', $_REQUEST)) { - // The user has pressed the yes-button - SimpleSAML_Auth_ProcessingChain::resumeProcessing($state); + // The user has pressed the yes-button + SimpleSAML_Auth_ProcessingChain::resumeProcessing($state); } $globalConfig = SimpleSAML_Configuration::getInstance(); +$daysleft = $state['daysleft']; + $t = new SimpleSAML_XHTML_Template($globalConfig, 'expirycheck:about2expire.php'); +$t->data['autofocus'] = 'yesbutton'; $t->data['yesTarget'] = SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php'); $t->data['yesData'] = array('StateId' => $id); -$t->data['daysleft'] = $state['daysleft']; +$t->data['warning'] = $warning; $t->data['expireOnDate'] = $state['expireOnDate']; $t->data['netId'] = $state['netId']; + +if ($daysleft == 0) { + # netid will expire today + $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header_today}', array( + '%NETID%' => htmlspecialchars($this->data['netId']) + )); + $this->data['warning'] = $this->t('{expirycheck:expwarning:warning_today}', array( + '%NETID%' => htmlspecialchars($this->data['netId']) + )); +} elseif ($daysleft == 1) { + # netid will expire in one day + + $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header}', array( + '%NETID%' => htmlspecialchars($this->data['netId']), + '%DAYS%' => $this->t('{expirycheck:expwarning:day}'), + '%DAYSLEFT%' => htmlspecialchars($daysleft), + )); + $this->data['warning'] = $this->t('{expirycheck:expwarning:warning}', array( + '%NETID%' => htmlspecialchars($this->data['netId']), + '%DAYS%' => $this->t('{expirycheck:expwarning:day}'), + '%DAYSLEFT%' => htmlspecialchars($daysleft), + )); +} else { + # netid will expire in next <daysleft> days + $this->data['header'] = $this->t('{expirycheck:expwarning:warning_header}', array( + '%NETID%' => htmlspecialchars($this->data['netId']), + '%DAYS%' => $this->t('{expirycheck:expwarning:days}'), + '%DAYSLEFT%' => htmlspecialchars($daysleft), + )); + $this->data['warning'] = $this->t('{expirycheck:expwarning:warning}', array( + '%NETID%' => htmlspecialchars($this->data['netId']), + '%DAYS%' => $this->t('{expirycheck:expwarning:days}'), + '%DAYSLEFT%' => htmlspecialchars($daysleft), + )); +} + $t->show(); diff --git a/modules/expirycheck/www/expired.php b/modules/expirycheck/www/expired.php index 87eef83da..47fbd2116 100644 --- a/modules/expirycheck/www/expired.php +++ b/modules/expirycheck/www/expired.php @@ -9,13 +9,14 @@ SimpleSAML\Logger::info('expirycheck - User has been warned that NetID is near to expirational date.'); if (!array_key_exists('StateId', $_REQUEST)) { - throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.'); + throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.'); } $state = SimpleSAML_Auth_State::loadState($_REQUEST['StateId'], 'expirywarning:expired'); $globalConfig = SimpleSAML_Configuration::getInstance(); $t = new SimpleSAML_XHTML_Template($globalConfig, 'expirycheck:expired.php'); -$t->data['expireOnDate'] = $state['expireOnDate']; -$t->data['netId'] = $state['netId']; +$t->data['header'] = $this->t('{expirycheck:expwarning:access_denied}'); +$t->data['expireOnDate'] = htmlspecialchars($state['expireOnDate']); +$t->data['netId'] = htmlspecialchars($state['netId']); $t->show(); -- GitLab