diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 862ddc2..0355724 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -13,9 +13,9 @@ class LoginController extends AbstractController #[Route('/login', name: 'login')] public function login(AuthenticationUtils $authenticationUtils): Response { - // if ($this->getUser()) { - // return $this->redirectToRoute('target_path'); - // } + if ($this->getUser()) { + return $this->redirectToRoute('home'); + } // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError(); diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 6487beb..f71e182 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -13,8 +13,12 @@ use Symfony\Component\Routing\Annotation\Route; class RegistrationController extends AbstractController { - #[Route('/register', name: 'app_register')] - public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response + #[Route('/register', name: 'register')] + public function register( + Request $request, + UserPasswordHasherInterface $userPasswordHasher, + EntityManagerInterface $entityManager + ): Response { $user = new User(); $form = $this->createForm(RegistrationFormType::class, $user); @@ -23,7 +27,7 @@ class RegistrationController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { // encode the plain password $user->setPassword( - $userPasswordHasher->hashPassword( + $userPasswordHasher->hashPassword( $user, $form->get('plainPassword')->getData() ) diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php index e9651c8..c2fa6d6 100644 --- a/src/Form/RegistrationFormType.php +++ b/src/Form/RegistrationFormType.php @@ -6,6 +6,7 @@ use App\Entity\User; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\IsTrue; @@ -18,14 +19,6 @@ class RegistrationFormType extends AbstractType { $builder ->add('username') - ->add('agreeTerms', CheckboxType::class, [ - 'mapped' => false, - 'constraints' => [ - new IsTrue([ - 'message' => 'You should agree to our terms.', - ]), - ], - ]) ->add('plainPassword', PasswordType::class, [ // instead of being set onto the object directly, // this is read and encoded in the controller @@ -43,6 +36,15 @@ class RegistrationFormType extends AbstractType ]), ], ]) + ->add('agreeTerms', CheckboxType::class, [ + 'mapped' => false, + 'constraints' => [ + new IsTrue([ + 'message' => 'You should agree to our terms.', + ]), + ], + ]) + ->add('register', SubmitType::class) ; } diff --git a/templates/security/register.html.twig b/templates/security/register.html.twig index 1f8256d..d558e9e 100644 --- a/templates/security/register.html.twig +++ b/templates/security/register.html.twig @@ -3,13 +3,5 @@ {% block body %}

Register

- {{ form_start(registrationForm) }} - {{ form_row(registrationForm.username) }} - {{ form_row(registrationForm.plainPassword, { - label: 'Password' - }) }} - {{ form_row(registrationForm.agreeTerms) }} - - - {{ form_end(registrationForm) }} + {{ form(registrationForm) }} {% endblock %}