Request resend of verification mail
This commit is contained in:
@@ -31,7 +31,7 @@ class ActivationController extends AbstractController
|
||||
try {
|
||||
$emailVerifier->handleEmailConfirmation($request, $user);
|
||||
} catch (VerifyEmailExceptionInterface $exception) {
|
||||
$this->addFlash('error', $exception->getReason());
|
||||
$this->addFlash('error', $exception->getReason() . ' If the link has expired, you can <a href="' . $this->generateUrl('app_verify_resend_email') . '">request a new one here</a>.');
|
||||
|
||||
return $this->redirectToRoute('app_register');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace App\Tech\Controller;
|
||||
|
||||
use App\Tech\Entity\User;
|
||||
use App\Tech\Form\RegistrationFormType;
|
||||
use App\Tech\Form\ResendVerificationEmailFormType;
|
||||
use App\Tech\Repository\UserRepository;
|
||||
use App\Tech\Service\EmailVerifier;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
@@ -54,4 +56,41 @@ class RegistrationController extends AbstractController
|
||||
'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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user