diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index bdde8ebb7..5fe6a6d88 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -50,7 +50,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Translation\Translator; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; @@ -214,16 +213,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'Form\\' ); - /* - * @legacy Conditional can be removed when MakerBundle no longer - * supports Symfony < 5.2 - */ - $passwordHasher = UserPasswordEncoderInterface::class; - - if (interface_exists(UserPasswordHasherInterface::class)) { - $passwordHasher = UserPasswordHasherInterface::class; - } - $useStatements = new UseStatementGenerator([ AbstractController::class, $userClassNameDetails->getFullName(), @@ -239,7 +228,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen ResetPasswordControllerTrait::class, ResetPasswordExceptionInterface::class, ResetPasswordHelperInterface::class, - $passwordHasher, + UserPasswordHasherInterface::class, EntityManagerInterface::class, ]); @@ -269,9 +258,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'from_email_name' => $this->fromEmailName, 'email_getter' => $this->emailGetterMethodName, 'email_field' => $this->emailPropertyName, - '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 'problem_validate_message_or_constant' => $problemValidateMessageOrConstant, 'problem_handle_message_or_constant' => $problemHandleMessageOrConstant, 'translator_available' => $isTranslatorAvailable, diff --git a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php index e0ea1da27..1eefcdb12 100644 --- a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php +++ b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php @@ -58,7 +58,7 @@ public function checkEmail(): Response * Validates and process the reset URL that the user clicked in their email. */ #[Route('/reset/{token}', name: 'app_reset_password')] - public function reset(Request $request, getShortName() ?> , TranslatorInterface $translator, string $token = null): Response + public function reset(Request $request, UserPasswordHasherInterface $passwordHasher, TranslatorInterface $translator, string $token = null): Response { if ($token) { // We store the token in session and remove it from the URL, to avoid the URL being @@ -94,7 +94,7 @@ public function reset(Request $request, getS $this->resetPasswordHelper->removeResetRequest($token); // Encode(hash) the plain password, and set it. - $encodedPassword = ->( + $encodedPassword = $passwordHasher->hashPassword( $user, $form->get('plainPassword')->getData() ); diff --git a/tests/Maker/MakeResetPasswordTest.php b/tests/Maker/MakeResetPasswordTest.php index 88981ceaf..f7206bd86 100644 --- a/tests/Maker/MakeResetPasswordTest.php +++ b/tests/Maker/MakeResetPasswordTest.php @@ -64,7 +64,19 @@ public function getTestDetails(): \Generator $this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); - $this->runResetPasswordTest($runner, 'it_generates_with_normal_setup.php'); + $runner->writeFile( + 'config/packages/mailer.yaml', + Yaml::dump(['framework' => [ + 'mailer' => ['dsn' => 'null://null'], + ]]) + ); + + $runner->copy( + 'make-reset-password/tests/it_generates_with_normal_setup.php', + 'tests/ResetPasswordFunctionalTest.php' + ); + + $runner->runTests(); }), ]; @@ -105,6 +117,7 @@ public function getTestDetails(): \Generator $this->assertStringContainsString('Success', $output); + // @legacy - conditional can be removed when PHPUnit 9.x is no longer supported. if (method_exists($this, 'assertFileDoesNotExist')) { $this->assertFileDoesNotExist($runner->getPath('config/packages/reset_password.yaml')); } else { @@ -184,23 +197,6 @@ public function getTestDetails(): \Generator ]; } - private function runResetPasswordTest(MakerTestRunner $runner, string $filename): void - { - $runner->writeFile( - 'config/packages/mailer.yaml', - Yaml::dump(['framework' => [ - 'mailer' => ['dsn' => 'null://null'], - ]]) - ); - - $runner->copy( - 'make-reset-password/tests/'.$filename, - 'tests/ResetPasswordFunctionalTest.php' - ); - - $runner->runTests(); - } - private function makeUser(MakerTestRunner $runner, string $identifier = 'email', string $userClass = 'User', bool $checkPassword = true): void { $runner->runConsole('make:user', [