<?php
// src/EventListener/RequestListener.php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Security;
use App\Service\ConfigService;
use App\Entity\KycVerificationStatus;
class AprilFoolsListener
{
private $urlGenerator;
private $authorizationChecker;
private $security;
public function __construct(UrlGeneratorInterface $urlGenerator, AuthorizationCheckerInterface $authorizationChecker, Security $security, private ConfigService $configService)
{
$this->urlGenerator = $urlGenerator;
$this->authorizationChecker = $authorizationChecker;
$this->security = $security;
}
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$url = $this->urlGenerator->generate('app_important_infos');
// Check if the user is authenticated and has the 'ROLE_CLIENT'
$isInfosPage = strncmp($request->getPathInfo(), $url, strlen($url)) == 0;
if ($this->authorizationChecker->isGranted('APRIL_FOOLS')) {
if(!$isInfosPage) {
$response = new RedirectResponse($url);
$event->setResponse($response);
}
} else if($isInfosPage){
$response = new RedirectResponse($this->urlGenerator->generate('app_client_dahsboard'));
$event->setResponse($response);
}
}
}