private EmailVerifier $emailVerifier;

    public function __construct(EmailVerifier $emailVerifier, EntityManagerInterface $entityManager)
    {
        $this->emailVerifier = $emailVerifier;
    }

here i have autowired the EmailVerifier in RegistrationController.php


    #[Route('/verify/email', name: 'app_verify_email')]
    public function verifyUserEmail(Request $request, TranslatorInterface $translator, UserRepository $userRepository): Response
    {   

        // $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

        // validate email confirmation link, sets User::isVerified=true and persists

        $id = $request->get('id');
        try {
            $user = $userRepository->find($id);
            // dd($user);

            $this->emailVerifier->handleEmailConfirmation($request, $user);
        } catch (VerifyEmailExceptionInterface $exception) {
            dd("inside catch");
            $this->addFlash('verify_email_error', $translator->trans($exception->getReason(), [], 'VerifyEmailBundle'));
            return $this->redirectToRoute('app_register');
        }
        $user->setIsVerified(true);

        $entityManager->persist($user);
        $entityManager->flush();
        // @TODO Change the redirect on success and handle or remove the flash message in your templates
        $this->addFlash('success', 'Your email address has been verified.');

        return $this->redirectToRoute('app_register');
    }

Cannot autowire service "App\Security\EmailVerifier": argument "$verifyEmailHelper" of method "__construct()" references interface "SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface" but no such service exists. Did you create a class that implements this interface?

1

There are 1 best solutions below

0
Sara Rodriguez Cubillas On

composer require symfonycasts/verify-email-bundle symfony/mailer