createForm(RegistrationFormType::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // encode the plain password $user->setPassword( $userPasswordHasher->hashPassword( $user, $form->get('plainPassword')->getData() ) ); $user->setRoles(['ROLE_USER', 'ROLE_PLAYER']); $entityManager->persist($user); $entityManager->flush(); // generate a signed url and email it to the user $emailVerifier->sendEmailConfirmation('app_verify_email', $user, (new TemplatedEmail()) ->from($this->getParameter('mailer_from')) ->to($user->getEmail()) ->subject('Please Confirm your Email') ->htmlTemplate('tech/registration/confirmation_email.html.twig') ); $this->addFlash('success', 'A confirmation email has been sent to your email address.'); return $this->redirectToRoute('website_home'); } return $this->render('tech/registration/register.html.twig', [ 'registrationForm' => $form->createView(), ]); } #[Route('/verify/resend', name: 'app_verify_resend_email')] public function resendVerificationEmail(Request $request, UserRepository $userRepository, EmailVerifier $emailVerifier): Response { $form = $this->createForm(ResendVerificationEmailFormType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $email = $form->get('email')->getData(); $user = $userRepository->findOneBy(['email' => $email]); if ($user) { if (!$user->isVerified()) { $emailVerifier->sendEmailConfirmation('app_verify_email', $user, (new TemplatedEmail()) ->from($this->getParameter('mailer_from')) ->to($user->getEmail()) ->subject('Please Confirm your Email') ->htmlTemplate('tech/registration/confirmation_email.html.twig') ); } else { $this->addFlash('info', 'This email address is already verified.'); return $this->redirectToRoute('app_login'); } } // We show the same success message regardless of whether the user exists or not, // to avoid revealing whether an email is registered. $this->addFlash('success', 'If an account exists with this email, a new confirmation link has been sent.'); return $this->redirectToRoute('website_home'); } return $this->render('tech/registration/resend_verification_email.html.twig', [ 'resendForm' => $form->createView(), ]); } }