src/EventListener/LoginEventListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\User;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  6. class LoginEventListener
  7. {
  8.     private $em;
  9.     public function __construct(EntityManagerInterface $em)
  10.     {
  11.         $this->em $em;
  12.     }
  13.     public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
  14.     {
  15.         $user $event->getAuthenticationToken()->getUser();
  16.         if (is_a($userUser::class) ) {
  17.             $user->setLastConnection(new \DateTime());
  18.             $this->em->persist($user);
  19.             $this->em->flush();
  20.         }
  21.     }
  22. }