src/ApplicationBundle/Listener/SessionListener.php line 887

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Listener;
  3. use ApplicationBundle\Interfaces\LoginInterface;
  4. use ApplicationBundle\Interfaces\SessionCheckInterface;
  5. use ApplicationBundle\Interfaces\SystemInterface;
  6. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  7. use ApplicationBundle\Modules\System\MiscActions;
  8. use ApplicationBundle\Modules\System\System;
  9. use Symfony\Component\HttpFoundation\Cookie;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  12. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  13. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. class SessionListener
  16. {
  17.     public $secretKey "";
  18.     private $em;
  19.     private $em_goc;
  20.     private $dm;
  21.     private $router;
  22.     private $session;
  23.     private $resolver;
  24.     private $applicationConnector;
  25.     private $kernelRootDir;
  26.     private $container;
  27.     protected $urlEncryptor;
  28.     public function __construct($kernelRootDir$container$resolver$applicationConnector$router$session$db_credentials$db_credentials_company_group$secret, \Nzo\UrlEncryptorBundle\UrlEncryptor\UrlEncryptor $urlEncryptor)
  29.     {
  30.         $this->secretKey $secret;
  31.         $this->em $db_credentials;
  32.         $this->em_goc $db_credentials_company_group;
  33. //        $this->dm=$odm_credentials;
  34.         $this->router $router;
  35.         $this->resolver $resolver;
  36.         $this->container $container;
  37.         $this->applicationConnector $applicationConnector;
  38.         $this->kernelRootDir $kernelRootDir;
  39.         $this->session $session;
  40.         $this->urlEncryptor $urlEncryptor;
  41.     }
  42.     public function onKernelController(FilterControllerEvent $event)
  43.     {
  44.         $controller $event->getController();
  45.         /*
  46.          * $controller passed can be either a class or a Closure.
  47.          * This is not usual in Symfony but it may happen.
  48.          * If it is a class, it comes in array format
  49.          */
  50.         if (!is_array($controller)) {
  51.             return;
  52.         }
  53.         $hbeeErrorCode UserConstants::ERROR_USER_EXISTS_ALREADY;
  54.         $request $event->getRequest();
  55.         $devAdminMode '_UNCHANGED_';
  56.         if ($request->request->has('devAdminOn') || $request->query->has('devAdminOn')) {
  57.             $devAdminMode $request->request->has('devAdminOn') ? $request->request->get('devAdminOn') : $request->query->get('devAdminOn');
  58.         }
  59. //        if ($request->request->has('devAdminOff')|| $request->query->has('devAdminOff')) {
  60. //            $devAdminMode=0;
  61. //
  62. //        }
  63.         $permissionOverride 0;
  64.         if ($request->query->has('OVP'))
  65.             $permissionOverride 1;
  66.         $authTokenInHeader $event->getRequest()->headers->get('auth-token');
  67.         if ($authTokenInHeader) {
  68.             $request->request->set('hbeeSessionToken'$authTokenInHeader);
  69.         }
  70.         if ($request->query->has('tvp')) {
  71.             $tvp json_decode($this->urlEncryptor->decrypt($request->query->get('tvp')), true);
  72.             $request->request->set('TVP'json_encode($tvp));
  73.             if (isset($tvp['timeout'])) {
  74.                 $currentDateTime = new \DateTime();
  75.                 $currTs $currentDateTime->format('U');
  76.                 if ($tvp['timeout'] > $currTs || $tvp['timeout'] == 0) {
  77.                     if (isset($tvp['token']))
  78.                         $request->request->set('hbeeSessionToken'$tvp['token']);
  79.                 } else {
  80.                     $url $this->router->generate('permission_denied_page');
  81.                     $event->setController(function () use ($url) {
  82.                         return new RedirectResponse($url);
  83.                     });
  84.                 }
  85.             }
  86.         }
  87.         //check if mobile
  88.         $session $this->session;
  89.         if (empty($session->get('appValiditySeconds'))) {  //how many sevonds is valid
  90.             $session->set('appValiditySeconds''_UNSET_');
  91.         }
  92.         if (empty($session->get('devAdminMode'))) {  //how many sevonds is valid
  93.             $session->set('devAdminMode'0);
  94.         }
  95.         if ($devAdminMode != '_UNCHANGED_')
  96.             $session->set('devAdminMode'$devAdminMode);
  97.         $to_set_session_data = [];
  98.         $CurrentRoute $event->getRequest()->attributes->get('_route');
  99.         if ($CurrentRoute == 'switch_app' || $CurrentRoute == 'app_switch_app_api') {
  100.             if ($request->query->has('hbeeSessionToken')) {
  101.                 $em_goc $this->em_goc;
  102.                 $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->query->get('hbeeSessionToken'))['sessionData'];
  103.                 if ($to_set_session_data != null) {
  104.                     foreach ($to_set_session_data as $k => $d) {
  105.                         //check if mobile
  106.                         $session->set($k$d);
  107.                     }
  108.                 } else {
  109.                     $hbeeErrorCode UserConstants::ERROR_TOKEN_EXPIRED;
  110.                 }
  111.             } else {
  112.                 $url $this->router->generate('user_login');
  113.                 if ($CurrentRoute == 'app_switch_app_api')
  114.                     $url .= ("?csToken=" $request->query->get('csToken''') . "&spd=" $request->query->get('spd''') . "&remoteVerify=1");
  115.                 else
  116.                     $url .= ("?csToken=" $request->query->get('csToken''') . "&spd=" $request->query->get('spd''') . "&remoteVerify=" $request->query->get('remoteVerify'0));
  117.                 $session->clear();
  118.                 $session->set('CLEARLOGIN'1);
  119.                 $event->setController(function () use ($url) {
  120.                     return new RedirectResponse($url);
  121.                 });
  122.             }
  123.         }
  124. //        if ($CurrentRoute == 'select_second_layer_api' ) {
  125. //
  126. //            if ($request->query->has('hbeeSessionToken')) {
  127. //
  128. //                $em_goc = $this->em_goc;
  129. //
  130. //
  131. //                $to_set_session_data = MiscActions::GetSessionDataFromToken($em_goc, $request->query->get('hbeeSessionToken'))['sessionData'];
  132. //                if ($to_set_session_data != null) {
  133. //                    foreach ($to_set_session_data as $k => $d) {
  134. //
  135. //                        //check if mobile
  136. //                        $session->set($k, $d);
  137. //                    }
  138. //
  139. //                } else {
  140. //                    $hbeeErrorCode = UserConstants::ERROR_TOKEN_EXPIRED;
  141. //                }
  142. //
  143. //            } else {
  144. //
  145. //
  146. //            }
  147. //        }
  148.         if (!$session->has(UserConstants::USER_ID)) {
  149.             if ($request->request->has('token')) {
  150.                 $em_goc $this->em_goc;
  151.                 $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  152.                 if ($to_set_session_data != null) {
  153.                     foreach ($to_set_session_data as $k => $d) {
  154.                         //check if mobile
  155.                         $session->set($k$d);
  156.                     }
  157.                 } else {
  158.                     $hbeeErrorCode UserConstants::ERROR_TOKEN_EXPIRED;
  159.                 }
  160.             } else if ($request->request->has('hbeeSessionToken')) {
  161.                 $em_goc $this->em_goc;
  162.                 $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('hbeeSessionToken'))['sessionData'];
  163.                 if ($to_set_session_data != null) {
  164.                     foreach ($to_set_session_data as $k => $d) {
  165.                         //check if mobile
  166.                         $session->set($k$d);
  167.                     }
  168.                 } else {
  169.                     $hbeeErrorCode UserConstants::ERROR_TOKEN_EXPIRED;
  170.                 }
  171.             } else if ($request->query->has('hbeeSessionToken')) {
  172.                 $em_goc $this->em_goc;
  173.                 $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->query->get('hbeeSessionToken'))['sessionData'];
  174.                 if ($to_set_session_data != null) {
  175.                     foreach ($to_set_session_data as $k => $d) {
  176.                         //check if mobile
  177.                         $session->set($k$d);
  178.                     }
  179.                 } else {
  180.                     $hbeeErrorCode UserConstants::ERROR_TOKEN_EXPIRED;
  181.                 }
  182.             } else if ($request->request->has('sessionData')) {
  183.                 $to_set_session_data $request->request->get('sessionData');
  184.                 foreach ($to_set_session_data as $k => $d) {
  185.                     //check if mobile
  186.                     $session->set($k$d);
  187.                 }
  188.             } else if ($request->request->has('sessionDataString')) {
  189.                 $to_set_session_data json_decode($request->request->get('sessionDataString'), true);
  190.                 if ($to_set_session_data != null) {
  191.                     foreach ($to_set_session_data as $k => $d) {
  192.                         //check if mobile
  193.                         $session->set($k$d);
  194.                     }
  195.                 }
  196.             }
  197.             if ($request->query->has('iFrameData')) {
  198.                 $session->set(UserConstants::USER_ID$request->query->get('uId'));
  199.                 $session->set(UserConstants::USER_NAME$request->query->get('uName'));
  200.                 $session->set(UserConstants::USER_LOGIN_ID$request->query->get('loginId'));
  201.                 $session->set(UserConstants::APPLICATION_SECRET$request->query->get('sKey'));
  202.                 $session->set(UserConstants::USER_GOC_ID$request->query->get('gocId'));
  203.                 $session->set(UserConstants::USER_DB_NAME$request->query->get('gocDb'));
  204.                 $session->set(UserConstants::USER_DB_USER$request->query->get('gocUsr'));
  205.                 $session->set(UserConstants::USER_DB_PASS$request->query->get('gocPass'));
  206.                 $session->set(UserConstants::USER_DB_HOST$request->query->get('gocDh'));
  207.                 $session->set(UserConstants::USER_TYPE$request->query->get('uType'));
  208.                 $session->set(UserConstants::USER_CURRENT_POSITION$request->query->get('currPos'));
  209.                 $session->set(UserConstants::USER_COMPANY_ID$request->query->get('cmpId'));
  210.                 $session->set(UserConstants::USER_APP_ID$request->query->get('uAId'));
  211.                 $session->set(UserConstants::USER_IMAGE"");
  212.                 $session->set('productNameDisplayType'0);
  213.                 $cmpImg $request->query->get('cmpIm');
  214.                 $cmpName $request->query->get('cmpN');
  215.                 $app_cid $request->query->get('uAId') . "_" $request->query->get('cmpId');
  216.                 $cid $request->query->get('cmpId');
  217.                 $session->set('userCompanyDarkVibrantList'json_encode(array(
  218.                     $cid => ""
  219.                 )));
  220.                 $cmpNameListStr json_encode(array(
  221.                     $cid => $cmpName
  222.                 ));
  223.                 $cmpImageListStr json_encode(array(
  224.                     $cid => $cmpImg
  225.                 ));
  226.                 $session->set(UserConstants::USER_COMPANY_NAME_LIST$cmpNameListStr);
  227.                 $session->set(UserConstants::USER_COMPANY_IMAGE_LIST$cmpImageListStr);
  228.                 $session->set(UserConstants::USER_PROHIBIT_LIST"[]");
  229.                 $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG1);
  230.             }
  231.         }
  232. //        $path=$this->kernelRootDir. '/gifnoc/invdata.json';
  233. //        file_put_contents($path, json_encode(array(
  234. //            'sessionDataString'=>$request->request->get('sessionDataString'),
  235. //            'productCode'=>$request->request->get('productCode'),
  236. //            'userId'=>$session->get(UserConstants::USER_ID),
  237. //            'sessionData'=>json_decode($request->request->get('sessionDataString'),true),
  238. //            'to_set_session_data'=>$to_set_session_data,
  239. ////            'invData'=>$data_searched,
  240. //
  241. //        )));//overwrite
  242.         if (!$session->has('isMobile')) {
  243. //        if
  244.             $useragent $event->getRequest()->headers->get('User-Agent');
  245.             if (!$useragent) {
  246.                 return false;
  247.             }
  248.             $isMobile = (
  249.                 preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i'$useragent) ||
  250.                 preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i'substr($useragent04))
  251.             );
  252.             $session->set('isMobile'$isMobile);
  253.         }
  254.         if ($controller[0] instanceof SessionCheckInterface) {
  255.             if (!empty($session->get(UserConstants::USER_ID))) {
  256.                 if ($session->get(UserConstants::APPLICATION_SECRET) == $this->secretKey) {
  257.                     //if session check variable is more than 1 hour from now, update app validity but if already disabled then check on every call
  258.                     $lastCheckDateTime null;
  259.                     $appValid 1;
  260.                     $currentDateTime = new \DateTime();
  261.                     $currentTime strtotime($currentDateTime->format('Y-m-d h:i:s'));
  262.                     $appIsValidTillTime $currentTime;
  263.                     $appIsValidTillDateTime $currentDateTime;
  264. //                    $session->set('appIsValidTillTime', $appIsValidTillDateTime->format('Y-m-d h:i:s'));
  265.                     if (!empty($session->get('lastCheckAppValidityTime'))) {
  266.                         $lastCheckDateTime strtotime($session->get('lastCheckAppValidityTime'));
  267.                     } else {
  268.                         $lastCheckDateTime strtotime('2022-01-01 00:00:00');
  269.                     }
  270.                     if (!empty($session->get('appIsValidTillTime'))) {
  271.                         $appIsValidTillTime strtotime($session->get('appIsValidTillTime'));
  272.                         $appIsValidTillDateTime = new \DateTime($session->get('appIsValidTillTime'));
  273.                     } else {
  274. //                        $appIsValidTillTime=$currentDateTime;
  275. //                        $session->set('appIsValidTillTime', $appIsValidTillTime->format('Y-m-d h:i:s'));
  276.                     }
  277.                     if (!empty($session->get('appValid'))) {
  278.                         $appValid $session->get('appValid');
  279.                     }
  280.                     $secondsTillLastCheck abs($currentTime $lastCheckDateTime);
  281. //                    $session->set('secondsTillLastCheck',$secondsTillLastCheck);
  282. //                    $session->set('lastCheckAppValiditySecond', abs($currentTime - $lastCheckDateTime));
  283.                     if ($secondsTillLastCheck 7200 || $appValid == 0) {
  284.                         $appValiditySeconds $session->get('appValiditySeconds');
  285.                         $appDataJson System::getAppDataByCurl();
  286. //                        $session->set('appDataJson',$appDataJson);
  287.                         $appData json_decode($appDataJsontrue);
  288. //                        $appIsValidTillTime=$currentDateTime;
  289.                         if ($appData == null)
  290.                             $appData = [];
  291.                         if (isset($appData[$session->get(UserConstants::USER_APP_ID)])) {
  292.                             $session->set('appDataCurl'$appData[$session->get(UserConstants::USER_APP_ID)]);
  293.                             if ($appData[$session->get(UserConstants::USER_APP_ID)]['expired'] == 1) {
  294.                                 $appValid 0;
  295.                                 $appValiditySeconds 0;
  296.                             } else {
  297.                                 $appIsValidTillTime strtotime($appData[$session->get(UserConstants::USER_APP_ID)]['suspensionDate']);
  298.                                 $appIsValidTillDateTime = new \DateTime($appData[$session->get(UserConstants::USER_APP_ID)]['suspensionDate']);
  299.                                 $appValiditySeconds $appIsValidTillTime $currentTime;
  300.                                 if ($appValiditySeconds 0)
  301.                                     $appValid 0;
  302.                                 else
  303.                                     $appValid 1;
  304.                             }
  305.                         } else {
  306.                         }
  307.                         $session->set('appValiditySeconds'$appValiditySeconds);
  308.                         $session->set('appIsValidTillTime'$appIsValidTillDateTime->format('Y-m-d h:i:s'));
  309.                         $session->set('lastCheckAppValidityTime'$currentDateTime->format('Y-m-d h:i:s'));
  310.                         $session->set('appValid'$appValid);
  311.                     }
  312.                     $session->set('appIsValidTillTime'$appIsValidTillDateTime->format('Y-m-d h:i:s'));
  313.                     if ($appValid != 1) {
  314.                         $url $this->router->generate('user_logout');
  315.                         if (strripos($request->server->get('REQUEST_URI'), 'select_data') === false) {
  316.                             if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  317.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('REQUEST_URI'));
  318.                             }
  319.                         } else {
  320.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  321.                         }
  322. //                        if ($request->server->has("REQUEST_URI")) {
  323. //                            if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  324. ////                            return $this->redirect($request->request->get('HTTP_REFERER'));
  325. //                                $session->set('LAST_REQUEST_URI_BEFORE_LOGIN', $request->server->get('REQUEST_URI'));
  326. //                            }
  327. //                        }
  328. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  329.                         $event->setController(function () use ($url) {
  330.                             return new RedirectResponse($url);
  331.                         });
  332.                     }
  333.                     $gocId $session->get(UserConstants::USER_GOC_ID);
  334.                     if ($gocId != && $gocId != "") {
  335.                         $gocDbName $session->get(UserConstants::USER_DB_NAME);
  336.                         $gocDbUser $session->get(UserConstants::USER_DB_USER);
  337.                         $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  338.                         $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  339. //                        $connector = $this->container->get('application_connector');
  340.                         $connector $this->applicationConnector;
  341.                         $connector->resetConnection(
  342.                             'default',
  343.                             $gocDbName,
  344.                             $gocDbUser,
  345.                             $gocDbPass,
  346.                             $gocDbHost,
  347.                             $reset false);
  348.                     }
  349.                     // User already have logged in. lets check its type
  350.                     if (
  351.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM ||
  352.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  353.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SUPPLIER ||
  354.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER ||
  355.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_ENTITY_USER_GROUP_OWNER ||
  356.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_CLIENT ||
  357.                         $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_APPLICANT
  358.                     ) {
  359.                         if (!empty($session->get('TRIGGER_RESET_PASSWORD')) || $session->get('IS_EMAIL_VERIFIED'0) == 0) {
  360.                             if (!empty($session->get('TRIGGER_RESET_PASSWORD'))) {
  361.                                 if ($session->get('TRIGGER_RESET_PASSWORD') == && !$authTokenInHeader) {
  362.                                     $red $this->router->generate('reset_password_new_password');
  363.                                     if (!$request->request->has('remoteVerify')) {
  364.                                         $session->set('TRIGGER_RESET_PASSWORD'0);
  365.                                         $event->setController(function () use ($red) {
  366.                                             return new RedirectResponse($red);
  367.                                         });
  368.                                     }
  369.                                 }
  370.                             }
  371.                             if ($session->get('IS_EMAIL_VERIFIED') == && !$authTokenInHeader) {
  372.                                 $red $this->router->generate('verify_email');
  373.                                 if (!$request->request->has('remoteVerify')) {
  374.                                     $event->setController(function () use ($red) {
  375.                                         return new RedirectResponse($red);
  376.                                     });
  377.                                 }
  378.                             }
  379.                         } else if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  380.                             if (strripos($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'), 'select_data') === false) {
  381.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  382.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  383.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  384.                                     if (!$request->request->has('remoteVerify')) {
  385.                                         $event->setController(function () use ($red) {
  386.                                             return new RedirectResponse($red);
  387.                                         });
  388.                                     }
  389.                                 }
  390.                             } else {
  391.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  392.                             }
  393.                         }
  394.                     } else {
  395.                         $message "Session Not Found";
  396.                         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  397.                         } else {
  398.                             if ($request->server->has("REQUEST_URI")) {
  399.                                 if (strripos($request->server->get('REQUEST_URI'), 'select_data') === false) {
  400.                                     if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  401.                                         $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('REQUEST_URI'));
  402.                                     }
  403.                                 } else {
  404.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  405.                                 }
  406.                             }
  407.                         }
  408.                         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  409.                             $session->set('jsonStrForListenerData'json_encode(array(
  410.                                 'uid' => 0,
  411.                                 'session' => [],
  412.                                 'success' => false,
  413.                                 'sessionExists' => false,
  414.                                 'hbeeErrorCode' => $hbeeErrorCode,
  415.                                 'errorStr' => $message,
  416.                                 'session_data' => [],
  417. //                                'session2' => $_SESSION,
  418.                             )));
  419.                             $url $this->router->generate('return_json_for_listener');
  420. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  421.                             $event->getRequest()->attributes->set('_controller''ApplicationBundle:PublicPages:ReturnJsonForListener');
  422.                             $event->setController($this->resolver->getController($request));
  423. //                        $event->setController(function () use ($url) {
  424. //                            return new RedirectResponse($url);
  425. //                        });
  426.                         } else {
  427.                             $url $this->router->generate('user_logout');
  428.                             $event->setController(function () use ($url) {
  429.                                 return new RedirectResponse($url);
  430.                             });
  431.                         }
  432.                     }
  433.                 } else {
  434.                     $message "Session Not Found";
  435.                     if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  436.                     } else {
  437.                         if ($request->server->has("REQUEST_URI")) {
  438.                             if (strripos($request->server->get('REQUEST_URI'), 'select_data') === false) {
  439.                                 if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  440.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('REQUEST_URI'));
  441.                                 }
  442.                             } else {
  443.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  444.                             }
  445. //                            if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  446. ////                            return $this->redirect($request->request->get('HTTP_REFERER'));
  447. //                                $session->set('LAST_REQUEST_URI_BEFORE_LOGIN', $request->server->get('REQUEST_URI'));
  448. //                            }
  449.                         }
  450.                     }
  451.                     if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  452.                         $session->set('jsonStrForListenerData'json_encode(array(
  453.                             'uid' => 0,
  454.                             'session' => [],
  455.                             'success' => false,
  456.                             'sessionExists' => false,
  457.                             'hbeeErrorCode' => $hbeeErrorCode,
  458.                             'errorStr' => $message,
  459.                             'session_data' => [],
  460. //                            'session2' => $_SESSION,
  461.                         )));
  462.                         $url $this->router->generate('return_json_for_listener');
  463. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  464.                         $event->getRequest()->attributes->set('_controller''ApplicationBundle:PublicPages:ReturnJsonForListener');
  465.                         $event->setController($this->resolver->getController($request));
  466. //                        $event->setController(function () use ($url) {
  467. //                            return new RedirectResponse($url);
  468. //                        });
  469.                     } else {
  470.                         $url $this->router->generate('user_logout');
  471.                         $event->setController(function () use ($url) {
  472.                             return new RedirectResponse($url);
  473.                         });
  474.                     }
  475.                 }
  476.             } else {
  477.                 // User can't see this page until do a login. let him/her login first.
  478.                 $message "Session Not Found";
  479.                 $hbeeErrorCode UserConstants::ERROR_TOKEN_EXPIRED;
  480.                 if ($authTokenInHeader || $request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  481.                 } else {
  482.                     if ($request->server->has("REQUEST_URI")) {
  483.                         if (strripos($request->server->get('REQUEST_URI'), 'select_data') === false) {
  484.                             if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  485.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('REQUEST_URI'));
  486.                             }
  487.                         } else {
  488.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  489.                         }
  490. //                        if ($request->server->get('REQUEST_URI') != '/' && $request->server->get('REQUEST_URI') != '') {
  491. ////                            return $this->redirect($request->request->get('HTTP_REFERER'));
  492. //                            $session->set('LAST_REQUEST_URI_BEFORE_LOGIN', $request->server->get('REQUEST_URI'));
  493. //                        }
  494.                     }
  495.                 }
  496.                 $session->set('jsonStrForListenerData'json_encode([]));
  497.                 if ($authTokenInHeader || $request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  498.                     $session->set('jsonStrForListenerData'json_encode(array(
  499.                         'uid' => 0,
  500.                         'session' => [],
  501.                         'success' => false,
  502.                         'sessionExists' => false,
  503.                         'hbeeErrorCode' => $hbeeErrorCode,
  504.                         'errorStr' => $message,
  505.                         'session_data' => [],
  506. //                        'session2' => $_SESSION,
  507.                     )));
  508.                     $url $this->router->generate('return_json_for_listener');
  509. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  510.                     $event->getRequest()->attributes->set('_controller''ApplicationBundle:PublicPages:ReturnJsonForListener');
  511.                     $event->setController($this->resolver->getController($request));
  512. //                    $event->setController(function () use ($url) {
  513. //                        return new RedirectResponse($url);
  514. //                    });
  515. //                    return new JsonResponse();
  516.                 } else {
  517.                     $url $this->router->generate('user_login');
  518. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  519.                     $event->setController(function () use ($url) {
  520.                         return new RedirectResponse($url);
  521.                     });
  522.                 }
  523.             }
  524.             $em $this->em;
  525. //            if ($CurrentRoute != "update_database_schema")
  526. //                MiscActions::decryptTrans($em, '_ALL_', 0);
  527. //            Here we got a general user who have all the right things. Let see if he/she have permission to tre current route.
  528. //            $ROUTE_LIST=json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  529.             $PROHIBIT_LIST json_decode($session->get(UserConstants::USER_PROHIBIT_LIST), true);
  530.             $CurrentRoute $event->getRequest()->attributes->get('_route');
  531.             $PL_unfiltered json_decode($session->get(UserConstants::USER_POSITION_LIST), true);
  532.             if ($PL_unfiltered == null)
  533.                 $PL_unfiltered = [];
  534.             $PL = [];
  535.             foreach ($PL_unfiltered as $PLU) {
  536.                 if ($PLU != '' && $PLU != " " && $PLU != && $PLU != null)
  537.                     $PL[] = $PLU;
  538.             }
  539.             if (!empty($PL) && $session->get(UserConstants::USER_CURRENT_POSITION) == 0) {
  540.                 $url $this->router->generate('user_login_position');
  541.                 $event->setController(function () use ($url) {
  542.                     return new RedirectResponse($url);
  543.                 });
  544.             }
  545.             if ($CurrentRoute == "user_login_position") {
  546.                 if (!empty($session->get(UserConstants::USER_ID))) {
  547.                     // This is an system user. send him to system dashboard
  548.                     if ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM) {
  549.                         // This is an system user. send him to system dashboard
  550.                         $url $this->router->generate('system_admin_dashboard');
  551.                         $event->setController(function () use ($url) {
  552.                             return new RedirectResponse($url);
  553.                         });
  554.                     } else {
  555.                         if (!empty($session->get(UserConstants::USER_CURRENT_POSITION)) && $session->get(UserConstants::USER_CURRENT_POSITION) != 0) {
  556.                             // user position got set up. send him to the normal dashboard.
  557.                             $PL json_decode($session->get(UserConstants::USER_POSITION_LIST), true);
  558.                             if ($PL == null$PL = [];
  559.                             if (count($PL) <= 1) {
  560.                                 $url $this->router->generate('dashboard');
  561.                                 $event->setController(function () use ($url) {
  562.                                     return new RedirectResponse($url);
  563.                                 });
  564.                             }
  565.                         }
  566.                     }
  567.                 } else {
  568.                     // User can't see this page until do a login. let him/her login first.
  569.                     $url $this->router->generate('user_login');
  570.                     $event->setController(function () use ($url) {
  571.                         return new RedirectResponse($url);
  572.                     });
  573.                 }
  574.             }
  575.             if ($permissionOverride == && $CurrentRoute != "dashboard" && $CurrentRoute != $session->get(UserConstants::USER_DEFAULT_ROUTE)) {
  576.                 if ($PROHIBIT_LIST != null or $PROHIBIT_LIST != []) {
  577.                     if (in_array($CurrentRoute$PROHIBIT_LIST)) {
  578.                         // User is not authorized. send him to dashboard
  579. //                    $controller->addFlash(
  580. //                        'error',
  581. //                        'Sorry Couldnot insert Data.'
  582. //                    );
  583.                         $url $this->router->generate('permission_denied_page');
  584.                         $event->setController(function () use ($url) {
  585.                             return new RedirectResponse($url);
  586.                         });
  587.                     }
  588.                 }
  589.             }
  590.         }
  591.         if ($controller[0] instanceof LoginInterface) {
  592.             $session $this->session;
  593.             // Three situation here
  594.             //  1. Have no session
  595.             //  2. Have session but no position
  596.             //  3. Have session and position
  597.             $route $event->getRequest()->attributes->get('_route');
  598.             $systemType '_ERP';//default
  599.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  600.             if ($route == "user_login") {
  601.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  602.                     $session->clear();
  603.                 } else if (!empty($session->get(UserConstants::USER_ID))) {
  604.                     // User already have logged in. lets check its type
  605.                     if ($systemType == '_ERP_') {
  606.                         if ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM) {
  607.                             // This is an system user. send him to system dashboard
  608.                             $url $this->router->generate('system_admin_dashboard');
  609.                             $event->setController(function () use ($url) {
  610.                                 return new RedirectResponse($url);
  611.                             });
  612.                         } else {
  613.                             // This user is a normal user. Check if its login position got set.
  614.                             if (!empty($session->get(UserConstants::USER_CURRENT_POSITION))) {
  615.                                 // user position got set up. send him to the normal dashboard.
  616.                                 $url $this->router->generate('dashboard');
  617.                                 if ($request->request->has('remoteVerify')) {
  618.                                     $session->set('remoteVerified'1);
  619.                                     $url $this->router->generate('get_session_data_for_app');
  620.                                     $event->setController(function () use ($url) {
  621.                                         return new RedirectResponse($url);
  622.                                     });
  623.                                 }
  624.                                 $event->setController(function () use ($url) {
  625.                                     return new RedirectResponse($url);
  626.                                 });
  627.                             } else {
  628.                                 // user position have not set up. send it to the position page
  629.                                 $url $this->router->generate('user_login_position');
  630.                                 $event->setController(function () use ($url) {
  631.                                     return new RedirectResponse($url);
  632.                                 });
  633.                             }
  634.                         }
  635.                         //do nothing its default to dashboard index
  636.                     } else if ($systemType == '_BUDDYBEE_') {
  637. //                        $event->getRequest()->attributes->set('_controller', 'ApplicationBundle:BuddybeePublic:ConsultancyHomePage');
  638. //                        $event->setController($this->resolver->getController($request));
  639.                     }
  640.                 } else {
  641.                     if ($systemType == '_ERP_') {
  642.                         //do nothing its default to dashboard index
  643.                     } else if ($systemType == '_BUDDYBEE_' && $request->isMethod('GET')) {
  644.                         if ($request->request->has('oAuthData') || $request->query->has('oAuthData') || $request->query->has('code')) {
  645.                         } else {
  646.                             $event->getRequest()->attributes->set('_controller''ApplicationBundle\Modules\Authentication\Controller\UserLoginController::applicantLoginAction');
  647.                             $event->setController($this->resolver->getController($request));
  648.                         }
  649.                     }
  650. //                    if ($systemType == '_BUDDYBEE_' && $request->isMethod('POST')) {
  651. //
  652. //                            $event->getRequest()->attributes->set('_controller', 'ApplicationBundle:UserLogin:applicantLogin');
  653. //                        $event->setController($this->resolver->getController($request));
  654. //                    }
  655.                 }
  656.             }
  657.         }
  658.         // Checking if its a system url request.
  659.         if ($controller[0] instanceof SystemInterface) {
  660.             // System controller.
  661.             $session $this->session;
  662.             if (!empty($session->get(UserConstants::USER_ID))) {
  663.                 if ($session->get(UserConstants::USER_TYPE) != UserConstants::USER_TYPE_SYSTEM) {
  664.                     // Kick the idiot out from here. If possible, keep a track
  665.                     $url $this->router->generate('user_logout');
  666.                     $event->setController(function () use ($url) {
  667.                         return new RedirectResponse($url);
  668.                     });
  669.                 } else {
  670.                     $lastCheckDateTime null;
  671.                     $appValid 1;
  672.                     $currentDateTime = new \DateTime();
  673.                     $currentTime strtotime($currentDateTime->format('Y-m-d h:i:s'));
  674.                     $appIsValidTillTime $currentTime;
  675.                     $appIsValidTillDateTime $currentDateTime;
  676. //                    $session->set('appIsValidTillTime', $appIsValidTillDateTime->format('Y-m-d h:i:s'));
  677.                     if (!empty($session->get('lastCheckAppValidityTime'))) {
  678.                         $lastCheckDateTime strtotime($session->get('lastCheckAppValidityTime'));
  679.                     } else {
  680.                         $lastCheckDateTime strtotime('2022-01-01 00:00:00');
  681.                     }
  682.                     if (!empty($session->get('appIsValidTillTime'))) {
  683.                         $appIsValidTillTime strtotime($session->get('appIsValidTillTime'));
  684.                         $appIsValidTillDateTime = new \DateTime($session->get('appIsValidTillTime'));
  685.                     } else {
  686. //                        $appIsValidTillTime=$currentDateTime;
  687. //                        $session->set('appIsValidTillTime', $appIsValidTillTime->format('Y-m-d h:i:s'));
  688.                     }
  689.                     if (!empty($session->get('appValid'))) {
  690.                         $appValid $session->get('appValid');
  691.                     }
  692.                     $secondsTillLastCheck abs($currentTime $lastCheckDateTime);
  693. //                    $session->set('lastCheckAppValiditySecond', abs($currentTime - $lastCheckDateTime));
  694.                     if ($secondsTillLastCheck 7200 || $appValid == 0) {
  695.                         $appValiditySeconds $session->get('appValiditySeconds');
  696.                         $appDataJson System::getAppDataByCurl();
  697.                         $appData json_decode($appDataJsontrue);
  698. //                        $appIsValidTillTime=$currentDateTime;
  699.                         if ($appData == null)
  700.                             $appData = [];
  701.                         if (isset($appData[$session->get(UserConstants::USER_APP_ID)])) {
  702.                             $session->set('appDataCurl'$appData[$session->get(UserConstants::USER_APP_ID)]);
  703.                             if ($appData[$session->get(UserConstants::USER_APP_ID)]['expired'] == 1) {
  704.                                 $appValid 0;
  705.                                 $appValiditySeconds 0;
  706.                             } else {
  707.                                 $appIsValidTillTime strtotime($appData[$session->get(UserConstants::USER_APP_ID)]['suspensionDate']);
  708.                                 $appIsValidTillDateTime = new \DateTime($appData[$session->get(UserConstants::USER_APP_ID)]['suspensionDate']);
  709.                                 $appValiditySeconds $appIsValidTillTime $currentTime;
  710.                                 if ($appValiditySeconds 0)
  711.                                     $appValid 0;
  712.                                 else
  713.                                     $appValid 1;
  714.                             }
  715.                         }
  716.                         $session->set('appValiditySeconds'$appValiditySeconds);
  717.                         $session->set('appIsValidTillTime'$appIsValidTillDateTime->format('Y-m-d h:i:s'));
  718.                         $session->set('lastCheckAppValidityTime'$currentDateTime->format('Y-m-d h:i:s'));
  719.                         $session->set('appValid'$appValid);
  720.                     }
  721.                     $session->set('appIsValidTillTime'$appIsValidTillDateTime->format('Y-m-d h:i:s'));
  722.                     if ($appValid != 1) {
  723.                         $url $this->router->generate('user_logout');
  724. //                $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1));
  725.                         $event->setController(function () use ($url) {
  726.                             return new RedirectResponse($url);
  727.                         });
  728.                     }
  729.                     $gocId $session->get(UserConstants::USER_GOC_ID);
  730.                     if ($gocId != && $gocId != "") {
  731.                         $gocDbName $session->get(UserConstants::USER_DB_NAME);
  732.                         $gocDbUser $session->get(UserConstants::USER_DB_USER);
  733.                         $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  734.                         $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  735. //                        $connector = $this->container->get('application_connector');
  736.                         $connector $this->applicationConnector;
  737.                         $connector->resetConnection(
  738.                             'default',
  739.                             $gocDbName,
  740.                             $gocDbUser,
  741.                             $gocDbPass,
  742.                             $gocDbHost,
  743.                             $reset true);
  744.                     }
  745.                 }
  746.             } else {
  747.                 // Seriously !! How did this person get this url. Track the pc if possible.
  748.                 $url $this->router->generate('user_login');
  749.                 $event->setController(function () use ($url) {
  750.                     return new RedirectResponse($url);
  751.                 });
  752.             }
  753.         }
  754.         //dashboard for diff aspects
  755.         if ($event->getRequest()->attributes->get('_route') == 'dashboard') {
  756.             $systemType '_ERP';//default
  757.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  758.             if ($systemType == '_ERP_') {
  759.                 //do nothing its default to dashboard index
  760.             } else if ($systemType == '_BUDDYBEE_') {
  761.                 $event->getRequest()->attributes->set('_controller''ApplicationBundle\Modules\Buddybee\Controller\BuddybeePublicController:ConsultancyHomePageAction');
  762.                 $event->setController($this->resolver->getController($request));
  763.             } else if ($systemType == '_CENTRAL_') {
  764.                 $event->getRequest()->attributes->set('_controller''ApplicationBundle\Modules\HoneybeeWeb\Controller\HoneybeeWebPublicController:CentralHomePageAction');
  765.                 $event->setController($this->resolver->getController($request));
  766.             }
  767. //            $event->setController(function() use ($url) {
  768. //                return new RedirectResponse($url);
  769. //            });
  770. //            $event->setController((\ApplicationBundle\Controller\BuddybeePublicController())->ConsultancyHomePageAction() );
  771.         }
  772.     }
  773.     public function onKernelResponse(FilterResponseEvent $event)
  774.     {
  775.         $session $this->session;
  776.         $request $event->getRequest();
  777.         $response $event->getResponse();
  778.         //temp debug
  779.         $em $this->em;
  780.         $currRoute $request->attributes->get('_route');
  781. //        if ($currRoute != "update_database_schema")
  782. //            MiscActions::encryptTrans($em, '_ALL_', 0);
  783.         if ($currRoute=='zkteco_handshake' ||
  784.             $currRoute=='zkteco_get_request' ||
  785.             $currRoute=='zkteco_device_cmd'
  786.         ) {
  787.             $response->headers->remove('Date');
  788.             $response->headers->remove('date');
  789.             $response->setStatusCode(200);
  790. // Remove headers Symfony adds automatically
  791.             $response->headers->remove('Cache-Control');
  792.             $response->headers->remove('Last-Modified');
  793.             $response->headers->remove('Expires');
  794.         } else {
  795.             if (
  796.                 ($request->request->has('returnJson') || $request->request->has('remoteVerify')) &&
  797.                 $request->request->has('token') &&
  798.                 !in_array($currRoute, [
  799.                     'select_data_ajax',
  800.                     'select_data_api',
  801.                     'select_data_ajax_public',
  802.                 ])
  803.             ) {
  804.                 $currDate = new \DateTime();
  805.                 $to_write '';
  806.                 $to_write .= "\nToken--" $request->request->get('token''NONE') . '  : ' $currDate->format('F d Y H:i:s');
  807.                 $to_write .= "\nResponse:\n
  808.             ";
  809.                 if (is_string($response->getContent()))
  810.                     $to_write .= $response->getContent();
  811.                 else
  812.                     $to_write .= json_encode($response->getContent());
  813. //            System::log_it($this->container->getParameter('kernel.root_dir'), $to_write, $currRoute, 1);
  814.             }
  815.             if ($session->has('remoteVerified')) {
  816.                 $lifetime 86400// 1 day
  817. //            $response->headers->setCookie(Cookie::create('PHPSESSID', $event->getRequest()->cookies->get('PHPSESSID'),time()+$lifetime));
  818.                 $response->headers->set('Access-Control-Allow-Origin'$event->getRequest()->headers->get('origin'));
  819.                 $response->headers->set('Access-Control-Allow-Credentials''true');
  820. //            $response->headers->setCookie(Cookie::create('PIKAMASTER', $event->getRequest()->cookies->get('PHPSESSID'),time()+$lifetime));
  821.             } else {
  822.                 // create a hash and set it as a response header
  823. //        $hash = sha1($response->getContent().$token);
  824. //            $response->headers->set('Access-Control-Allow-Origin', '*');
  825. //            $response->headers->set('Access-Control-Allow-Credentials', 'true');
  826.                 $response->headers->set('Access-Control-Allow-Origin'$event->getRequest()->headers->get('origin'));
  827.                 $response->headers->set('Access-Control-Allow-Credentials''true');
  828. //            $response->headers->setCookie(Cookie::create('honeybeeCAuthId', $session->get(UserConstants::USER_ID)));
  829. //            $response->headers->setCookie(Cookie::create('honeybeeCAuthId2', $event->getRequest()->cookies->get('PHPSESSID')));
  830.             }
  831. //        if($session->has(UserConstants::USER_ID)) {
  832. //            if ($session->get(UserConstants::USER_ID) == '' || $session->get(UserConstants::USER_ID) == '') {
  833. //                $response->headers->setCookie(Cookie::create('USRCKIE', ''));
  834. //                $response->headers->setCookie(Cookie::create('REMEMBERME', ''));
  835. //                $response->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', ''));
  836. //            }
  837. //        }
  838. //        else
  839. //        {
  840. //            $response->headers->setCookie(Cookie::create('USRCKIE', ''));
  841. //            $response->headers->setCookie(Cookie::create('REMEMBERME', ''));
  842. //            $response->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', ''));
  843. //        }
  844.             if ($session->has('CLEARLOGIN')) {
  845.                 if ($session->get('CLEARLOGIN') == 1) {
  846.                     if (version_compare(PHP_VERSION'7.0.0''>=')) {
  847.                         $response->headers->setCookie(Cookie::create('USRCKIE'''));
  848.                         $response->headers->setCookie(Cookie::create('REMEMBERME'''));
  849.                         $response->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE'''));
  850.                     } else {
  851.                         $response->headers->setCookie(new Cookie('USRCKIE'''));
  852.                         $response->headers->setCookie(new Cookie('REMEMBERME'''));
  853.                         $response->headers->setCookie(new Cookie('CLEARLOGINCOOKIE'''));
  854.                     }
  855.                 }
  856.                 $session->set('CLEARLOGIN'0);
  857.             } else {
  858.             }
  859.             if ($session->has('REMEMBERME')) {
  860.                 if ($session->get('REMEMBERME') == 1) {
  861.                     $lifetime 86400// 1 day
  862.                     if (version_compare(PHP_VERSION'7.0.0''>=')) {
  863.                         $response->headers->setCookie(Cookie::create('USRCKIE'json_encode(array(
  864.                                 'uid' => $session->get(UserConstants::USER_ID),
  865.                                 'ut' => $session->get(UserConstants::USER_TYPE),
  866.                                 'companyId' => $session->get(UserConstants::USER_COMPANY_ID),
  867.                                 'gocId' => $session->get(UserConstants::USER_GOC_ID),
  868.                             )
  869.                         ), time() + $lifetime
  870.                         )
  871.                         );
  872.                         $response->headers->setCookie(Cookie::create('REMEMBERMEACTIVATED''PIKA'));
  873.                     } else {
  874.                         $response->headers->setCookie(new Cookie('USRCKIE'json_encode(array(
  875.                                     'uid' => $session->get(UserConstants::USER_ID),
  876.                                     'ut' => $session->get(UserConstants::USER_TYPE),
  877.                                     'companyId' => $session->get(UserConstants::USER_COMPANY_ID),
  878.                                     'gocId' => $session->get(UserConstants::USER_GOC_ID),
  879.                                 )
  880.                             ), time() + $lifetime
  881.                             )
  882.                         );
  883.                         $response->headers->setCookie(new Cookie('REMEMBERMEACTIVATED''PIKA'));
  884.                     }
  885.                 } else {
  886.                     if (version_compare(PHP_VERSION'7.0.0''>=')) {
  887.                         $response->headers->setCookie(Cookie::create('USRCKIE'json_encode(array(
  888.                                     'uid' => $session->get(UserConstants::USER_ID),
  889.                                     'ut' => $session->get(UserConstants::USER_TYPE),
  890.                                     'companyId' => $session->get(UserConstants::USER_COMPANY_ID),
  891.                                     'gocId' => $session->get(UserConstants::USER_GOC_ID),
  892.                                 )
  893.                             )
  894.                         )
  895.                         );
  896.                         $response->headers->setCookie(Cookie::create('REMEMBERMEACTIVATED''MASTER'));
  897.                     } else {
  898.                         $response->headers->setCookie(new Cookie('USRCKIE'json_encode(array(
  899.                                         'uid' => $session->get(UserConstants::USER_ID),
  900.                                         'ut' => $session->get(UserConstants::USER_TYPE),
  901.                                         'companyId' => $session->get(UserConstants::USER_COMPANY_ID),
  902.                                         'gocId' => $session->get(UserConstants::USER_GOC_ID),
  903.                                     )
  904.                                 )
  905.                             )
  906.                         );
  907.                         $response->headers->setCookie(new Cookie('REMEMBERMEACTIVATED''MASTER'));
  908.                     }
  909.                 }
  910.             } else {
  911.                 if (version_compare(PHP_VERSION'7.0.0''>='))
  912.                     $response->headers->setCookie(Cookie::create('REMEMBERMEACTIVATED''CHU'));
  913.                 else
  914.                     $response->headers->setCookie(new Cookie('REMEMBERMEACTIVATED''CHU'));
  915.             }
  916.         }
  917.     }
  918.     public function onKernelException(ExceptionEvent $event)
  919.     {
  920.         $exception $event->getThrowable();
  921.         $session $this->session;
  922.         $request $event->getRequest();
  923.         $response $event->getResponse();
  924.         //temp debug
  925.         $em $this->em;
  926.         $currRoute $request->attributes->get('_route');
  927. //        if ($currRoute != "update_database_schema")
  928. //            MiscActions::encryptTrans($em, '_ALL_', 0);
  929.         if (
  930.             (
  931.                 $request->query->has('returnJson') ||
  932.                 $request->request->has('returnJson') ||
  933.                 $request->query->has('remoteVerify') ||
  934.                 $request->request->has('remoteVerify') ||
  935.                 $event->getRequest()->headers->get('auth-token'))
  936.         ) {
  937.             $response = new JsonResponse([
  938.                 'success' => false,
  939.                 'error' => 'server_error',
  940.                 'message' => $exception->getMessage(),
  941.             ], 500);
  942.             $event->setResponse($response);
  943.             $event->stopPropagation();
  944.             if ($origin $event->getRequest()->headers->get('Origin')) {
  945.                 $response->headers->set('Access-Control-Allow-Origin'$origin);
  946.                 $response->headers->set('Access-Control-Allow-Credentials''true');
  947.             }
  948.         }
  949.     }
  950. }