Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace PMB\UserBundle\Listener;
- use PMB\UserBundle\Entity\UserLogs;
- class ListenerLogs
- {
- protected $doctrine;
- public function __construct(\Doctrine\ORM\EntityManager $doctrine)
- {
- $this->doctrine = $doctrine;
- }
- /**
- * Record login actions to LogsLogin
- * @param InteractiveLoginEvent $event
- */
- public function onLogin(\Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event)
- {
- $user = $event->getAuthenticationToken()->getUser();
- if($user instanceof Partner)
- {
- $userLogs = new UserLogs();
- $userLogs->setDateConnexion(new \DateTime('now'));
- $userLogs->setIpAddress($event->getRequest()->getClientIp());
- $em = $this->doctrine->getManager();
- $em->persist($userLogs);
- $em->flush();
- }
- }
- }
- SERVICE :
- pmb.numeric.listener_logs:
- class: PMB\UserBundle\Listener\ListenerLogs
- arguments: ['@doctrine.orm.entity_manager']
- tags:
- - { name: kernel.event_listener, event: security.interactive_login, method: onLogin }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement