diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index dbd30a01c0..ebf8cbf354 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -52,7 +52,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Address; -use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -291,7 +290,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $formClassDetails = $this->generateFormClass( $userClassNameDetails, $generator, - $usernameField + $usernameField, + $this->passwordField ); // 2) Generate the controller @@ -307,7 +307,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen Request::class, Response::class, Route::class, - UserPasswordHasherInterface::class, EntityManagerInterface::class, ]); @@ -355,7 +354,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'route_name' => 'app_register', 'form_class_name' => $formClassDetails->getShortName(), 'user_class_name' => $userClassNameDetails->getShortName(), - 'password_field' => $this->passwordField, 'redirect_route_name' => $this->redirectRouteName ?? null, 'translator_available' => $isTranslatorAvailable, ], @@ -545,7 +543,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void ); } - private function generateFormClass(ClassNameDetails $userClassDetails, Generator $generator, string $usernameField): ClassNameDetails + private function generateFormClass(ClassNameDetails $userClassDetails, Generator $generator, string $usernameField, string $passwordField): ClassNameDetails { $formClassDetails = $generator->createClassNameDetails( 'RegistrationFormType', @@ -568,9 +566,8 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator 'plainPassword' => [ 'type' => PasswordType::class, 'options_code' => << false, + 'hash_property_path' => '$passwordField', 'attr' => ['autocomplete' => 'new-password'], 'constraints' => [ new NotBlank([ diff --git a/src/Resources/skeleton/registration/RegistrationController.tpl.php b/src/Resources/skeleton/registration/RegistrationController.tpl.php index 77969a1cf5..f28b2f1359 100644 --- a/src/Resources/skeleton/registration/RegistrationController.tpl.php +++ b/src/Resources/skeleton/registration/RegistrationController.tpl.php @@ -13,21 +13,13 @@ public function __construct(private getPropertyType($email_verif generateRouteForControllerMethod($route_path, $route_name) ?> - public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response + public function register(Request $request, EntityManagerInterface $entityManager): Response { $user = new (); $form = $this->createForm(::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // encode the plain password - $user->set( - $userPasswordHasher->hashPassword( - $user, - $form->get('plainPassword')->getData() - ) - ); - $entityManager->persist($user); $entityManager->flush();