src/EventSubscriber/EmailConfirmationListenerNew.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\QI;
  4. use FOS\UserBundle\Event\FormEvent;
  5. use FOS\UserBundle\FOSUserEvents;
  6. use FOS\UserBundle\Mailer\MailerInterface;
  7. use FOS\UserBundle\Util\TokenGeneratorInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. class EmailConfirmationListenerNew implements EventSubscriberInterface
  13. {
  14.     private $mailer;
  15.     private $tokenGenerator;
  16.     private $router;
  17.     private $session;
  18.     /**
  19.      * EmailConfirmationListener constructor.
  20.      */
  21.     public function __constructTokenGeneratorInterface $tokenGeneratorUrlGeneratorInterface $routerSessionInterface $sessionQI $qi)
  22.     {
  23.         $this->tokenGenerator $tokenGenerator;
  24.         $this->router $router;
  25.         $this->session $session;
  26.         $this->qi $qi;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
  35.         ];
  36.     }
  37.     public function onRegistrationSuccess(FormEvent $event)
  38.     {
  39.         /** @var $user \FOS\UserBundle\Model\UserInterface */
  40.         $user $event->getForm()->getData();
  41.         $user->setEnabled(true);
  42.         if (null === $user->getConfirmationToken()) {
  43.             $user->setConfirmationToken($this->tokenGenerator->generateToken());
  44.         }
  45.         //$this->mailer->sendConfirmationEmailMessage($user);
  46.         $this->session->set('fos_user_send_confirmation_email/email'$user->getEmail());
  47.         //$this->qi->sendMailPHP($this->qi->getTexto('asunto_mail_registro'),$user->getEmail(),$this->qi->getTextoBig('mail_registro'));
  48.         $url $this->router->generate('homepage');
  49.         $event->setResponse(new RedirectResponse($url));
  50.     }
  51. }