*/ class PasswordRequestEventSubscriber implements EventSubscriberInterface { protected MailNotifier $notifier; protected UrlGeneratorInterface $urlGenerator; protected EntityManager $entityManager; protected TokenGeneratorInterface $tokenGenerator; public function __construct( MailNotifier $notifier, UrlGeneratorInterface $urlGenerator, EntityManager $entityManager, TokenGeneratorInterface $tokenGenerator ) { $this->notifier = $notifier; $this->urlGenerator = $urlGenerator; $this->entityManager = $entityManager; $this->tokenGenerator = $tokenGenerator; } public static function getSubscribedEvents() { return [ PasswordRequestEvent::EVENT => 'onRequest', ]; } public function onRequest(PasswordRequestEvent $event) { $user = $event->getUser(); $user->setConfirmationToken($this->tokenGenerator->generateToken()); $user->setPasswordRequestedAt(new \DateTime('now')); $this->entityManager->update($user); $this->notifier ->setSubject('Mot de passe perdu') ->addRecipient($user->getEmail()) ->notify('@Core/mail/account/resetting_request.html.twig', [ 'reseting_update_link' => $this->urlGenerator->generate( 'auth_resetting_update', [ 'token' => $user->getConfirmationToken(), ], UrlGeneratorInterface::ABSOLUTE_URL ), ]) ; } }