src/Infrastructure/Mailing/Subscriber/AuthSubscriber.php line 25

  1. <?php
  2. namespace App\Infrastructure\Mailing\Subscriber;
  3. use App\Domain\Password\Event\PasswordResetTokenCreatedEvent;
  4. use App\Infrastructure\Mailing\Mailer;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class AuthSubscriber implements EventSubscriberInterface
  7. {
  8.     private Mailer $mailer;
  9.     public function __construct(Mailer $mailer)
  10.     {
  11.         $this->mailer $mailer;
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             PasswordResetTokenCreatedEvent::class => 'onPasswordRequest'
  17.         ];
  18.     }
  19.     public function onPasswordRequest(PasswordResetTokenCreatedEvent $event): void
  20.     {
  21.         $user $event->getUser();
  22.         $email $this->mailer->createEmail('mails/auth/password_reset.twig', [
  23.             'token' => $event->getToken()->getToken(),
  24.             'id' => $user->getId(),
  25.             'username' => $user->getUsername(),
  26.             'user' => $user,
  27.             'route' => 'admin_auth_password_reset_confirm'
  28.         ])
  29.             ->to($event->getUser()->getEmail())
  30.             ->subject('AW | RĂ©initialisation de votre mot de passe');
  31.         $this->mailer->send($email);
  32.     }
  33. }