<?php
namespace App\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class LoginSubscriber implements EventSubscriberInterface
{
private $em;
private $log;
private $storage;
private $router;
private $event;
public function __construct(EntityManagerInterface $em, LoggerInterface $log, TokenStorageInterface $storage, RouterInterface $router, RequestStack $event)
{
$this->em = $em;
$this->log = $log;
$this->storage = $storage;
$this->router = $router;
$this->event = $event;
}
public function onSecurityInteractiveLogin(AuthenticationSuccessEvent $event)
{
// $request = $event->getRequest();
$session = $this->event->getSession();
// $captcha = $session->get('_captcha_captcha');
// $frase = $captcha['phrase'];
//// dump($frase);
//// dump($captcha);
//// dump($session);
// dump($request);
// $req = $event->getRequest()->get('login');
//// dd($req['captcha']);
// $this->storage->setToken('','');
// $event->getRequest()->getSession()->invalidate(1);
// return new RedirectResponse($this->router->generate('app_logout'));
// $this->storage->setToken('','');
// $session->invalidate(1);
//$mes = new CustomUserMessageAuthenticationException('Ingrese el CAPTCHA correcto.');
//$session->set(Security::AUTHENTICATION_ERROR, $mes);
//return new RedirectResponse($this->router->generate('app_logout'));
}
public static function getSubscribedEvents()
{
return [
'security.authentication.success' => 'onSecurityInteractiveLogin',
];
}
}