Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <?php
  2.  
  3. namespace PMB\UserBundle\Listener;
  4. use PMB\UserBundle\Entity\UserLogs;
  5. use PMB\UserBundle\Entity\User;
  6. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  7. use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
  8. use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  13. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  14.  
  15. class RegisterListener
  16. {
  17. protected $doctrine;
  18. protected $storage;
  19. protected $mailer;
  20.  
  21. public function __construct(Doctrine $doctrine, TokenStorageInterface $storage, \Swift_Mailer $mailer)
  22. {
  23. $this->doctrine = $doctrine;
  24. $this->storage = $storage;
  25. $this->mailer = $mailer;
  26. }
  27.  
  28. /**
  29. * Record login actions to LogsLogin
  30. *
  31. */
  32.  
  33. public function onRegister(\FOS\UserBundle\Event\FilterUserResponseEvent $event)
  34. {
  35.  
  36. $userLogs = new UserLogs();
  37. $userLogs->setDateConnexion(new \DateTime('now'));
  38. $userLogs->setUser($event->getUser());
  39. $em = $this->doctrine->getManager();
  40. $em->persist($userLogs);
  41. $em->flush();
  42.  
  43. $message = \Swift_Message::newInstance()
  44. ->setSubject('Registration Email')
  45. ->setFrom('CarnetNumerique@pmb-software.com')
  46. ->setTo('mazzathibault@gmail.com')
  47. ->setBody(
  48. $this->renderView(
  49. // app/Resources/views/Emails/registration.html.twig
  50. 'Emails/registration.html.twig',
  51. array('name' => $event->getUser()->getUsername())
  52. ),
  53. 'text/html'
  54. );
  55.  
  56. $this->get('mailer')->send($message);
  57. }
  58. }
  59.  
  60.  
  61. SERVICE :
  62.  
  63. register:
  64. class: PMB\UserBundle\Listener\RegisterListener
  65. arguments: ['@doctrine', '@security.token_storage', '@mailer']
  66. tags:
  67. - { name: kernel.event_listener,
  68. event : fos_user.registration.completed,
  69. method: onRegister }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement