src/EventSubscriber/CheckTwoFactListener.php line 29
<?php
namespace App\EventSubscriber;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
*
*/
class CheckTwoFactListener implements EventSubscriberInterface
{
private $request;
private $router;
public function __construct(RequestStack $request, Router $router)
{
$this->request = $request;
$this->router = $router;
}
public function onKernelRequest(RequestEvent $event)
{
if($this->request->getSession()->get("2factRequested") == 1){
$event->setResponse(new RedirectResponse($this->router->generate('twofactor_auth')));
}
}
public static function getSubscribedEvents(): array
{
return array(
// must be registered before the default Locale listener
KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
);
}
}