From a91096224561821cba080ed47b965def85c7937a Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Tue, 21 May 2024 17:42:19 +0200 Subject: [PATCH] Manage translations for email confirmation and verification --- src/Controller/UserController.php | 27 +++++--- templates/base.html.twig | 2 +- templates/user/confirmation_email.html.twig | 11 --- templates/user/emailConfirmation.html.twig | 4 ++ templates/user/signIn.html.twig | 4 +- translations/messages+intl-icu.en.xlf | 77 +++++++++++++++++++-- translations/messages+intl-icu.fr.xlf | 77 +++++++++++++++++++-- 7 files changed, 168 insertions(+), 34 deletions(-) delete mode 100644 templates/user/confirmation_email.html.twig create mode 100644 templates/user/emailConfirmation.html.twig diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 72cb7ec..330ee45 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -60,18 +60,19 @@ class UserController extends AbstractController { $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // encode the plain password + //region encode the plain password $user->setPassword( $userPasswordHasher->hashPassword( $user, $form->get('newPassword')->getData() ) ); + //endregion $entityManager->persist($user); $entityManager->flush(); - // Generate the mail with the link to verify the account + //region Generate the mail with the link to verify the account $this->emailVerifier->sendEmailConfirmation( 'user_mailVerify', $user, @@ -83,11 +84,12 @@ class UserController extends AbstractController { ) ) ->to($user->getEmail()) - ->subject('Please Confirm your Email') - ->htmlTemplate('user/confirmation_email.html.twig') + ->subject($this->translator->trans('emails.emailConfirmation.subject')) + ->htmlTemplate('user/emailConfirmation.html.twig') ); + //endregion - $this->addFlash('info', 'Please validate your account through the confirmation mail'); + $this->addFlash('info', $this->translator->trans('pages.signUp.emailConfirmationMessage')); return $this->redirectToRoute('core_main'); } @@ -106,22 +108,26 @@ class UserController extends AbstractController { */ #[Route('/emailVerify', name: 'user_mailVerify')] public function verifyUserEmail (Request $request, TranslatorInterface $translator, UserRepository $userRepository): Response { + //region Get the user id from query $id = $request->query->get('id'); if ($id === null) { + $this->addFlash('danger', $this->translator->trans('pages.emailVerify.errorId')); return $this->redirectToRoute('user_signUp'); } - + //endregion + //region Get the user himself $user = $userRepository->find($id); if ($user === null) { + $this->addFlash('danger', $this->translator->trans('pages.emailVerify.errorUser')); return $this->redirectToRoute('user_signUp'); } + //endregion try { $this->emailVerifier->handleEmailConfirmation($request, $user); } catch (VerifyEmailExceptionInterface $exception) { $this->addFlash('verify_email_error', $translator->trans($exception->getReason(), [], 'VerifyEmailBundle')); - return $this->redirectToRoute('user_signUp'); } @@ -143,7 +149,12 @@ class UserController extends AbstractController { if ($user !== null) { $this->addFlash( 'warning', - 'You are already logged in, please sign out first.' + $this->translator->trans( + 'pages.emailVerify.warningAlreadyConnected', + [ + 'signOutUrl' => $this->generateUrl('user_signOut'), + ] + ) ); } diff --git a/templates/base.html.twig b/templates/base.html.twig index e9a5eb5..e830643 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -15,7 +15,7 @@