From 9ce4593bc195f5cc0b732da2e6267b00c73e6efc Mon Sep 17 00:00:00 2001
From: Julien Rosset
Date: Wed, 15 May 2024 18:28:11 +0200
Subject: [PATCH] Translations for menu, home and signIn page
---
assets/app.js | 31 ++++++-----
assets/styles/_layout.scss | 8 +++
src/Controller/UserController.php | 25 +++++----
src/Security/UserChecker.php | 8 ++-
templates/_flashes.html.twig | 25 +++++----
templates/base.html.twig | 6 ++-
templates/core/main.html.twig | 5 +-
templates/user/signIn.html.twig | 14 ++---
translations/messages+intl-icu.en.xlf | 76 +++++++++++++++++++++++++++
translations/messages+intl-icu.fr.xlf | 76 +++++++++++++++++++++++++++
translations/security+intl-icu.en.xlf | 19 +++++++
translations/security+intl-icu.fr.xlf | 19 +++++++
12 files changed, 260 insertions(+), 52 deletions(-)
create mode 100644 translations/messages+intl-icu.en.xlf
create mode 100644 translations/messages+intl-icu.fr.xlf
create mode 100644 translations/security+intl-icu.en.xlf
create mode 100644 translations/security+intl-icu.fr.xlf
diff --git a/assets/app.js b/assets/app.js
index 4e44013..089beb5 100644
--- a/assets/app.js
+++ b/assets/app.js
@@ -8,23 +8,22 @@ import 'bootstrap';
import $ from 'jquery';
//endregion
//region Utils
-import Utils from 'utils';
window.$ = $; // Declare $ as a global variable, accessible in all files
//endregion
-//region Header & Footer fixe (overlay)
-const headerHeight = Utils.getElementRealHeight($('header:not(.overlay-not-fixed)'));
-const footerHeight = Utils.getElementRealHeight($('footer:not(.overlay-not-fixed)'));
-$('#div-body').css(
- {
- 'padding-top': headerHeight,
- 'padding-bottom': footerHeight,
- },
-);
-$('html').css(
- {
- 'scroll-padding-top': headerHeight,
- },
-);
-//endregion
\ No newline at end of file
+////region Header & Footer fixe (overlay)
+//const headerHeight = Utils.getElementRealHeight($('header:not(.overlay-not-fixed)'));
+//const footerHeight = Utils.getElementRealHeight($('footer:not(.overlay-not-fixed)'));
+//$('#div-body').css(
+// {
+// 'padding-top': headerHeight,
+// 'padding-bottom': footerHeight,
+// },
+//);
+//$('html').css(
+// {
+// 'scroll-padding-top': headerHeight,
+// },
+//);
+////endregion
\ No newline at end of file
diff --git a/assets/styles/_layout.scss b/assets/styles/_layout.scss
index 7300cec..86cce84 100644
--- a/assets/styles/_layout.scss
+++ b/assets/styles/_layout.scss
@@ -15,4 +15,12 @@ header {
}
footer {
bottom : 0;
+}
+
+#div-body {
+ padding-top : 21px;
+ padding-bottom : 0;
+}
+html {
+ scroll-padding-top : 21px
}
\ No newline at end of file
diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php
index 7f82acd..2f09d85 100644
--- a/src/Controller/UserController.php
+++ b/src/Controller/UserController.php
@@ -3,6 +3,7 @@
namespace App\Controller;
use App\Entity\User;
+use App\Form\SignInFormType;
use App\Form\SignUpFormType;
use App\Repository\UserRepository;
use App\Security\EmailVerifier;
@@ -21,6 +22,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
class UserController extends AbstractController {
+ /**
+ * @var TranslatorInterface The translator service
+ */
+ private readonly TranslatorInterface $translator;
/**
* @var EmailVerifier The email verifier service
*/
@@ -29,16 +34,18 @@ class UserController extends AbstractController {
/**
* Initialisation
*
- * @param EmailVerifier $emailVerifier The email verifier service
+ * @param TranslatorInterface $translator The translator service
+ * @param EmailVerifier $emailVerifier The email verifier service
*/
- public function __construct (EmailVerifier $emailVerifier) {
+ public function __construct (TranslatorInterface $translator, EmailVerifier $emailVerifier) {
+ $this->translator = $translator;
$this->emailVerifier = $emailVerifier;
}
/**
* Register a new user
*
- * @param Request $request The query
+ * @param Request $request The request
* @param UserPasswordHasherInterface $userPasswordHasher The password hashing service
* @param EntityManagerInterface $entityManager The entity manager
*
@@ -126,12 +133,13 @@ class UserController extends AbstractController {
/**
* Sign in a user
*
+ * @param Request $request The request
* @param AuthenticationUtils $authenticationUtils Security errors from query
*
* @return Response The response
*/
#[Route(path: '/signIn', name: 'user_signIn')]
- public function login (AuthenticationUtils $authenticationUtils): Response {
+ public function login (Request $request, AuthenticationUtils $authenticationUtils): Response {
/** @var User|null $user */
$user = $this->getUser();
if ($user !== null) {
@@ -141,14 +149,13 @@ class UserController extends AbstractController {
);
}
- $error = $authenticationUtils->getLastAuthenticationError();
-
- $lastUsername = $authenticationUtils->getLastUsername();
+ if (($error = $authenticationUtils->getLastAuthenticationError()) !== null) {
+ $this->addFlash('danger', $this->translator->trans($error->getMessageKey(), $error->getMessageData(), 'security'));
+ }
return $this->render(
'user/signIn.html.twig',
[
- 'last_username' => $lastUsername,
- 'error' => $error,
+ 'last_username' => $authenticationUtils->getLastUsername(),
]
);
}
diff --git a/src/Security/UserChecker.php b/src/Security/UserChecker.php
index 6d96073..fe9231c 100644
--- a/src/Security/UserChecker.php
+++ b/src/Security/UserChecker.php
@@ -9,6 +9,10 @@ use Symfony\Component\Security\Core\User\UserInterface;
/**
* Check if a user is valid for authentification
+ *
+ * The user must have:
+ * - Verified his email
+ * - Account validated by administrator
*/
class UserChecker implements UserCheckerInterface {
/**
@@ -20,10 +24,10 @@ class UserChecker implements UserCheckerInterface {
}
if (!$user->isVerified()) {
- throw new CustomUserMessageAccountStatusException('Your account mail has not been validated.');
+ throw new CustomUserMessageAccountStatusException('user.emailNotVerified');
}
if ($user->getValidationAdministrator() === null || $user->getValidationDate() === null) {
- throw new CustomUserMessageAccountStatusException('Your account has not been validated by an administrator yet.');
+ throw new CustomUserMessageAccountStatusException('user.notValidatedByAdmin');
}
}
/**
diff --git a/templates/_flashes.html.twig b/templates/_flashes.html.twig
index 0bfa03b..a9a0988 100644
--- a/templates/_flashes.html.twig
+++ b/templates/_flashes.html.twig
@@ -1,12 +1,15 @@
{% block flashTag %}
-
- {% endblock %}
- {% for flashType, flashMessages in app.flashes %}
- {% for flashMessage in flashMessages %}
-
- {{ flashMessage }}
-
-
- {% endfor %}
- {% endfor %}
-
\ No newline at end of file
+ {% set flashes = app.flashes %}
+ {% if flashes|length > 0 %}
+
+ {% for flashType, flashMessages in flashes %}
+ {% for flashMessage in flashMessages %}
+
+ ]]>
+
+
+
+
+
+
+ pages.signIn
+ Connexion
+
+
+
+
+ pages.signUp
+ Nouveau compte
+
+
+
+
+ pages.signOut
+ Déconnexion
+
+
+
+
+
+
+
+ fields.email.label
+ Email
+
+
+
+
+
+
+ fields.password.label
+ Mot de passe
+
+
+
+
+
+
+ fields.rememberMe.label
+ Se souvenir de moi
+
+
+
+
+
+ fields.signIn
+ Connexion
+
+
+
+
+
\ No newline at end of file
diff --git a/translations/security+intl-icu.en.xlf b/translations/security+intl-icu.en.xlf
new file mode 100644
index 0000000..1bc6cae
--- /dev/null
+++ b/translations/security+intl-icu.en.xlf
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ user.emailNotVerified
+ Your account mail has not been verified.
+
+
+
+
+ user.notValidatedByAdmin
+ Your account has not been validated by an administrator yet.
+
+
+
+
+
\ No newline at end of file
diff --git a/translations/security+intl-icu.fr.xlf b/translations/security+intl-icu.fr.xlf
new file mode 100644
index 0000000..0c53549
--- /dev/null
+++ b/translations/security+intl-icu.fr.xlf
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ user.emailNotVerified
+ Vous n'avez pas encore validé votre adresse email.
+
+
+
+
+ user.notValidatedByAdmin
+ Votre compte n'a pas encore été validé par un administrateur.
+
+
+
+
+
\ No newline at end of file