src/EventListener/ResidentChangePwd.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\HttpKernel;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\Security\Core\Security;
  10. class ResidentChangePwd
  11. {
  12.     protected $container;
  13.     protected $router;
  14.     /**
  15.      * ResidentChangePwd constructor.
  16.      */
  17.     public function __construct(ContainerInterface $containerRouterInterface $routerSecurity $security)
  18.     {
  19.         $this->container $container;
  20.         $this->security $security;
  21.         $this->router $router;
  22.     }
  23.     public function onKernelRequest(RequestEvent $event)
  24.     {
  25.         if (HttpKernel::MAIN_REQUEST != $event->getRequestType()) {
  26.             return;
  27.         }
  28.         if (!$this->security->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  29.             return;
  30.         }
  31.         $user $this->security->getUser();
  32.         if (null === $user->getClientRef()) {
  33.             return;
  34.         }
  35.         // Default resident Password must be changed
  36.         $request $event->getRequest();
  37.         $route $request->get('_route');
  38.         if ('app_default_forcepwdchange' === $route) {
  39.             return;
  40.         }
  41.         if (str_starts_with((string) $route'api_restricted_first_connection')) {
  42.             return;
  43.         }
  44.         if (str_starts_with((string) $route'api_post_quittances_preference')) {
  45.             return;
  46.         }
  47.         if (str_starts_with((string) $route'api_new_document')) {
  48.             return;
  49.         }
  50.         if (str_starts_with((string) $route'api_restricted_new_document')) {
  51.             return;
  52.         }
  53.         if (str_starts_with((string) $route'api_get_document_by_type')) {
  54.             return;
  55.         }
  56.         if (str_starts_with((string) $route'api_restricted_get_documents_tenant')) {
  57.             return;
  58.         }
  59.         if (str_starts_with((string) $route'app_app_getuploadedmedia')) {
  60.             return;
  61.         }
  62.         if (str_starts_with((string) $route'api_restricted_download_media')) {
  63.             return;
  64.         }
  65.         if (str_starts_with((string) $route'api_restricted_get_current_user_infos')) {
  66.             return;
  67.         }
  68.         if (str_starts_with((string) $route'api_restricted_post_quittances_preference')) {
  69.             return;
  70.         }
  71.         if (str_starts_with((string) $route'api_')) {
  72.             $response = new JsonResponse('Le mot de passe résident doit être changé !'JsonResponse::HTTP_ACCEPTED);
  73.         } else {
  74.             $response = new RedirectResponse($this->router->generate('app_default_forcepwdchange'));
  75.         }
  76.         $event->setResponse($response);
  77.     }
  78. }