src/Aviatur/GeneralBundle/EventListener/RequestListener.php line 253

Open in your IDE?
  1. <?php
  2. namespace Aviatur\GeneralBundle\EventListener;
  3. use Aviatur\AgencyBundle\Entity\Agency;
  4. use Aviatur\CustomerBundle\Entity\Customer;
  5. use Aviatur\CustomerBundle\Models\CustomerModel;
  6. use Aviatur\FlightBundle\Entity\ConfigFlightAgency;
  7. use Aviatur\GeneralBundle\Entity\Parameter;
  8. use Aviatur\GeneralBundle\Entity\SeoHeader;
  9. use Aviatur\GeneralBundle\Entity\SeoIndex;
  10. use Aviatur\GeneralBundle\Entity\Whitemark;
  11. use Aviatur\GeneralBundle\Services\AviaturAthServices;
  12. use Aviatur\GeneralBundle\Services\AviaturChangeCoin;
  13. use Aviatur\GeneralBundle\Services\AviaturErrorHandler;
  14. use Aviatur\GeneralBundle\Services\AviaturLogSave;
  15. use Aviatur\GeneralBundle\Services\AviaturWebService;
  16. use Aviatur\GeneralBundle\Services\ExceptionLog;
  17. use Aviatur\HotelBundle\Entity\ConfigHotelAgency;
  18. use Doctrine\Persistence\ManagerRegistry;
  19. use Firebase\JWT\JWT;
  20. use Symfony\Component\HttpFoundation\RedirectResponse;
  21. use Symfony\Component\HttpFoundation\RequestStack;
  22. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  23. use Symfony\Component\HttpKernel\Event\RequestEvent;
  24. use Symfony\Component\Routing\RouterInterface;
  25. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  26. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  27. class RequestListener
  28. {
  29.     private \Symfony\Component\HttpFoundation\RequestStack $requestStack;
  30.     private \Symfony\Component\HttpFoundation\Session\SessionInterface $session;
  31.     private \Aviatur\GeneralBundle\Services\AviaturLogSave $aviaturLogSave;
  32.     private \Swift_Mailer $mailer;
  33.     private \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $authorizationChecker;
  34.     private \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage;
  35.     private \Aviatur\GeneralBundle\Services\ExceptionLog $exceptionLog;
  36.     private \Aviatur\GeneralBundle\Services\AviaturChangeCoin $changeCoin;
  37.     private \Aviatur\GeneralBundle\Services\AviaturWebService $aviaturWebService;
  38.     private $projectDir;
  39.     private $env;
  40.     private $em;
  41.     private $aviaturAthServices;
  42.     private $aviaturErrorHandler;
  43.     private $router;
  44.     protected $twig;
  45.     private $aviaturSufixAssetsFolder;
  46.     private $aviaturDefaultAssetsFolder;
  47.     private $emailNotification;
  48.     private string $sessionSufixParameters '[parameters]';
  49.     private string $wwwPrefix 'www.';
  50.     public function __construct(
  51.         RequestStack $requestStackSessionInterface $sessionAviaturLogSave $aviaturLogSave, \Swift_Mailer $mailerAuthorizationCheckerInterface $authorizationCheckerTokenStorageInterface $tokenStorage,
  52.         ExceptionLog $exceptionLogAviaturChangeCoin $changeCoinAviaturWebService $aviaturWebServiceManagerRegistry $registryAviaturAthServices $aviaturAthServicesAviaturErrorHandler $aviaturErrorHandler,
  53.         RouterInterface $router$twig$aviaturSufixAssetsFolder$aviaturDefaultAssetsFolder$emailNotification$projectDir$env
  54.     ) {
  55.         $this->requestStack $requestStack;
  56.         $this->session $session;
  57.         $this->aviaturLogSave $aviaturLogSave;
  58.         $this->mailer $mailer;
  59.         $this->authorizationChecker $authorizationChecker;
  60.         $this->tokenStorage $tokenStorage;
  61.         $this->exceptionLog $exceptionLog;
  62.         $this->changeCoin $changeCoin;
  63.         $this->aviaturWebService $aviaturWebService;
  64.         $this->projectDir $projectDir;
  65.         $this->env $env;
  66.         $this->em $registry->getManager();
  67.         $this->aviaturAthServices $aviaturAthServices;
  68.         $this->aviaturErrorHandler $aviaturErrorHandler;
  69.         $this->router $router;
  70.         $this->twig $twig;
  71.         $this->aviaturSufixAssetsFolder $aviaturSufixAssetsFolder;
  72.         $this->aviaturDefaultAssetsFolder $aviaturDefaultAssetsFolder;
  73.         $this->emailNotification $emailNotification;
  74.         $this->loginKey $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneByName('aval_public_key_auth')->getDescription();
  75.     }
  76.     public function onKernelRequest(RequestEvent $event)
  77.     {
  78.         apc_clear_cache();
  79.         apc_clear_cache('user');
  80.         $request $event->getRequest();
  81.         $domain $request->getHost();
  82.         if (('www.aviatur.com' != $domain) && ('ecommprod.grupoaviatur.com' != $domain) && ('agenciadeviajes.compensar.com' != $domain) && ('compensar.grupoaviatur.com' != $domain) && ('mobile.aviatur.com' != $domain) && ('mobile.grupoaviatur.com' != $domain)) {
  83.             $this->aviaturLogSave->logSave($domain.' '.$request->server->get('REQUEST_URI').' '.$request->attributes->get('_route').' '.microtime(), 'DomainTime''RQ'microtime());
  84.         }
  85.         if (('www.aviaturcolombia.com' == $domain) && !$request->getQueryString() && ('/' == $request->getPathInfo())) {
  86.             $response = new RedirectResponse('http://www.aviaturcolombia.com/en/');
  87.             return $event->setResponse($response);
  88.         }
  89.         $post $request->request;
  90.         $securityContext $this->authorizationChecker;
  91.         $server $this->requestStack->getCurrentRequest()->server;
  92.         $referer str_replace('www.'''parse_url($server->get('HTTP_REFERER'), PHP_URL_HOST));
  93.         $whitemarkAgency null;
  94.         $requestQuery $request->query;
  95.         $protocol 'domain';
  96.         if ($request->isSecure()) {
  97.             $protocol 'domainsecure';
  98.         }
  99.         $this->session->set('emailNoReply''noreply@aviatur.com.co');
  100.         $agency $this->em->getRepository(Agency::class)->findOneBy(
  101.             [$protocol => [$domainstr_replace($this->wwwPrefix''$domain)]]
  102.         );
  103.         // ?? $this->em->getRepository(Agency::class)->findOneBy(
  104.         //    ['domain' => [$domain, str_replace($this->wwwPrefix, '', $domain)]]
  105.         //)
  106.         if ($agency) {
  107.             $isAgency true;
  108.             $onlySearcherSite $this->em->getRepository(Whitemark::class)->findOneBy(['agency' => $agency'url' => $referer]);
  109.             if (null != $onlySearcherSite) {
  110.                 if (== $onlySearcherSite->getEmbebed()) {
  111.                     $this->session->set('onlySearcherSite'true);
  112.                 }
  113.             }
  114.             if ('' != $post->get('detailWhitemarkReferer')) {
  115.                 $requestQuery->set('whitemark'$post->get('detailWhitemarkReferer'));
  116.             }
  117. //            if ($post->get('hotelWhitemarkReferer') != "") {
  118. //                $requestQuery->set('whitemark', $post->get('hotelWhitemarkReferer'));
  119. //            }
  120. //            if ($post->get('packageWhitemarkReferer') != "") {
  121. //
  122. //                $requestQuery->set('whitemark', $post->get('packageWhitemarkReferer'));
  123. //            }
  124.             if ('' != $post->get('loginWhitemark')) {
  125.                 $requestQuery->set('whitemark'$post->get('loginWhitemark'));
  126.                 $this->session->set('whitemarkLogin'$post->get('loginWhitemark'));
  127.             } else {
  128.                 if ($this->session->has('whitemarkLogin')) {
  129.                     $whitemarkAgency $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['referer' => $this->session->get('whitemarkLogin')]);
  130.                     $requestQuery->set('whitemark'$this->session->get('whitemarkLogin'));
  131.                 }
  132.             }
  133.             // if (!$this->session->has('agencyDataInfo')) {
  134.                 $agencyDataInfo = [
  135.                     'agency_id' => $agency->getId(),
  136.                     'agency_name' => $agency->getName(),
  137.                     'agency_nit' => $agency->getNit(),
  138.                     'agency_phone' => $agency->getPhone(),
  139.                     'agency_email' => $agency->getMailContact(),
  140.                     'address' => $agency->getAddress(),
  141.                     'agency_phones' => json_decode($agency->getPhonesContact(), true),
  142.                     'socialmedia' => json_decode($agency->getSocialmedia(), true)
  143.                 ];
  144.                 // if (count($agencyDataInfo) > 0) {
  145.                     $this->session->set('agencyDataInfo'$agencyDataInfo);
  146.                 // }
  147.             // }
  148.         } else {
  149.             $whitemarkAgency $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['url' => str_replace($this->wwwPrefix''$domain)]);
  150.             if (null != $whitemarkAgency) {
  151.                 $agency $whitemarkAgency->getAgency();
  152.                 $isAgency true;
  153.                 $requestQuery->set('whitemark'$whitemarkAgency->getReferer());
  154.                 if (!$this->session->has('whitemarkDataInfo')) {
  155.                     $whitemarkAgencyDataInfo = [
  156.                         'whitemark_id' => $whitemarkAgency->getId(),
  157.                         'whitemark_name' => $whitemarkAgency->getName(),
  158.                         'whitemark_phone' => $whitemarkAgency->getPhone(),
  159.                         'whitemark_email' => $whitemarkAgency->getEmail(),
  160.                         'whitemark_address' => $whitemarkAgency->getAddress(),
  161.                         'whitemark_phones' => json_decode($whitemarkAgency->getPhonesContact(), true),
  162.                     ];
  163.                     if (count($whitemarkAgencyDataInfo) > 0) {
  164.                         $this->session->set('whitemarkDataInfo'$whitemarkAgencyDataInfo);
  165.                     }
  166.                 }
  167.             } else {
  168.                 $isAgency false;
  169.             }
  170.         }
  171.         if ($isAgency) {
  172.             $post $request->request;
  173.             if ($requestQuery->has('whitemark') || '' != $this->session->get('whitemark')) {
  174.                 $refererInfo $requestQuery->get('whitemark');
  175.                 if (null == $whitemarkAgency) {
  176.                     if (false !== strpos($agency->getDomainsecure(), 'whitemark') && '' == $refererInfo) {
  177.                         $whitemark $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['referer' => $this->session->get('whitemark')]);
  178.                         if (!$requestQuery->has('whitemark')) {
  179.                             $requestQuery->set('whitemark'$this->session->get('whitemark'));
  180.                             if (== $whitemark->getEmbebed()) {
  181.                                 $this->session->set('homeWhitemark''https://'.$whitemark->getUrl());
  182.                             }
  183.                         }
  184.                     } else {
  185.                         if (false !== strpos($referer'whitemark')) {
  186.                             $whitemark $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['referer' => $refererInfo]);
  187.                         } else {
  188.                             $whitemark $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['url' => $referer'referer' => $refererInfo]);
  189.                         }
  190.                         if ('' != $this->session->get('whitemark')) {
  191.                             $whitemark $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Whitemark::class)->findOneBy(['referer' => $this->session->get('whitemark')]);
  192.                             $requestQuery->set('whitemark'$this->session->get('whitemark'));
  193.                         }
  194.                     }
  195.                 } else {
  196.                     $whitemark $whitemarkAgency;
  197.                 }
  198.                 if (null == $whitemark) {
  199.                     $response = new RedirectResponse('https://www.aviatur.com');
  200.                     return $event->setResponse($response);
  201.                 } else {
  202.                     $this->session->set('whitemark'$requestQuery->get('whitemark'));
  203.                     $this->session->set('whitemarkSite'$whitemark->getEmbebed());
  204.                     $this->session->set('whitemarkName'$whitemark->getName());
  205.                     $this->session->set('whitemarkMail'$whitemark->getEmail());
  206.                     if (== $whitemark->getEmbebed()) {
  207.                         $wmData = [];
  208.                         $wmData['direccion'] = $whitemark->getAddress();
  209.                         $wmData['telefono'] = $whitemark->getPhone();
  210.                         $wmData['correo'] = $whitemark->getEmail();
  211.                         $this->session->set('whitemarkData'$wmData);
  212.                         $this->session->set('homeWhitemark''https://'.$whitemark->getUrl());
  213.                         $query $this->em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.agency = :agency and a.url LIKE :menu ORDER BY a.creationdate DESC');
  214.                         $query $query->setParameter('agency'$agency);
  215.                         $query $query->setParameter('menu''%'.$refererInfo.'%');
  216.                         $content $query->getResult();
  217.                         $menu = [];
  218.                         foreach ($content as $item) {
  219.                             $menu[$item->getTitle()] = $item->getUrl();
  220.                         }
  221.                         $this->session->set('whitemarkMenu'$menu);
  222.                     }
  223.                 }
  224.             }
  225.             if ($requestQuery->has('special_campaing')) {
  226.                 $this->session->set('special_campaing'$requestQuery->get('special_campaing'));
  227.             }
  228.             if ($post->has('flightSpecialReferer')) {
  229.                 $this->session->set('special_campaing'$post->get('flightSpecialReferer'));
  230.             }
  231.             // if ((strpos($agency->getDomainsecure(), 'whitemark') !== false) && (!$this->session->has('whitemark'))) {
  232.             // $response = new RedirectResponse("http://www.aviatur.com");
  233.             // return $event->setResponse($response);
  234.             // }
  235.             if ('claro' == $agency->getAssetsFolder()) {
  236.                 $specialMenuData file_get_contents($this->projectDir.'/web/contenido/json_claro.txt');
  237.                 $specialMenuData json_decode($specialMenuDatatrue);
  238.                 $this->session->set('agency_special_header'$specialMenuData);
  239.             }
  240.             $_route $request->attributes->get('_route');
  241.             $this->session->set('agencyId'$agency->getId());
  242.             $this->session->set('agencyShortName'ucwords(str_replace('_'' '$agency->getAssetsfolder())));
  243.             $this->session->set('domain'$agency->getDomain());
  244.             $this->session->set('domainsecure'$agency->getDomainsecure());
  245.             $this->session->set('domainport'$agency->getCustomport());
  246.             $this->session->remove('notEnableFlightSearch');
  247.             $this->session->remove('notEnableHotelSearch');
  248.             $this->session->remove('notEnableMultiHVSearch');
  249.             $configFlightAgency $this->em->getRepository(ConfigFlightAgency::class)->findByAgency($agency);
  250.             if ((is_countable($configFlightAgency) ? count($configFlightAgency) : 0) < 1) {
  251.                 $this->session->set('notEnableFlightSearch'true);
  252.             }
  253.             $configHotelAgency $this->em->getRepository(ConfigHotelAgency::class)->findByAgency($agency);
  254.             if ((is_countable($configHotelAgency) ? count($configHotelAgency) : 0) < 1) {
  255.                 $this->session->set('notEnableHotelSearch'true);
  256.             }
  257.             if ((is_countable($configFlightAgency) ? count($configFlightAgency) : 0) < || (is_countable($configHotelAgency) ? count($configHotelAgency) : 0) < 1) {
  258.                 $this->session->set('notEnableMultiHVSearch'true);
  259.             }
  260.             if (null != $this->tokenStorage->getToken() && !$this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  261.                 // authenticated REMEMBERED, FULLY will imply REMEMBERED (NON anonymous)
  262.                 /* if ($agency->getDomain() == "aviatur.com"){
  263.                   var_dump($request);
  264.                   var_dump($request->isSecure());
  265.                   var_dump($request->isSecure() != TRUE);
  266.                   VAR_DUMP(($agency->getCustomport() == 443) && ($agency->getDomain() === $agency->getDomainsecure()) && (strpos($agency->getDomainsecure(), 'whitemark') === false) && (strpos($agency->getDomainsecure(), 'wm.') === false) && (strpos($agency->getDomainsecure(), 'mb.') === false) && ($request->isSecure() != TRUE));
  267.                   exit();
  268.                   } */
  269.                 if ((443 == $agency->getCustomport()) && ($agency->getDomain() === $agency->getDomainsecure()) && (false === strpos($agency->getDomainsecure(), 'whitemark')) && (false === strpos($agency->getDomainsecure(), 'wm.')) && (false === strpos($agency->getDomainsecure(), 'mb.')) && (!$request->isSecure())) {
  270.                     $response = new RedirectResponse('https://'.$agency->getDomainsecure().$request->server->get('REQUEST_URI'));
  271.                     return $event->setResponse($response);
  272.                 } elseif ((false === strpos($_route'_nocheck')) && (false === strpos($_route'fos_user_')) && ($agency->getDomainsecure() != $agency->getDomain())) {
  273.                     if (((false !== strpos($_route'_secure')) || (false !== strpos($_route'sonata_')) || (false !== strpos($_route'admin_aviatur_'))) && (true != $request->isSecure())) {
  274.                         $response = new RedirectResponse('https://'.$agency->getDomainsecure().$request->server->get('REQUEST_URI'));
  275.                         return $event->setResponse($response);
  276.                     } elseif ((false === strpos($_route'_secure')) && (false === strpos($_route'sonata_')) && (false === strpos($_route'admin_aviatur_')) && (true == $request->isSecure())) {
  277.                         $response = new RedirectResponse('http://'.$agency->getDomain().$request->server->get('REQUEST_URI'));
  278.                         return $event->setResponse($response);
  279.                     }
  280.                 }
  281.             }
  282.             $search = ['?_ga=''&_ga='];
  283.             $tempUrl explode('|||||'str_replace($search'|||||'$_SERVER['REQUEST_URI']));
  284.             $finalUrl trim($tempUrl[0], '/');
  285.             $seoIndex $this->em->getRepository(SeoIndex::class)->findBy(['agency' => $agency]);
  286.             $seoUrlIndex = [];
  287.             if (null != $seoIndex) {
  288.                 foreach ($seoIndex as $item) {
  289.                     if ($item->getUrl() == $finalUrl) {
  290.                         $seoUrlIndex['url'] = $item->getUrl();
  291.                         $seoUrlIndex['name'] = $item->getName();
  292.                         $seoUrlIndex['content'] = $item->getContent();
  293.                     }
  294.                 }
  295.                 $this->twig->addGlobal('seoUrlIndex'$seoUrlIndex);
  296.             }
  297.             $seoHeader $this->em->getRepository(SeoHeader::class)->findByWithNull($finalUrl$agency);
  298.             if (null != $seoHeader) {
  299.                 $this->twig->addGlobal('seo_title'$seoHeader->getTitle());
  300.                 $this->twig->addGlobal('seo_description'$seoHeader->getDescription());
  301.                 $this->twig->addGlobal('seo_meta_title'$seoHeader->getMetatitle());
  302.                 $this->twig->addGlobal('seo_keywords'$seoHeader->getKeywords());
  303.             }
  304.             $now = new \Datetime();
  305.             $agencyJson json_encode([
  306.                 'id' => $agency->getId(),
  307.                 'name' => $agency->getName(),
  308.                 'date' => $now->format('l, Y-F-d H:i:s'),
  309.             ]);
  310.             // verificar assets folder
  311.             $sessionSufixAssetsFolder $this->aviaturSufixAssetsFolder;
  312.             $defaultAssetsFolder $this->aviaturDefaultAssetsFolder;
  313.             if ('' == $agency->getAssetsFolder() || null == $agency->getAssetsFolder()) {
  314.                 // set default assets folder
  315.                 $this->session->set($domain.$sessionSufixAssetsFolder$defaultAssetsFolder);
  316.             } elseif (!$this->session->has($domain.$sessionSufixAssetsFolder)) {
  317.                 $this->session->set($domain.$sessionSufixAssetsFolder$agency->getAssetsFolder());
  318.             }
  319.             // verificar parametros por defecto y especificos para la agencia.
  320. //            if (!$this->session->has($domain . $this->sessionSufixParameters)) {
  321.             $parameters $this->em->getRepository(Parameter::class)->findParameters($agency);
  322.             if ($parameters) {
  323.                 $array = [];
  324.                 foreach ($parameters as $item) {
  325.                     $array += [
  326.                         $item['name'] => $item['value'],
  327.                     ];
  328.                 }
  329.                 $this->session->set($domain.$this->sessionSufixParametersjson_encode($array));
  330.             } else {
  331.                 $this->exceptionLog->log(
  332.                     'Error Fatal',
  333.                     'No hay parametros por defecto ni especificos para asignar a la agencia: '.$agencyJson,
  334.                     null,
  335.                     false
  336.                 );
  337.             }
  338.             if ($this->changeCoin->validateChangeCoin($_route)) {
  339.                 if ($request->query->has('currency') || $request->request->has('typeCoin')) {
  340.                     $this->changeCoin->removeSessionValues();
  341.                     $typeCoin $request->query->has('currency') ? $request->query->get('currency') : $request->request->get('typeCoin');
  342.                     $sessionVariables = [
  343.                         'typeCoin' => $typeCoin,
  344.                         'typeCoinMemory' => $typeCoin,
  345.                         'typeCountry' => strtolower(mb_substr($typeCoin02)),
  346.                     ];
  347.                     $this->changeCoin->setSessionValues($sessionVariables);
  348.                 } else {
  349.                     if (!$this->session->has('typeCoin')) {
  350.                         if ($this->session->has('typeCoinMemory')) {
  351.                             $typeCoin $this->session->get('typeCoinMemory');
  352.                             $sessionVariables = [
  353.                                 'typeCoin' => $typeCoin,
  354.                                 'typeCountry' => strtolower(mb_substr($typeCoin02)),
  355.                             ];
  356.                         } else {
  357.                             $sessionVariables = [
  358.                                 'typeCoin' => 'COP',
  359.                                 'typeCountry' => 'co',
  360.                             ];
  361.                         }
  362.                         $this->changeCoin->setSessionValues($sessionVariables);
  363.                     }
  364.                 }
  365.                 $this->changeCoin->InfoCoin('COP');
  366.             }
  367.             if ($post->has('operatorId')) {
  368.                 $this->session->set('operatorId'$post->get('operatorId'));
  369.                 $this->session->set('operatorName'$post->get('operatorName'));
  370.                 $this->session->set('airlineFront'$post->get('airline'));
  371.                 if ($post->has('adapterId')) {
  372.                     $this->session->set('flightAdapterId'$post->get('adapterId'));
  373.                 } elseif ($post->get('flightProviderIds')) {
  374.                     $this->session->set('flightAdapterId'$post->get('flightProviderIds'));
  375.                     $this->session->set('officeId'$post->get('officeId'));
  376.                     $this->session->set('externalId'$post->get('externalId'));
  377.                 }
  378.                 if ($post->has('cencosud')) {
  379.                     $this->session->set('frontCencosud''1');
  380.                 } elseif ($this->session->has('frontCencosud')) {
  381.                     $this->session->remove('frontCencosud');
  382.                 }
  383.                 $this->session->set('hotelAdapterId'$post->get('hotelProviderIds'));
  384.                 $customerModel = new CustomerModel();
  385.                 $this->aviaturWebService->setUrls(json_decode($this->session->get($domain.$this->sessionSufixParameters)));
  386.                 $responseAgent $this->aviaturWebService->callWebService('GENERALLAVE''dummy|http://www.aviatur.com.co/dummy/'$customerModel->getXmlAgent($post->get('operatorId')));
  387.                 $this->session->set('front_user'$responseAgent->asXml());
  388.                 $responseAgentAdditionals $this->aviaturWebService->callWebService('GENERALLAVE''dummy|http://www.aviatur.com.co/dummy/'$customerModel->getXmlAgentAdditionals($post->get('operatorId')));
  389.                 $this->session->set('front_user_additionals'$responseAgentAdditionals->asXml());
  390.             }
  391.             // Validar agencia aval y token para inicio de sesion
  392.             if (strpos($agency->getName(), 'Aval')) {
  393.                 if (isset($_GET['authorization']) || $this->session->has('token')) {
  394.                     $response $this->aviaturAthServices->validateToken(["token" => $_GET['authorization'] ?? $this->session->get('token')], FALSE);
  395.                     if (!isset($response['error'])) {
  396.                         if ($response['ok']['code'] != 0) {
  397.                             $this->session->remove('token');
  398.                             $this->session->remove('userAth');
  399.                             $redirectError $this->aviaturErrorHandler->errorRedirectNoEmail($this->router->generate('homepage'), 'Sesión Inactiva''La sesión ha caducado');
  400.                             return new RedirectResponse($redirectError);
  401.                         } else {
  402.                             if (!$this->session->has('token')) {
  403.                                 $this->session->set('token'$_GET['authorization'] ?? $this->session->get('token'));
  404.                                 $decodedToken json_encode(JWT::decode($_GET['authorization'], $this->loginKey, ['RS256'], TRUE));
  405.                                 $this->session->set('userAth'$decodedToken);
  406.                             } else {
  407.                                 if (isset($_GET['authorization']) && $this->session->has('token') && $this->session->get('token') != $_GET['authorization']) {
  408.                                     $this->session->set('token'$_GET['authorization']);
  409.                                     $decodedToken json_encode(JWT::decode($_GET['authorization'], $this->loginKey, ['RS256'], TRUE));
  410.                                     $this->session->set('userAth'$decodedToken);
  411.                                 }
  412.                             }
  413.                         }
  414.                     } else {
  415.                         $this->session->remove('token');
  416.                         $this->session->remove('userAth');
  417.                         $redirectError $this->aviaturErrorHandler->errorRedirectNoEmail($this->router->generate('homepage'), 'Sesión Inactiva''La sesión ha caducado');
  418.                         return new RedirectResponse($redirectError);
  419.                     }
  420.                 }
  421.             } else {
  422.                 if ($post->has('token')) {
  423.                     $this->session->set('token'$post->get('token'));
  424.                 }
  425.             }
  426.             if ((false !== strpos($agency->getDomainsecure(), 'b2t')) && (!$this->session->has('operatorId'))) {
  427.                 if (false === strpos($server->get('REQUEST_URI'), 'trenes/confirmar-reserva')) {
  428.                     $response = new RedirectResponse('http://miavianet.aviatur.com.co');
  429.                     return $event->setResponse($response);
  430.                 }
  431.             }
  432. //            }
  433.         } else {
  434.             $response = new RedirectResponse('https://www.aviatur.com');
  435.             return $event->setResponse($response);
  436.         }
  437.         if (null != $this->tokenStorage->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  438.             $customer $this->tokenStorage->getToken()->getUser();
  439.             if ($customer instanceof Customer) {
  440.                 $city $customer->getCity();
  441.                 $this->em->persist($customer);
  442.                 $this->em->flush();
  443.                 if (null == $city) {
  444.                     $dataCity $this->em->getRepository(\Aviatur\GeneralBundle\Entity\City::class)->findOneBy(['id' => '2164']);
  445.                     $dataCountry $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Country::class)->findOneBy(['id' => '165']);
  446.                     $customer->setCity($dataCity);
  447.                     $customer->setCountry($dataCountry);
  448.                     $customer->setAviaturclientid(0);
  449.                     $customer->setAcceptInformation(0);
  450.                     $customer->setAcceptSms(0);
  451.                     $customer->setPersonType(8);
  452.                     $customer->setFrecuencySms(0);
  453.                     if (!$customer->getBirthdate()) {
  454.                         $date = new \DateTime();
  455.                         $date->sub(new \DateInterval('P19Y'));
  456.                         $customer->setBirthdate($date);
  457.                         $this->fieldCompletionAlert($customer'Birthdate'$date);
  458.                     }
  459.                     $this->em->persist($customer);
  460.                     $this->em->flush();
  461.                 }
  462.                 if (!$customer->getCity()) {
  463.                     $customer->completeCity($this->em);
  464.                     $this->em->flush();
  465.                     $this->cityNullAlert($customer$request);
  466.                 }
  467.             }
  468.         }
  469.         if (!$this->session->has('headerPromoStart')) {
  470.             $homePromoTime $this->em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoTime::class)->findOneByHomePromoList(2);
  471.             $this->session->set('headerPromoStart'$homePromoTime->getStartDate());
  472.             $this->session->set('headerPromoEnd'$homePromoTime->getEndDate());
  473.         }
  474.     }
  475.     private function fieldCompletionAlert($customer$field$newval)
  476.     {
  477.         $env $this->env;
  478.         $message = (new \Swift_Message())
  479.                 ->setContentType('text/html')
  480.                 ->setFrom('errors.'.$env.'@aviatur.com')
  481.                 ->setTo([$this->emailNotification'jorge.ubaque@aviatur.com'])
  482.                 ->setSubject('Customer Registration Issue: '.$field)
  483.                 ->setBody('The system has automatically set a new value to field ('.$field.') for user:<br><br>
  484.                                 username: '.$customer->getUsername().'<br>
  485.                                 customer_id: '.$customer->getId().'<br><br>
  486.                                 The field was set to: '.print_r($newvaltrue).'
  487.                                 ');
  488.         $this->mailer->send($message);
  489.         return true;
  490.     }
  491.     private function cityNullAlert($customer$request)
  492.     {
  493.         $env $this->env;
  494.         $message = (new \Swift_Message())
  495.                 ->setContentType('text/html')
  496.                 ->setFrom('errors.'.$env.'@aviatur.com')
  497.                 ->setTo([$this->emailNotification'jorge.ubaque@aviatur.com'])
  498.                 ->setSubject('Customer Registration Issue: City NULL')
  499.                 ->setBody('The system has detected that City is still null after all filters. The entity has set the default values, please check.<br><br>Customer Info:<br><br>
  500.                                 Username: '.$customer->getUsername().'<br>
  501.                                 Customer_id: '.$customer->getId().'<br><br>
  502.                                 Server info: <pre>'.print_r($request->servertrue).'</pre><br><br>
  503.                                 ');
  504.         $this->mailer->send($message);
  505.         return true;
  506.     }
  507. }