From 74d0f7c1ab4d21b88ef84c09d0d72c2033bde297 Mon Sep 17 00:00:00 2001
From: Hanne Moa <hanne.moa@uninett.no>
Date: Thu, 15 Sep 2016 14:32:50 +0200
Subject: [PATCH] Avoid concatenated error messages

For #455
---
 modules/authX509/templates/X509error.php       |  4 ++--
 modules/authX509/www/expirywarning.php         |  1 +
 modules/authYubiKey/templates/yubikeylogin.php |  4 ++--
 modules/authYubiKey/www/yubikeylogin.php       |  1 +
 modules/core/templates/loginuserpass.php       | 10 ++--------
 modules/core/www/loginuserpass.php             |  1 +
 modules/core/www/loginuserpassorg.php          |  1 +
 7 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/modules/authX509/templates/X509error.php b/modules/authX509/templates/X509error.php
index 1f272301c..459bbf2c5 100644
--- a/modules/authX509/templates/X509error.php
+++ b/modules/authX509/templates/X509error.php
@@ -11,8 +11,8 @@ if ($this->data['errorcode'] !== NULL) {
 	<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
 		<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-error.48x48.png" class="float-l" style="margin: 15px" alt="" />
 		<h2><?php echo $this->t('{login:error_header}'); ?></h2>
-		<p><b><?php echo $this->t('{errors:title_' . $this->data['errorcode'] . '}'); ?></b></p>
-		<p><?php echo $this->t('{errors:descr_' . $this->data['errorcode'] . '}'); ?></p>
+		<p><b><?php echo $this->t($this->data['errorcodes']['title'][$this->data['errorcode']]); ?></b></p>
+		<p><?php echo $this->t($this->data['errorcodes']['descr'][$this->data['errorcode']]); ?></p>
 	</div>
 <?php
 }
diff --git a/modules/authX509/www/expirywarning.php b/modules/authX509/www/expirywarning.php
index b5faa22a2..02b2b221e 100644
--- a/modules/authX509/www/expirywarning.php
+++ b/modules/authX509/www/expirywarning.php
@@ -27,4 +27,5 @@ $t->data['target'] = SimpleSAML\Module::getModuleURL('authX509/expirywarning.php
 $t->data['data'] = array('StateId' => $id);
 $t->data['daysleft'] = $state['daysleft'];
 $t->data['renewurl'] = $state['renewurl'];
+$t->data['errorcodes'] = SimpleSAML\Error\Errorcodes::getAllErrorCodeMessages();
 $t->show();
diff --git a/modules/authYubiKey/templates/yubikeylogin.php b/modules/authYubiKey/templates/yubikeylogin.php
index 732904dec..0c9f3e48e 100644
--- a/modules/authYubiKey/templates/yubikeylogin.php
+++ b/modules/authYubiKey/templates/yubikeylogin.php
@@ -12,8 +12,8 @@ if ($this->data['errorcode'] !== NULL) {
 	<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
 		<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-error.48x48.png" class="float-l" style="margin: 15px" alt="" />
 		<h2><?php echo $this->t('{login:error_header}'); ?></h2>
-		<p><b><?php echo $this->t('{errors:title_' . $this->data['errorcode'] . '}'); ?></b></p>
-		<p><?php echo $this->t('{errors:descr_' . $this->data['errorcode'] . '}'); ?></p>
+		<p><b><?php echo $this->t($this->data['errorcodes']['title'][$this->data['errorcode']]); ?></b></p>
+		<p><?php echo $this->t($this->data['errorcodes']['descr'][$this->data['errorcode']]); ?></p>
 	</div>
 <?php
 }
diff --git a/modules/authYubiKey/www/yubikeylogin.php b/modules/authYubiKey/www/yubikeylogin.php
index 7873828e6..52311b5bf 100644
--- a/modules/authYubiKey/www/yubikeylogin.php
+++ b/modules/authYubiKey/www/yubikeylogin.php
@@ -31,6 +31,7 @@ $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->show();
diff --git a/modules/core/templates/loginuserpass.php b/modules/core/templates/loginuserpass.php
index f9d739c62..5baaec7ae 100644
--- a/modules/core/templates/loginuserpass.php
+++ b/modules/core/templates/loginuserpass.php
@@ -20,16 +20,10 @@ if ($this->data['errorcode'] !== null) {
         <h2><?php echo $this->t('{login:error_header}'); ?></h2>
 
         <p><strong><?php
-                echo htmlspecialchars($this->t(
-                    '{errors:title_'.$this->data['errorcode'].'}',
-                    $this->data['errorparams']
-                )); ?></strong></p>
+            echo htmlspecialchars($this->t($this->data['errorcodes']['title'][$this->data['errorcode']], $this->data['errorparams'])); ?></strong></p>
 
         <p><?php
-            echo htmlspecialchars($this->t(
-                '{errors:descr_'.$this->data['errorcode'].'}',
-                $this->data['errorparams']
-            )); ?></p>
+            echo htmlspecialchars($this->t($this->data['errorcodes']['descr'][$this->data['errorcode']], $this->data['errorparams'])); ?></p>
     </div>
 <?php
 }
diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php
index 545032027..9a2958b08 100644
--- a/modules/core/www/loginuserpass.php
+++ b/modules/core/www/loginuserpass.php
@@ -93,6 +93,7 @@ if (array_key_exists('forcedUsername', $state)) {
 }
 $t->data['links'] = $source->getLoginLinks();
 $t->data['errorcode'] = $errorCode;
+$t->data['errorcodes'] = SimpleSAML\Error\Errorcodes::getAllErrorCodeMessages();
 $t->data['errorparams'] = $errorParams;
 
 if (isset($state['SPMetadata'])) {
diff --git a/modules/core/www/loginuserpassorg.php b/modules/core/www/loginuserpassorg.php
index 23db59831..4f33b36f1 100644
--- a/modules/core/www/loginuserpassorg.php
+++ b/modules/core/www/loginuserpassorg.php
@@ -81,6 +81,7 @@ $t->data['rememberMeEnabled'] = false;
 $t->data['rememberMeChecked'] = false;
 if (isset($_COOKIE[$source->getAuthId() . '-username'])) $t->data['rememberUsernameChecked'] = TRUE;
 $t->data['errorcode'] = $errorCode;
+$t->data['errorcodes'] = SimpleSAML\Error\Errorcodes::getAllErrorCodeMessages();
 $t->data['errorparams'] = $errorParams;
 
 if ($organizations !== NULL) {
-- 
GitLab