Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace PMB\UserBundle\Listener;
- use PMB\UserBundle\Entity\UserLogs;
- use PMB\UserBundle\Entity\User;
- use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
- use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
- use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\DependencyInjection\ContainerInterface as Container;
- class RegisterListener
- {
- protected $doctrine;
- protected $storage;
- protected $mailer;
- public function __construct(Doctrine $doctrine, TokenStorageInterface $storage, \Swift_Mailer $mailer)
- {
- $this->doctrine = $doctrine;
- $this->storage = $storage;
- $this->mailer = $mailer;
- }
- /**
- * Record login actions to LogsLogin
- *
- */
- public function onRegister(\FOS\UserBundle\Event\FilterUserResponseEvent $event)
- {
- $userLogs = new UserLogs();
- $userLogs->setDateConnexion(new \DateTime('now'));
- $userLogs->setUser($event->getUser());
- $em = $this->doctrine->getManager();
- $em->persist($userLogs);
- $em->flush();
- $message = \Swift_Message::newInstance()
- ->setSubject('Registration Email')
- ->setFrom('CarnetNumerique@pmb-software.com')
- ->setTo('mazzathibault@gmail.com')
- ->setBody(
- $this->renderView(
- // app/Resources/views/Emails/registration.html.twig
- 'Emails/registration.html.twig',
- array('name' => $event->getUser()->getUsername())
- ),
- 'text/html'
- );
- $this->get('mailer')->send($message);
- }
- }
- SERVICE :
- register:
- class: PMB\UserBundle\Listener\RegisterListener
- arguments: ['@doctrine', '@security.token_storage', '@mailer']
- tags:
- - { name: kernel.event_listener,
- event : fos_user.registration.completed,
- method: onRegister }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement