<?php
namespace AWCmsBundle\Handler;
use Anyx\LoginGateBundle\Event\BruteForceAttemptEvent;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\AuthenticationEvents;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\AccountStatusException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Contracts\Translation\TranslatorInterface;
use Anyx\LoginGateBundle\Security\Events as LoginGateBundleEvents;
/**
* Class LoginFailureHandler
* @package AWCmsBundle\Handler
*
*/
class LoginFailureHandler implements EventSubscriberInterface
{
protected $session;
protected $translator;
/**
* LoginFailureHandler constructor.
* @param SessionInterface $session
* @param TranslatorInterface $translator
*/
public function __construct(SessionInterface $session, TranslatorInterface $translator)
{
$this->session = $session;
$this->translator = $translator;
}
public static function getSubscribedEvents()
{
return [
LoginGateBundleEvents::BRUTE_FORCE_ATTEMPT => ['onBruteForceAttempt']
];
}
public function onBruteForceAttempt(BruteForceAttemptEvent $event){
$this->session->getFlashBag()->add('notice_error', $this->translator->trans('user.form.too_many_attempts'));
}
}