<?php
/**
* This file is part of the MADIS - RGPD Management application.
*
* @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes
* @author ANODE <contact@agence-anode.fr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Domain\User\Symfony\EventSubscriber\Kernel;
use App\Application\Controller\ControllerHelper;
use App\Domain\User\Exception\ExceededLoginAttemptsException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ExceptionSubscriber implements EventSubscriberInterface
{
private ControllerHelper $helper;
public function __construct(ControllerHelper $helper)
{
$this->helper = $helper;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => 'onException',
];
}
public function onException(ExceptionEvent $event)
{
if ($event->getThrowable() instanceof ExceededLoginAttemptsException) {
$view = $this->helper->render('User/Security/locked.html.twig');
$event->setResponse($view);
}
}
}