diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index bd70e0be7..55bba0ec8 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -50,7 +50,9 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface; +use Symfony\Component\Translation\Translator; use Symfony\Component\Validator\Validation; +use Symfony\Contracts\Translation\TranslatorInterface; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; use SymfonyCasts\Bundle\VerifyEmail\Model\VerifyEmailSignatureComponents; use SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle; @@ -324,6 +326,10 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen } } + if ($isTranslatorAvailable = class_exists(Translator::class)) { + $useStatements[] = TranslatorInterface::class; + } + $generator->generateController( $controllerClassNameDetails->getFullName(), 'registration/RegistrationController.tpl.php', @@ -348,6 +354,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'password_hasher_class_details' => ($passwordClassDetails = $generator->createClassNameDetails($passwordHasher, '\\')), 'password_hasher_variable_name' => str_replace('Interface', '', sprintf('$%s', lcfirst($passwordClassDetails->getShortName()))), // @legacy see passwordHasher conditional above 'use_password_hasher' => UserPasswordHasherInterface::class === $passwordHasher, // @legacy see passwordHasher conditional above + 'translator_available' => $isTranslatorAvailable, ], $userRepoVars ) diff --git a/src/Resources/skeleton/registration/RegistrationController.tpl.php b/src/Resources/skeleton/registration/RegistrationController.tpl.php index 187f92acf..de8f192d8 100644 --- a/src/Resources/skeleton/registration/RegistrationController.tpl.php +++ b/src/Resources/skeleton/registration/RegistrationController.tpl.php @@ -73,7 +73,7 @@ public function register(Request $request, g generateRouteForControllerMethod('/verify/email', 'app_verify_email') ?> - public function verifyUserEmail(Request $request): Response + public function verifyUserEmail(Request $request, TranslatorInterface $translator): Response { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); @@ -101,7 +101,7 @@ public function verifyUserEmail(Request $requestemailVerifier->handleEmailConfirmation($request, getUser()' ?>); } catch (VerifyEmailExceptionInterface $exception) { - $this->addFlash('verify_email_error', $exception->getReason()); + $this->addFlash('verify_email_error', $translator->trans($exception->getReason(), [], 'VerifyEmailBundle')$exception->getReason()); return $this->redirectToRoute(''); } diff --git a/tests/Maker/MakeRegistrationFormTest.php b/tests/Maker/MakeRegistrationFormTest.php index 10438a9ad..6e4e612d2 100644 --- a/tests/Maker/MakeRegistrationFormTest.php +++ b/tests/Maker/MakeRegistrationFormTest.php @@ -165,6 +165,37 @@ public function getTestDetails() $this->runRegistrationTest($runner, 'it_generates_registration_form_with_verification.php'); }), ]; + + yield 'it_generates_registration_form_with_verification_and_translator' => [$this->createRegistrationFormTest() + ->setRequiredPhpVersion(70200) + ->addExtraDependencies('symfonycasts/verify-email-bundle') + // needed for internal functional test + ->addExtraDependencies('symfony/web-profiler-bundle', 'mailer', 'symfony/translation') + ->run(function (MakerTestRunner $runner) { + $runner->writeFile( + 'config/packages/mailer.yaml', + Yaml::dump(['framework' => [ + 'mailer' => ['dsn' => 'null://null'], + ]]) + ); + + $this->makeUser($runner); + + $output = $runner->runMaker([ + 'n', // add UniqueEntity + 'y', // verify user + 'y', // require authentication to verify user email + 'victor@symfonycasts.com', // from email address + 'SymfonyCasts', // From Name + 'n', // no authenticate after + 0, // route number to redirect to + ]); + + $this->assertStringContainsString('Success', $output); + + $this->runRegistrationTest($runner, 'it_generates_registration_form_with_verification.php'); + }), + ]; } private function makeUser(MakerTestRunner $runner, string $identifier = 'email')