From e2dfb888798fa23fed7ca6264cf16ce63e6eb04c Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Thu, 23 May 2024 14:11:33 +0200
Subject: [PATCH] add translation for new error messages

---
 lib/AccessCheck/App/Controller.pm     | 4 ++--
 lib/AccessCheck/L10N/fr.pm            | 9 +++++++++
 templates/web/edugain/errors.html.tt2 | 6 ++++++
 templates/web/renater/errors.html.tt2 | 8 +++++++-
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/AccessCheck/App/Controller.pm b/lib/AccessCheck/App/Controller.pm
index 452d491..9851bbf 100644
--- a/lib/AccessCheck/App/Controller.pm
+++ b/lib/AccessCheck/App/Controller.pm
@@ -133,7 +133,7 @@ sub check_csrf_token {
     return $self->abort(
         status       => 403,
         log_message  => sprintf("missing anti-CSRF token for action %s", $self->current_route()),
-        user_message => "missing CSRF token"
+        user_message => "missing_csrf_token"
     ) if !$provided_token;
 
     my $expected_token = $self->csrf_token();
@@ -146,7 +146,7 @@ sub check_csrf_token {
             $provided_token,
             $expected_token,
         ),
-        user_message => "invalid CSRF token"
+        user_message => "invalid_csrf_token"
     ) if $provided_token ne $expected_token;
 
     return 1;
diff --git a/lib/AccessCheck/L10N/fr.pm b/lib/AccessCheck/L10N/fr.pm
index 5be7bac..49b0fb6 100644
--- a/lib/AccessCheck/L10N/fr.pm
+++ b/lib/AccessCheck/L10N/fr.pm
@@ -296,6 +296,11 @@ msgstr "Les attributs eduPersonAffiliation et eduPersonScopedAffiliation sont va
 #: templates/web/edugain/errors.tt2.html:12 templates/web/renater/errors.tt2.html:12
 msgid "internal error"
 msgstr "erreur interne"
+
+#: templates/web/edugain/errors.html.tt2:35 templates/web/renater/errors.html.tt2:32
+msgid "invalid CSRF token"
+msgstr "jeton CSRF invalide"
+
 #. (matches.0)
 #: templates/web/edugain/errors.html.tt2:35
 msgid "invalid parameter '%1'"
@@ -305,6 +310,10 @@ msgstr "paramètre invalide '%1'"
 msgid "mail notification failure"
 msgstr "échec de notification par mail"
 
+#: templates/web/edugain/errors.html.tt2:32 templates/web/renater/errors.html.tt2:29
+msgid "missing CSRF token"
+msgstr "jeton CSRF manquant"
+
 #. (matches.0)
 #: templates/web/edugain/errors.tt2.html:30 templates/web/renater/errors.tt2.html:30
 msgid "missing parameter '%1'"
diff --git a/templates/web/edugain/errors.html.tt2 b/templates/web/edugain/errors.html.tt2
index 8ab9a27..66056e7 100644
--- a/templates/web/edugain/errors.html.tt2
+++ b/templates/web/edugain/errors.html.tt2
@@ -28,6 +28,12 @@
         [% ELSIF error == 'no_displayname_attribute' %]
         [% c.loc("your identity provider doesn't provide displayName attribute, required for this application") %]
 
+        [% ELSIF error == 'missing_csrf_token' %]
+        [% c.loc("missing CSRF token") %]
+
+        [% ELSIF error == 'invalid_csrf_token' %]
+        [% c.loc("invalid CSRF token") %]
+
         [% ELSIF (matches = error.match('missing_(\w+)')) %]
         [% c.loc("missing parameter '[_1]'", matches.0) %]
 
diff --git a/templates/web/renater/errors.html.tt2 b/templates/web/renater/errors.html.tt2
index 6611942..f826368 100644
--- a/templates/web/renater/errors.html.tt2
+++ b/templates/web/renater/errors.html.tt2
@@ -25,10 +25,16 @@
         [% ELSIF error == 'unauthenticated' %]
         [% c.loc("you need to authenticate to access this page") %]
 
+        [% ELSIF error == 'missing_csrf_token' %]
+        [% c.loc("missing CSRF token") %]
+
+        [% ELSIF error == 'invalid_csrf_token' %]
+        [% c.loc("invalid CSRF token") %]
+
         [% ELSIF (matches = error.match('missing_(\w+)')) %]
         [% c.loc("missing parameter '[_1]'", matches.0) %]
 
-	[% ELSIF (matches = error.match('invalid_(\w+)')) %]
+        [% ELSIF (matches = error.match('invalid_(\w+)')) %]
         [% c.loc("invalid parameter '[_1]'", matches.0) %]
 
         [% ELSE %]
-- 
GitLab