src/EventListener/KycListener.php line 27

Open in your IDE?
  1. <?php
  2. // src/EventListener/RequestListener.php
  3. namespace App\EventListener;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use App\Service\ConfigService;
  10. use App\Entity\KycVerificationStatus;
  11. class KycListener
  12. {
  13.     private $urlGenerator;
  14.     private $authorizationChecker;
  15.     private $security;
  16.     public function __construct(UrlGeneratorInterface $urlGeneratorAuthorizationCheckerInterface $authorizationCheckerSecurity $security, private ConfigService $configService)
  17.     {
  18.         $this->urlGenerator $urlGenerator;
  19.         $this->authorizationChecker $authorizationChecker;
  20.         $this->security $security;
  21.     }
  22.     public function onKernelRequest(RequestEvent $event)
  23.     {
  24.         $request $event->getRequest();
  25.     return;
  26.         // Check if the current path is not in the list of paths to exclude
  27.         
  28.         $excludePaths = ['/prestataire-back-office','/auth/connexion''/auth/inscription''/reset-password''/auth/formulaire_contact''/auth/print_condition_utilisation','/auth/condition-utilisation''/auth/check-existing-user''/otp''/informations'$this->urlGenerator->generate('app_data_protection_infos'), $this->urlGenerator->generate('app_new_kyc_sumsub_webhook')];
  29.         foreach($excludePaths as $path){
  30.             if(strncmp($request->getPathInfo(), $pathstrlen($path)) == 0){
  31.                 return;
  32.             }
  33.         } 
  34.         $user $this->security->getUser();
  35.         if($user && !$user->isDataProtectionChecked() && !$this->authorizationChecker->isGranted('ROLE_ADMIN')  && !$this->authorizationChecker->isGranted('ROLE_PLAYER')){
  36.             $event->setResponse(new RedirectResponse($this->urlGenerator->generate('app_data_protection_infos')));
  37.             return;
  38.         }
  39.         $kycVerificationStatus $this->configService->getKycVerificationStatusVerified();
  40.         if ($user?->getKycVerificationStatus()?->getId() == $kycVerificationStatus->getId()  && !$this->authorizationChecker->isGranted('ROLE_PLAYER') && !$user?->hasSubmittedKycDocument() &&  !$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
  41.             $documentRoutesArray = [
  42.                 '/verification/'
  43.             ];
  44.             $isDocumentRoutes false;            
  45.             foreach($documentRoutesArray as $path){
  46.                 if(strncmp($request->getPathInfo(), $pathstrlen($path)) == 0){
  47.                     $isDocumentRoutes true;;
  48.                 }
  49.             } 
  50.             $urlKycDocument $this->urlGenerator->generate('app_kyc_info');
  51.             if(!$isDocumentRoutes){
  52.                 $event->setResponse(new RedirectResponse($urlKycDocument));
  53.             }
  54.         }
  55.         if ($this->authorizationChecker->isGranted('KYC_INFO_SUBMITTED') || $this->authorizationChecker->isGranted('ROLE_PLAYER')) {
  56.             return;
  57.         }
  58.         
  59.         // Redirect to a specific page
  60.         
  61.         $url $this->urlGenerator->generate('app_kyc');
  62.         if(strncmp($request->getPathInfo(), $urlstrlen($url)) != 0){
  63.             $event->setResponse(new RedirectResponse($url));
  64.         }
  65.         
  66.         
  67.     }
  68.     
  69. }