vendor/eckinox/security-bundle/src/EventListener/SecurityListener.php line 27

Open in your IDE?
  1. <?php
  2. namespace Eckinox\SecurityBundle\EventListener;
  3. use App\Entity\Security\AppUser;
  4. use App\Entity\Security\User;
  5. use Eckinox\SecurityBundle\Entity\AbstractAppUser;
  6. use Eckinox\SecurityBundle\Entity\AbstractUser;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\HttpKernel\Event\RequestEvent;
  9. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  10. use Symfony\Component\Routing\RouterInterface;
  11. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  12. class SecurityListener
  13. {
  14.     /**
  15.      * @var TokenStorageInterface
  16.      */
  17.     private $tokenStorage;
  18.     public function __construct(TokenStorageInterface $tokenStorageRouterInterface $router)
  19.     {
  20.         $this->tokenStorage $tokenStorage;
  21.     }
  22.     public function onKernelRequest(RequestEvent $event)
  23.     {
  24.         $request $event->getRequest();
  25.         if(!$this->tokenStorage->getToken()) {
  26.             return;
  27.         }
  28.         $user $this->tokenStorage->getToken()->getUser();
  29.         if (!$user->isEnabled()) {
  30.             $this->tokenStorage->setToken();
  31.             $request->getSession()->invalidate();
  32.             return;
  33.         }
  34.     }
  35. }