<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Social\UserBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\FOSUserEvents;
use Social\FrontendBundle\Entity\BootLiveSchedule;
use Social\InternalBundle\Entity\BootProfile;
use Social\UserBundle\Entity\User;
use FOS\UserBundle\Event\FormEvent;
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 EmailConfirmationListener
*
* @package Social\UserBundle\EventListener
*/
class EmailConfirmationListener implements EventSubscriberInterface
{
/**
* @var MailerInterface $mailer
*/
private $mailer;
/**
* @var TokenGeneratorInterface $tokenGenerator
*/
private $tokenGenerator;
/**
* @var UrlGeneratorInterface $router
*/
private $router;
/**
* @var SessionInterface $session
*/
private $session;
/**
* @var EntityManagerInterface
*/
private $em;
/**
* EmailConfirmationListener constructor.
*
* @param MailerInterface $mailer
* @param TokenGeneratorInterface $tokenGenerator
* @param UrlGeneratorInterface $router
* @param SessionInterface $session
* @param EntityManagerInterface $entityManager
*/
public function __construct(
MailerInterface $mailer,
TokenGeneratorInterface $tokenGenerator,
UrlGeneratorInterface $router,
SessionInterface $session,
EntityManagerInterface $entityManager
) {
$this->mailer = $mailer;
$this->tokenGenerator = $tokenGenerator;
$this->router = $router;
$this->session = $session;
$this->em = $entityManager;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
];
}
/**
* @param FormEvent $event
*/
public function onRegistrationSuccess(FormEvent $event)
{
/** @var User $user */
$user = $event->getForm()->getData();
$user->setEnabled(true);
$user->setConfirmed(false);
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($this->tokenGenerator->generateToken());
}
$this->mailer->sendConfirmationEmailMessage($user);
}
}