src/EventSubscriber/EasyAdminSubscriber.php line 28

Open in your IDE?
  1. <?php 
  2. namespace App\EventSubscriber;
  3. use App\Entity\Site\User;
  4. use App\Service\EmailService;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
  8. class EasyAdminSubscriber implements EventSubscriberInterface
  9. {
  10.     private $resetPasswordHelper$emailService;
  11.     public function __construct(ResetPasswordHelperInterface $resetPasswordHelperEmailService $emailService )
  12.     {
  13.         $this->emailService $emailService;
  14.         $this->resetPasswordHelper $resetPasswordHelper;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             AfterEntityPersistedEvent::class => ['sendUserPasswordEmail'],
  20.         ];
  21.     }
  22.     public function sendUserPasswordEmail(AfterEntityPersistedEvent $event)
  23.     {
  24.         $entity $event->getEntityInstance();
  25.         if (!($entity instanceof User)) {
  26.             return;
  27.         }
  28.         $resetToken $this->resetPasswordHelper->generateResetToken($entity);
  29.         $this->emailService->send([$entity->getEmail()], "email/accountCreated.html.twig""Création de votre mot de passe", ['resetToken' => $resetToken, ] );
  30.     }
  31. }