src/EventSubscriber/CheckTwoFactListener.php line 31

  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Bundle\FrameworkBundle\Routing\Router;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. use Symfony\Component\HttpKernel\Event\RequestEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. /**
  11.  *
  12.  */
  13. class CheckTwoFactListener implements EventSubscriberInterface
  14. {
  15.     private $request;
  16.     private $router;
  17.     public function __construct(RequestStack $requestRouter $router)
  18.     {
  19.         $this->request $request;
  20.         $this->router $router;
  21.     }
  22.     public function onKernelRequest(RequestEvent $event)
  23.     {
  24.         if($this->request->getSession()->get("2factRequested") == 1){
  25.             $event->setResponse(new RedirectResponse($this->router->generate('twofactor_auth')));
  26.         }
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return array(
  31.             // must be registered before the default Locale listener
  32.             KernelEvents::REQUEST => array(array('onKernelRequest'17)),
  33.         );
  34.     }
  35. }