tinternet.net/src/EventSuscriber/Account/PasswordRequestEventSubscri...

51 lines
1.4 KiB
PHP

<?php
namespace App\EventSuscriber\Account;
use App\Event\Account\PasswordRequestEvent;
use App\Notification\MailNotifier;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* class EventListener.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class PasswordRequestEventSubscriber implements EventSubscriberInterface
{
protected MailNotifier $notifier;
protected UrlGeneratorInterface $urlGenerator;
public function __construct(MailNotifier $notifier, UrlGeneratorInterface $urlGenerator)
{
$this->notifier = $notifier;
$this->urlGenerator = $urlGenerator;
}
public static function getSubscribedEvents()
{
return [
PasswordRequestEvent::EVENT => 'onRequest',
];
}
public function onRequest(PasswordRequestEvent $event)
{
$this->notifier
->setFrom('system@tinternet.net')
->setSubject('[Tinternet & cie] Mot de passe perdu')
->addRecipient($event->getUser()->getEmail())
->notify('resetting_request', [
'reseting_update_link' => $this->urlGenerator->generate(
'auth_resetting_update',
[
'token' => $event->getUser()->getConfirmationToken(),
],
UrlGeneratorInterface::ABSOLUTE_URL
),
])
;
}
}