<?php
namespace App\EventSubscriber;
use App\Service\QI;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Mailer\MailerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class EmailConfirmationListenerNew implements EventSubscriberInterface
{
private $mailer;
private $tokenGenerator;
private $router;
private $session;
/**
* EmailConfirmationListener constructor.
*/
public function __construct( TokenGeneratorInterface $tokenGenerator, UrlGeneratorInterface $router, SessionInterface $session, QI $qi)
{
$this->tokenGenerator = $tokenGenerator;
$this->router = $router;
$this->session = $session;
$this->qi = $qi;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
];
}
public function onRegistrationSuccess(FormEvent $event)
{
/** @var $user \FOS\UserBundle\Model\UserInterface */
$user = $event->getForm()->getData();
$user->setEnabled(true);
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($this->tokenGenerator->generateToken());
}
//$this->mailer->sendConfirmationEmailMessage($user);
$this->session->set('fos_user_send_confirmation_email/email', $user->getEmail());
//$this->qi->sendMailPHP($this->qi->getTexto('asunto_mail_registro'),$user->getEmail(),$this->qi->getTextoBig('mail_registro'));
$url = $this->router->generate('homepage');
$event->setResponse(new RedirectResponse($url));
}
}