|
@@ -0,0 +1,39 @@
|
|
|
+<?php
|
|
|
+namespace AppBundle\Service;
|
|
|
+
|
|
|
+use AppBundle\Entity\User;
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
|
|
+use Symfony\Component\HttpKernel\HttpKernel;
|
|
|
+use Symfony\Component\Security\Core\Security;
|
|
|
+
|
|
|
+class ActivityListener
|
|
|
+{
|
|
|
+ private $em;
|
|
|
+ private $security;
|
|
|
+
|
|
|
+ public function __construct(EntityManagerInterface $em, Security $security)
|
|
|
+ {
|
|
|
+ $this->em = $em;
|
|
|
+ $this->security = $security;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function onCoreController(FilterControllerEvent $event)
|
|
|
+ {
|
|
|
+ // Check that the current request is a "MASTER_REQUEST"
|
|
|
+ // Ignore any sub-request
|
|
|
+ if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check token authentication availability
|
|
|
+ if ($this->security->getToken()) {
|
|
|
+ $user = $this->security->getToken()->getUser();
|
|
|
+
|
|
|
+ if ( ($user instanceof User) && !($user->isActiveNow()) ) {
|
|
|
+ $user->setLastActivity(new \DateTime());
|
|
|
+ $this->em->flush();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|