From 7774f9c08f3b0759670c93c0b29998b824ddb061 Mon Sep 17 00:00:00 2001 From: Nomen Nescio Date: Sun, 12 Jan 2025 15:23:52 +0100 Subject: [PATCH] Quick hack to get uniform responses to authentication failures This is meant as a first step in solving https://github.com/privacyidea/simplesamlphp-module-privacyidea/issues/220 Suggestions on how to improve the design on this fix are very welcome. The new strings still need to be added to the po files. --- src/Auth/PIResponse.php | 12 +++++++++--- templates/pi-form.twig | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Auth/PIResponse.php b/src/Auth/PIResponse.php index 256edb2..09d5f03 100644 --- a/src/Auth/PIResponse.php +++ b/src/Auth/PIResponse.php @@ -82,7 +82,11 @@ public static function fromJSON(string $json, PrivacyIDEA $privacyIDEA): ?PIResp if (!isset($map['result']['value'])) { $ret->errorCode = $map['result']['error']['code']; - $ret->errorMessage = $map['result']['error']['message']; + $ret->errorMessage = $map['result']['error']['message']; + if ($ret->errorCode == 904){ + $ret->errorCode = 1312; + $ret->errorMessage = 'Sorry, authentication failed... Please try again!'; + } return $ret; } @@ -131,7 +135,9 @@ public static function fromJSON(string $json, PrivacyIDEA $privacyIDEA): ?PIResp } elseif ($r === AuthenticationStatus::REJECT) { - $ret->authenticationStatus = AuthenticationStatus::REJECT; + $ret->authenticationStatus = AuthenticationStatus::REJECT; + $ret->errorCode = 1312; + $ret->errorMessage = 'Sorry, authentication failed... Please try again!'; } else { @@ -420,4 +426,4 @@ public function getErrorMessage(): string { return $this->errorMessage; } -} \ No newline at end of file +} diff --git a/templates/pi-form.twig b/templates/pi-form.twig index 9ccd58d..2b411aa 100644 --- a/templates/pi-form.twig +++ b/templates/pi-form.twig @@ -57,8 +57,13 @@
gtk-dialog-error + {% if errorCode is same as '1312' %} +

{{ 'Authentication failed'|trans }}

+ {{ 'Please try again!'|trans }} + {% else %}

{{ 'An error occurred'|trans }}

"Error {{ errorCode }}: {{ errorMessage }}" + {% endif %}
{% endif %}