<?php
namespace Eckinox\SecurityBundle\EventListener;
use App\Entity\Security\AppUser;
use App\Entity\Security\User;
use Eckinox\SecurityBundle\Entity\AbstractAppUser;
use Eckinox\SecurityBundle\Entity\AbstractUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class SecurityListener
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage, RouterInterface $router)
{
$this->tokenStorage = $tokenStorage;
}
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
if(!$this->tokenStorage->getToken()) {
return;
}
$user = $this->tokenStorage->getToken()->getUser();
if (!$user->isEnabled()) {
$this->tokenStorage->setToken();
$request->getSession()->invalidate();
return;
}
}
}