<?php
namespace App\Infrastructure\Mailing\Subscriber;
use App\Domain\Password\Event\PasswordResetTokenCreatedEvent;
use App\Infrastructure\Mailing\Mailer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AuthSubscriber implements EventSubscriberInterface
{
private Mailer $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public static function getSubscribedEvents(): array
{
return [
PasswordResetTokenCreatedEvent::class => 'onPasswordRequest'
];
}
public function onPasswordRequest(PasswordResetTokenCreatedEvent $event): void
{
$email = $this->mailer->createEmail('mails/auth/password_reset.twig', [
'token' => $event->getToken()->getToken(),
'id' => $event->getUser()->getId(),
'username' => $event->getUser()->getUsername(),
])
->to($event->getUser()->getEmail())
->subject('Mandalas | RĂ©initialisation de votre mot de passe');
$this->mailer->send($email);
}
}