<?php
namespace App\EventListener;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
class ResidentChangePwd
{
protected $container;
protected $router;
/**
* ResidentChangePwd constructor.
*/
public function __construct(ContainerInterface $container, RouterInterface $router, Security $security)
{
$this->container = $container;
$this->security = $security;
$this->router = $router;
}
public function onKernelRequest(RequestEvent $event)
{
if (HttpKernel::MAIN_REQUEST != $event->getRequestType()) {
return;
}
if (!$this->security->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return;
}
$user = $this->security->getUser();
if (null === $user->getClientRef()) {
return;
}
// Default resident Password must be changed
$request = $event->getRequest();
$route = $request->get('_route');
if ('app_default_forcepwdchange' === $route) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_first_connection')) {
return;
}
if (str_starts_with((string) $route, 'api_post_quittances_preference')) {
return;
}
if (str_starts_with((string) $route, 'api_new_document')) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_new_document')) {
return;
}
if (str_starts_with((string) $route, 'api_get_document_by_type')) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_get_documents_tenant')) {
return;
}
if (str_starts_with((string) $route, 'app_app_getuploadedmedia')) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_download_media')) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_get_current_user_infos')) {
return;
}
if (str_starts_with((string) $route, 'api_restricted_post_quittances_preference')) {
return;
}
if (str_starts_with((string) $route, 'api_')) {
$response = new JsonResponse('Le mot de passe résident doit être changé !', JsonResponse::HTTP_ACCEPTED);
} else {
$response = new RedirectResponse($this->router->generate('app_default_forcepwdchange'));
}
$event->setResponse($response);
}
}