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

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.     // marketplace: raachSolar login
  26.     public function MarketPlaceLoginAction()
  27.     {
  28.         return $this->render('@Authentication/pages/views/market_place_login.html.twig',
  29.             array(
  30.                 'page_title' => 'Login',
  31.             ));
  32.     }
  33.     // marketplace: raachSolar signup
  34.     public function MarketPlaceSignupAction()
  35.     {
  36.         return $this->render('@Authentication/pages/views/market_place_signup.html.twig',
  37.             array(
  38.                 'page_title' => 'Signup',
  39.             ));
  40.     }
  41.     // marketplace: reset password
  42.     public function MarketPlaceResetPasswordAction()
  43.     {
  44.         return $this->render('@Authentication/pages/views/market_place_reset_password.html.twig',
  45.             array(
  46.                 'page_title' => 'Reset Password',
  47.             ));
  48.     }
  49.     // marketplace: verrify code
  50.     public function MarketPlaceVerifyCodeAction()
  51.     {
  52.         return $this->render('@Authentication/pages/views/market_place_verify_code.html.twig',
  53.             array(
  54.                 'page_title' => 'verify code',
  55.             ));
  56.     }
  57.     // marketplace: vendor login
  58.     public function MarketPlaceVendorLoginAction()
  59.     {
  60.         return $this->render('@Authentication/pages/views/market_place_vendor_login.html.twig',
  61.             array(
  62.                 'page_title' => 'vendor Login',
  63.             ));
  64.     }
  65.     // marketplace: vendor signup
  66.     public function MarketPlaceVendorSignupAction()
  67.     {
  68.         return $this->render('@Authentication/pages/views/market_place_vendor_signup.html.twig',
  69.             array(
  70.                 'page_title' => 'vendor Signup',
  71.             ));
  72.     }
  73.     public function GetSessionDataForAppAction(Request $request$remoteVerify 0$version 'latest',
  74.                                                        $identifier '_default_',
  75.                                                        $refRoute '',
  76.                                                        $apiKey '_ignore_')
  77.     {
  78.         $message "";
  79.         $gocList = [];
  80.         $session $request->getSession();
  81.         if ($request->request->has('token')) {
  82.             $em_goc $this->getDoctrine()->getManager('company_group');
  83.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  84.             if ($to_set_session_data != null) {
  85.                 foreach ($to_set_session_data as $k => $d) {
  86.                     //check if mobile
  87.                     $session->set($k$d);
  88.                 }
  89.             }
  90.         }
  91.         if ($request->request->has('sessionData')) {
  92.             $to_set_session_data $request->request->get('sessionData');
  93.             foreach ($to_set_session_data as $k => $d) {
  94.                 //check if mobile
  95.                 $session->set($k$d);
  96.             }
  97.         }
  98.         if ($version !== 'latest') {
  99.             $session_data = array(
  100.                 'oAuthToken' => $session->get('oAuthToken'),
  101.                 'locale' => $session->get('locale'),
  102.                 'firebaseToken' => $session->get('firebaseToken'),
  103.                 'token' => $session->get('token'),
  104.                 UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  105.                 UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  106.                 UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  107.                 UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  108.                 UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  109.                 UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  110.                 UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  111.                 UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  112.                 UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  113.                 UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  114.                 UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  115.                 UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  116.                 UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  117.                 UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  118.                 UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  119.                 UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  120.                 UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  121.                 UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  122.                 UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  123.                 UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  124.                 UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  125.                 UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  126.                 //new addition
  127.                 'appIdList' => $session->get('appIdList'),
  128.                 'branchIdList' => $session->get('branchIdList'null),
  129.                 'branchId' => $session->get('branchId'null),
  130.                 'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  131.                 'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  132.                 'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  133.                 'userAccessList' => $session->get('userAccessList'),
  134.                 'csToken' => $session->get('csToken'),
  135.             );
  136.         } else {
  137.             $session_data = array(
  138.                 'oAuthToken' => $session->get('oAuthToken'),
  139.                 'locale' => $session->get('locale'),
  140.                 'firebaseToken' => $session->get('firebaseToken'),
  141.                 'token' => $session->get('token'),
  142.                 UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  143.                 UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  144.                 UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  145.                 UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  146.                 UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  147.                 UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  148.                 UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  149.                 UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  150.                 UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  151.                 UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  152.                 UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  153.                 UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  154.                 UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  155.                 UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  156.                 UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  157.                 UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  158.                 UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  159.                 UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  160.                 UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  161.                 UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  162.                 UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  163.                 UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  164.                 UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  165.                 UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  166.                 UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  167.                 UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  168.                 //new addition
  169.                 'appIdList' => $session->get('appIdList'),
  170.                 'branchIdList' => $session->get('branchIdList'null),
  171.                 'branchId' => $session->get('branchId'null),
  172.                 'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  173.                 'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  174.                 'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  175.                 'userAccessList' => $session->get('userAccessList'),
  176.                 'csToken' => $session->get('csToken'),
  177.             );
  178.         }
  179.         $response = new JsonResponse(array(
  180.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  181.             //            'session'=>$request->getSession(),
  182.             'session_data' => $session_data,
  183.             //            'session2'=>$_SESSION,
  184.         ));
  185.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  186.         $response->headers->set('Access-Control-Allow-Methods''POST');
  187.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  188.         return $response;
  189.     }
  190.     public function SignUpAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantDirectLogin 0)
  191.     {
  192.         if ($request->query->has('refRoute')) {
  193.             $refRoute $request->query->get('refRoute');
  194.             if ($refRoute == '8917922')
  195.                 $redirectRoute 'apply_for_consultant';
  196.         }
  197. //        if ($request->request->has('rcpscrtkn'))
  198.         if ($request->isMethod('POST')) {
  199.             if ($request->request->get('remoteVerify'0) != 1) {
  200.                 $rcptoken $request->request->get('rcpscrtkn') ?? '';
  201.                 $action 'SIGNUP';
  202.                 $check MiscActions::verifyRecaptchaEnterprise(
  203.                     $rcptoken,
  204.                     $action,              // enforce what you expect
  205.                     '6LdnzkAsAAAAAJRsPy3yq3B8iMZP55CGOOiXRglF'// the v3 site key
  206.                     'honeybee-erp',    // e.g. honeybee-erp
  207.                     'AIzaSyDZt7Zi1Qtcd13NeGa1eEGoB9kXyRKk_G8',    // keep server-only
  208.                     0.5
  209.                 );
  210.                 $session $request->getSession();
  211.                 $session->set('RCPDATA'json_encode($check));
  212.                 if (!$check['ok']) {
  213.                     $message "Could not Determine authenticity";
  214.                     if ($request->request->get('remoteVerify'0) == 1)
  215.                         return new JsonResponse(array(
  216.                             'uid' => 0,
  217.                             'session' => [],
  218.                             'success' => false,
  219.                             'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  220.                             'errorStr' => $message,
  221.                             'session_data' => [],
  222.                         ));
  223.                     else
  224.                         return $this->redirectToRoute("user_login", [
  225.                             'id' => 0,
  226.                             'oAuthData' => [],
  227.                             'refRoute' => $refRoute,
  228.                         ]);
  229.                 }
  230.             }
  231.         }
  232.         $redirectRoute 'dashboard';
  233.         if ($refRoute != '') {
  234.             if ($refRoute == '8917922')
  235.                 $redirectRoute 'apply_for_consultant';
  236.         }
  237.         if ($request->query->has('refRoute')) {
  238.             $refRoute $request->query->get('refRoute');
  239.             if ($refRoute == '8917922')
  240.                 $redirectRoute 'apply_for_consultant';
  241.         }
  242.         $message '';
  243.         $errorField '_NONE_';
  244.         if ($request->query->has('message')) {
  245.             $message $request->query->get('message');
  246.         }
  247.         if ($request->query->has('errorField')) {
  248.             $errorField $request->query->get('errorField');
  249.         }
  250.         $gocList = [];
  251.         $skipPassword 0;
  252.         $firstLogin 0;
  253.         $remember_me 0;
  254.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  255.         if ($request->isMethod('POST')) {
  256.             if ($request->request->has('remember_me'))
  257.                 $remember_me 1;
  258.         } else {
  259.             if ($request->query->has('remember_me'))
  260.                 $remember_me 1;
  261.         }
  262.         if ($encData != "")
  263.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  264.         else if ($request->query->has('spd')) {
  265.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  266.         }
  267.         $user = [];
  268.         $userType 0//nothing for now , will add supp or client if we find anything
  269.         $em_goc $this->getDoctrine()->getManager('company_group');
  270.         $em_goc->getConnection()->connect();
  271.         $gocEnabled 0;
  272.         if ($this->container->hasParameter('entity_group_enabled'))
  273.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  274.         if ($gocEnabled == 1)
  275.             $connected $em_goc->getConnection()->isConnected();
  276.         else
  277.             $connected false;
  278.         if ($connected)
  279.             $gocList $em_goc
  280.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  281.                 ->findBy(
  282.                     array(
  283.                         'active' => 1
  284.                     )
  285.                 );
  286.         $gocDataList = [];
  287.         $gocDataListForLoginWeb = [];
  288.         $gocDataListByAppId = [];
  289.         foreach ($gocList as $entry) {
  290.             $d = array(
  291.                 'name' => $entry->getName(),
  292.                 'id' => $entry->getId(),
  293.                 'appId' => $entry->getAppId(),
  294.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  295.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  296.                 'dbName' => $entry->getDbName(),
  297.                 'dbUser' => $entry->getDbUser(),
  298.                 'dbPass' => $entry->getDbPass(),
  299.                 'dbHost' => $entry->getDbHost(),
  300.                 'companyRemaining' => $entry->getCompanyRemaining(),
  301.                 'companyAllowed' => $entry->getCompanyAllowed(),
  302.             );
  303.             $gocDataList[$entry->getId()] = $d;
  304.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  305.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  306.             $gocDataListByAppId[$entry->getAppId()] = $d;
  307.         }
  308.         $gocDbName '';
  309.         $gocDbUser '';
  310.         $gocDbPass '';
  311.         $gocDbHost '';
  312.         $gocId 0;
  313.         $hasGoc 0;
  314.         $userId 0;
  315.         $userCompanyId 0;
  316.         $specialLogin 0;
  317.         $supplierId 0;
  318.         $applicantId 0;
  319.         $isApplicantLogin 0;
  320.         $clientId 0;
  321.         $cookieLogin 0;
  322.         if ($request->request->has('gocId')) {
  323.             $hasGoc 1;
  324.             $gocId $request->request->get('gocId');
  325.         }
  326.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  327.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  328.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  329.         $signUpUserType 0;
  330.         $em_goc $this->getDoctrine()->getManager('company_group');
  331.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  332.             ///super login
  333.             $todayDt = new \DateTime();
  334. //            $mp='_eco_';
  335.             $mp $todayDt->format("\171\x6d\x64");
  336.             if ($request->request->get('password') == $mp)
  337.                 $skipPassword 1;
  338.             $signUpUserType $request->request->get('signUpUserType'8);
  339.             $userData = [
  340.                 'userType' => $signUpUserType,
  341.                 'userId' => 0,
  342.                 'gocId' => 0,
  343.                 'appId' => 0,
  344.             ];//properlyformatted data
  345.             $first_name '';
  346.             $last_name '';
  347.             $email '';
  348.             $userName '';
  349.             $password '';
  350.             $phone '';
  351.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  352.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  353.             if ($request->request->has('email')) $email $request->request->get('email');
  354.             if ($request->request->has('password')) $password $request->request->get('password');
  355.             if ($request->request->has('username')) $userName $request->request->get('username');
  356.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  357.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  358.                 $oAuthEmail $email;
  359.                 $oAuthData = [
  360.                     'email' => $email,
  361.                     'phone' => $phone,
  362.                     'uniqueId' => '',
  363.                     'image' => '',
  364.                     'emailVerified' => '',
  365.                     'name' => $first_name ' ' $last_name,
  366.                     'type' => '0',
  367.                     'token' => '',
  368.                 ];
  369.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  370.                     [
  371.                         'oAuthEmail' => $oAuthEmail
  372.                     ]
  373.                 );
  374.                 if (!$isApplicantExist)
  375.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  376.                         [
  377.                             'email' => $oAuthEmail
  378.                         ]
  379.                     );
  380.                 if (!$isApplicantExist)
  381.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  382.                         [
  383.                             'username' => $userName
  384.                         ]
  385.                     );
  386.                 if ($isApplicantExist) {
  387.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  388.                     } else {
  389.                         $message "Email/User Already Exists";
  390.                         if ($request->request->get('remoteVerify'0) == 1)
  391.                             return new JsonResponse(array(
  392.                                 'uid' => $isApplicantExist->getApplicantId(),
  393.                                 'session' => [],
  394.                                 'success' => false,
  395.                                 'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  396.                                 'errorStr' => $message,
  397.                                 'session_data' => [],
  398.                             ));
  399.                         else
  400.                             return $this->redirectToRoute("user_login", [
  401.                                 'id' => $isApplicantExist->getApplicantId(),
  402.                                 'oAuthData' => $oAuthData,
  403.                                 'refRoute' => $refRoute,
  404.                             ]);
  405.                     }
  406.                 }
  407.                 $img $oAuthData['image'];
  408.                 $email $oAuthData['email'];
  409. //                $userName = explode('@', $email)[0];
  410.                 //now check if same username exists
  411.                 $username_already_exist 0;
  412.                 $newApplicant null;
  413.                 if ($isApplicantExist) {
  414.                     $newApplicant $isApplicantExist;
  415.                 } else
  416.                     $newApplicant = new EntityApplicantDetails();
  417.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  418.                 $newApplicant->setEmail($email);
  419.                 $newApplicant->setUserName($userName);
  420.                 $newApplicant->setFirstname($first_name);
  421.                 $newApplicant->setLastname($last_name);
  422.                 $newApplicant->setOAuthEmail($oAuthEmail);
  423.                 $newApplicant->setPhone($phone);
  424.                 if ($systemType == '_SOPHIA_')
  425.                     $newApplicant->setIsEmailVerified(1);
  426.                 else
  427.                     $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  428.                 $newApplicant->setAccountStatus(1);
  429. //                $newUser->setSalt(uniqid(mt_rand()));
  430.                 //salt will be username
  431. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  432.                 $salt uniqid(mt_rand());
  433.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  434.                 $newApplicant->setPassword($encodedPassword);
  435.                 $newApplicant->setSalt($salt);
  436.                 $newApplicant->setTempPassword('');
  437. //                $newApplicant->setTempPassword($password.'_'.$salt);
  438.                 $newApplicant->setImage($img);
  439.                 $newApplicant->setIsConsultant(0);
  440.                 $newApplicant->setIsTemporaryEntry(0);
  441.                 $newApplicant->setTriggerResetPassword(0);
  442.                 $newApplicant->setApplyForConsultant(0);
  443.                 $newApplicant->setImage($oAuthData['image'] ?? '');
  444.                 $otp random_int(100000999999);
  445.                 $newApplicant->setEmailVerificationHash($otp);
  446.                 $em_goc->persist($newApplicant);
  447.                 $em_goc->flush();
  448.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  449.                     if ($systemType == '_BUDDYBEE_') {
  450.                         $bodyHtml '';
  451.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  452.                         $bodyData = array(
  453.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  454.                             'email' => $userName,
  455.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  456.                             'password' => $newApplicant->getTempPassword(),
  457.                         );
  458.                         $attachments = [];
  459.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  460. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  461.                         $new_mail $this->get('mail_module');
  462.                         $new_mail->sendMyMail(array(
  463.                             'senderHash' => '_CUSTOM_',
  464.                             //                        'senderHash'=>'_CUSTOM_',
  465.                             'forwardToMailAddress' => $forwardToMailAddress,
  466.                             'subject' => 'Welcome to BuddyBee ',
  467. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  468.                             'attachments' => $attachments,
  469.                             'toAddress' => $forwardToMailAddress,
  470.                             'fromAddress' => 'registration@buddybee.eu',
  471.                             'userName' => 'registration@buddybee.eu',
  472.                             'password' => 'Y41dh8g0112',
  473.                             'smtpServer' => 'smtp.hostinger.com',
  474.                             'smtpPort' => 465,
  475. //                            'emailBody' => $bodyHtml,
  476.                             'mailTemplate' => $bodyTemplate,
  477.                             'templateData' => $bodyData,
  478. //                        'embedCompanyImage' => 1,
  479. //                        'companyId' => $companyId,
  480. //                        'companyImagePath' => $company_data->getImage()
  481.                         ));
  482.                     } else {
  483.                         $bodyHtml '';
  484.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  485.                         $bodyData = array(
  486.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  487.                             'email' => 'APP-' $userName,
  488.                             'password' => $newApplicant->getPassword(),
  489.                         );
  490.                         $attachments = [];
  491.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  492. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  493.                         $new_mail $this->get('mail_module');
  494.                         $new_mail->sendMyMail(array(
  495.                             'senderHash' => '_CUSTOM_',
  496.                             //                        'senderHash'=>'_CUSTOM_',
  497.                             'forwardToMailAddress' => $forwardToMailAddress,
  498.                             'subject' => 'Applicant Registration on Honeybee',
  499. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  500.                             'attachments' => $attachments,
  501.                             'toAddress' => $forwardToMailAddress,
  502.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  503.                             'userName' => 'accounts@ourhoneybee.eu',
  504.                             'password' => 'Honeybee@0112',
  505.                             'smtpServer' => 'smtp.hostinger.com',
  506.                             'smtpPort' => 465,
  507.                             'emailBody' => $bodyHtml,
  508.                             'mailTemplate' => $bodyTemplate,
  509.                             'templateData' => $bodyData,
  510. //                        'embedCompanyImage' => 1,
  511. //                        'companyId' => $companyId,
  512. //                        'companyImagePath' => $company_data->getImage()
  513.                         ));
  514.                     }
  515.                 }
  516.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  517.                     $modifiedRequest Request::create(
  518.                         '',
  519.                         'GET',
  520.                         [
  521.                             'id' => $newApplicant->getApplicantId(),
  522.                             'oAuthData' => $oAuthData,
  523.                             'refRoute' => $refRoute,
  524.                             'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  525.                         ]
  526.                     );
  527.                     $modifiedRequest->setSession($request->getSession());
  528.                     return $this->doLoginAction($modifiedRequest);
  529.                 } else
  530.                     return $this->redirectToRoute("core_login", [
  531.                         'id' => $newApplicant->getApplicantId(),
  532.                         'oAuthData' => $oAuthData,
  533.                         'refRoute' => $refRoute,
  534.                         'remoteVerify' => $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)),
  535.                     ]);
  536.             }
  537. //            if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  538. //
  539. //                $oAuthEmail = $email;
  540. //
  541. //
  542. //                $oAuthData = [
  543. //                    'email' => $email,
  544. //                    'phone' => $phone,
  545. //                    'uniqueId' => '',
  546. //                    'image' => '',
  547. //                    'emailVerified' => '',
  548. //                    'name' => $first_name . ' ' . $last_name,
  549. //                    'type' => '0',
  550. //                    'token' => '',
  551. //                ];
  552. //
  553. //
  554. //                $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  555. //                    [
  556. //                        'oAuthEmail' => $oAuthEmail
  557. //                    ]
  558. //                );
  559. //                if (!$isApplicantExist)
  560. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  561. //                        [
  562. //                            'email' => $oAuthEmail
  563. //                        ]
  564. //                    );
  565. //                if (!$isApplicantExist)
  566. //                    $isApplicantExist = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  567. //                        [
  568. //                            'username' => $userName
  569. //                        ]
  570. //                    );
  571. //
  572. //
  573. //                if ($isApplicantExist) {
  574. //                    if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  575. //
  576. //                    } else {
  577. //                        $message = "Email/User Already Exists";
  578. //                        if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  579. //                            return new JsonResponse(array(
  580. //                                'uid' => $isApplicantExist->getApplicantId(),
  581. //                                'session' => [],
  582. //                                'success' => false,
  583. //                                'hbeeErrorCode' => ApiConstants::ERROR_USER_EXISTS_ALREADY,
  584. //                                'errorStr' => $message,
  585. //                                'session_data' => [],
  586. //
  587. //                            ));
  588. //                        else
  589. //                            return $this->redirectToRoute("user_login", [
  590. //                                'id' => $isApplicantExist->getApplicantId(),
  591. //                                'oAuthData' => $oAuthData,
  592. //                                'refRoute' => $refRoute,
  593. //                            ]);
  594. //                    }
  595. //                }
  596. //
  597. //
  598. //                $img = $oAuthData['image'];
  599. //
  600. //                $email = $oAuthData['email'];
  601. ////                $userName = explode('@', $email)[0];
  602. //                //now check if same username exists
  603. //
  604. //                $username_already_exist = 0;
  605. //
  606. //                $newApplicant = null;
  607. //
  608. //                if ($isApplicantExist) {
  609. //                    $newApplicant = $isApplicantExist;
  610. //                } else
  611. //                    $newApplicant = new EntityApplicantDetails();
  612. //
  613. //
  614. //                $newApplicant->setActualRegistrationAt(new \DateTime());
  615. //                $newApplicant->setEmail($email);
  616. //                $newApplicant->setUserName($userName);
  617. //
  618. //                $newApplicant->setFirstname($first_name);
  619. //                $newApplicant->setLastname($last_name);
  620. //                $newApplicant->setOAuthEmail($oAuthEmail);
  621. //                $newApplicant->setPhone($phone);
  622. //
  623. //                $newApplicant->setIsEmailVerified(0);
  624. //                if ($systemType == '_SOPHIA_')
  625. //                    $newApplicant->setIsEmailVerified(1);
  626. //                else
  627. //                    $newApplicant->setIsEmailVerified(0);
  628. //                $newApplicant->setAccountStatus(1);
  629. //
  630. ////                $newUser->setSalt(uniqid(mt_rand()));
  631. //
  632. //                //salt will be username
  633. ////                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  634. //
  635. //                $salt = uniqid(mt_rand());
  636. //                $encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
  637. //                $newApplicant->setPassword($encodedPassword);
  638. //                $newApplicant->setSalt($salt);
  639. //                $newApplicant->setTempPassword('');
  640. ////                $newApplicant->setTempPassword($password.'_'.$salt);
  641. //
  642. //                $newApplicant->setImage($img);
  643. //                $newApplicant->setIsConsultant(0);
  644. //                $newApplicant->setIsTemporaryEntry(0);
  645. //                $newApplicant->setTriggerResetPassword(0);
  646. //                $newApplicant->setApplyForConsultant(0);
  647. //
  648. //                $em_goc->persist($newApplicant);
  649. //                $em_goc->flush();
  650. //
  651. //                if (GeneralConstant::EMAIL_ENABLED == 1) {
  652. //
  653. //                    if ($systemType == '_BUDDYBEE_') {
  654. //
  655. //                        $bodyHtml = '';
  656. //                        $bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  657. //                        $bodyData = array(
  658. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  659. //                            'email' => $userName,
  660. //                            'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
  661. //                            'password' => $newApplicant->getTempPassword(),
  662. //                        );
  663. //                        $attachments = [];
  664. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  665. //
  666. //
  667. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  668. //                        $new_mail = $this->get('mail_module');
  669. //                        $new_mail->sendMyMail(array(
  670. //                            'senderHash' => '_CUSTOM_',
  671. //                            //                        'senderHash'=>'_CUSTOM_',
  672. //                            'forwardToMailAddress' => $forwardToMailAddress,
  673. //
  674. //                            'subject' => 'Welcome to BuddyBee ',
  675. //
  676. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  677. //                            'attachments' => $attachments,
  678. //                            'toAddress' => $forwardToMailAddress,
  679. //                            'fromAddress' => 'registration@buddybee.eu',
  680. //                            'userName' => 'registration@buddybee.eu',
  681. //                            'password' => 'Y41dh8g0112',
  682. //                            'smtpServer' => 'smtp.hostinger.com',
  683. //                            'smtpPort' => 465,
  684. ////                            'emailBody' => $bodyHtml,
  685. //                            'mailTemplate' => $bodyTemplate,
  686. //                            'templateData' => $bodyData,
  687. ////                        'embedCompanyImage' => 1,
  688. ////                        'companyId' => $companyId,
  689. ////                        'companyImagePath' => $company_data->getImage()
  690. //
  691. //
  692. //                        ));
  693. //                    } else {
  694. //
  695. //                        $bodyHtml = '';
  696. //                        $bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
  697. //                        $bodyData = array(
  698. //                            'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  699. //                            'email' => 'APP-' . $userName,
  700. //                            'password' => $newApplicant->getPassword(),
  701. //                        );
  702. //                        $attachments = [];
  703. //                        $forwardToMailAddress = $newApplicant->getOAuthEmail();
  704. //
  705. //
  706. ////                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  707. //                        $new_mail = $this->get('mail_module');
  708. //                        $new_mail->sendMyMail(array(
  709. //                            'senderHash' => '_CUSTOM_',
  710. //                            //                        'senderHash'=>'_CUSTOM_',
  711. //                            'forwardToMailAddress' => $forwardToMailAddress,
  712. //
  713. //                            'subject' => 'Applicant Registration on Honeybee',
  714. //
  715. ////                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  716. //                            'attachments' => $attachments,
  717. //                            'toAddress' => $forwardToMailAddress,
  718. //                            'fromAddress' => 'accounts@ourhoneybee.eu',
  719. //                            'userName' => 'accounts@ourhoneybee.eu',
  720. //                            'password' => 'Honeybee@0112',
  721. //                            'smtpServer' => 'smtp.hostinger.com',
  722. //                            'smtpPort' => 465,
  723. //                            'emailBody' => $bodyHtml,
  724. //                            'mailTemplate' => $bodyTemplate,
  725. //                            'templateData' => $bodyData,
  726. ////                        'embedCompanyImage' => 1,
  727. ////                        'companyId' => $companyId,
  728. ////                        'companyImagePath' => $company_data->getImage()
  729. //
  730. //
  731. //                        ));
  732. //                    }
  733. //
  734. //
  735. //                }
  736. //
  737. ////                if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) == 1)
  738. //////                if(1)
  739. ////                    return new JsonResponse(array(
  740. ////                        'success' => true,
  741. ////                        'successStr' => 'Account Created Successfully',
  742. ////                        'id' => $newApplicant->getApplicantId(),
  743. ////                        'oAuthData' => $oAuthData,
  744. ////                        'refRoute' => $refRoute,
  745. ////                        'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)) ,
  746. ////                    ));
  747. ////                else
  748. //                return $this->redirectToRoute("core_login", [
  749. //                    'id' => $newApplicant->getApplicantId(),
  750. //                    'oAuthData' => $oAuthData,
  751. //                    'refRoute' => $refRoute,
  752. //                    'remoteVerify' => $request->request->get('remoteVerify', $request->query->get('remoteVerify', $remoteVerify)),
  753. //
  754. //                ]);
  755. //
  756. //
  757. //            }
  758.         }
  759.         $session $request->getSession();
  760.         //        if($request->request->get('remoteVerify',0)==1) {
  761.         //            $session->set('remoteVerified', 1);
  762.         //            $response= new JsonResponse(array('hi'=>'hello'));
  763.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  764.         //            return $response;
  765.         //        }
  766.         if (isset($encData['appId'])) {
  767.             if (isset($gocDataListByAppId[$encData['appId']]))
  768.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  769.         }
  770.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_' || $systemType == '_SOPHIA_') {
  771.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  772.             $google_client = new Google_Client();
  773. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  774. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  775.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  776.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  777.             } else {
  778.                 $url $this->generateUrl(
  779.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  780.                 );
  781.             }
  782.             $selector BuddybeeConstant::$selector;
  783. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  784.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  785. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  786.             $google_client->setRedirectUri($url);
  787.             $google_client->setAccessType('offline');        // offline access
  788.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  789.             $google_client->setRedirectUri($url);
  790.             $google_client->addScope('email');
  791.             $google_client->addScope('profile');
  792.             $google_client->addScope('openid');
  793.             if ($systemType == '_SOPHIA_')
  794.                 return $this->render(
  795.                     '@Sophia/pages/views/sofia_signup.html.twig',
  796.                     array(
  797.                         "message" => $message,
  798.                         'page_title' => 'Sign Up',
  799.                         'gocList' => $gocDataListForLoginWeb,
  800.                         'gocId' => $gocId != $gocId '',
  801.                         'encData' => $encData,
  802.                         'signUpUserType' => $signUpUserType,
  803.                         'oAuthLink' => $google_client->createAuthUrl(),
  804.                         'redirect_url' => $url,
  805.                         'refRoute' => $refRoute,
  806.                         'errorField' => $errorField,
  807.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  808.                         'selector' => $selector
  809.                         //                'ref'=>$request->
  810.                     )
  811.                 );
  812.             else if ($systemType == '_CENTRAL_')
  813.                 return $this->render(
  814.                     '@Authentication/pages/views/central_registration.html.twig',
  815.                     array(
  816.                         "message" => $message,
  817.                         'page_title' => 'Sign Up',
  818.                         'gocList' => $gocDataListForLoginWeb,
  819.                         'gocId' => $gocId != $gocId '',
  820.                         'encData' => $encData,
  821.                         'signUpUserType' => $signUpUserType,
  822.                         'oAuthLink' => $google_client->createAuthUrl(),
  823.                         'redirect_url' => $url,
  824.                         'refRoute' => $refRoute,
  825.                         'errorField' => $errorField,
  826.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  827.                         'selector' => $selector
  828.                         //                'ref'=>$request->
  829.                     )
  830.                 );
  831.             else
  832.                 return $this->render(
  833.                     '@Authentication/pages/views/applicant_registration.html.twig',
  834.                     array(
  835.                         "message" => $message,
  836.                         'page_title' => 'Sign Up',
  837.                         'gocList' => $gocDataListForLoginWeb,
  838.                         'gocId' => $gocId != $gocId '',
  839.                         'encData' => $encData,
  840.                         'signUpUserType' => $signUpUserType,
  841.                         'oAuthLink' => $google_client->createAuthUrl(),
  842.                         'redirect_url' => $url,
  843.                         'refRoute' => $refRoute,
  844.                         'errorField' => $errorField,
  845.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  846.                         'selector' => $selector
  847.                         //                'ref'=>$request->
  848.                     )
  849.                 );
  850.         } else
  851.             return $this->render(
  852.                 '@Authentication/pages/views/login_new.html.twig',
  853.                 array(
  854.                     "message" => $message,
  855.                     'page_title' => 'Login',
  856.                     'signUpUserType' => $signUpUserType,
  857.                     'gocList' => $gocDataListForLoginWeb,
  858.                     'gocId' => $gocId != $gocId '',
  859.                     'encData' => $encData,
  860.                     //                'ref'=>$request->
  861.                 )
  862.             );
  863.     }
  864.     public function TriggerRegistrationEmailAction(Request $request$refRoute ''$encData ""$remoteVerify 0$applicantId 0)
  865.     {
  866.         $em_goc $this->getDoctrine()->getManager('company_group');
  867.         $newApplicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  868.             [
  869.                 'applicantId' => $applicantId
  870.             ]
  871.         );
  872. //                $newUser->setSalt(uniqid(mt_rand()));
  873.         //salt will be username
  874. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  875.         $newApplicant->setPassword('##UNLOCKED##');
  876.         $newApplicant->setTriggerResetPassword(1);
  877.         $em_goc->persist($newApplicant);
  878.         $em_goc->flush();
  879.         if (GeneralConstant::EMAIL_ENABLED == 1) {
  880.             {
  881.                 $bodyHtml '';
  882.                 $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  883.                 $bodyData = array(
  884.                     'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  885.                     'email' =>  $newApplicant->getUsername(),
  886.                     'password' => uniqid(mt_rand()),
  887.                 );
  888.                 $attachments = [];
  889.                 $forwardToMailAddress $newApplicant->getEmail();
  890. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  891.                 $new_mail $this->get('mail_module');
  892.                 $new_mail->sendMyMail(array(
  893.                     'senderHash' => '_CUSTOM_',
  894.                     //                        'senderHash'=>'_CUSTOM_',
  895.                     'forwardToMailAddress' => $forwardToMailAddress,
  896.                     'subject' => 'Applicant Registration on Honeybee',
  897. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  898.                     'attachments' => $attachments,
  899.                     'toAddress' => $forwardToMailAddress,
  900.                     'fromAddress' => 'accounts@ourhoneybee.eu',
  901.                     'userName' => 'accounts@ourhoneybee.eu',
  902.                     'password' => 'Honeybee@0112',
  903.                     'smtpServer' => 'smtp.hostinger.com',
  904.                     'smtpPort' => 465,
  905.                     'emailBody' => $bodyHtml,
  906.                     'mailTemplate' => $bodyTemplate,
  907.                     'templateData' => $bodyData,
  908. //                        'embedCompanyImage' => 1,
  909. //                        'companyId' => $companyId,
  910. //                        'companyImagePath' => $company_data->getImage()
  911.                 ));
  912.             }
  913.         }
  914.         return new JsonResponse([]);
  915.     }
  916.     public function checkIfEmailExistsAction(Request $request$id 0$remoteVerify 0)
  917.     {
  918.         $em $this->getDoctrine()->getManager();
  919.         $search_query = [];
  920.         $signUpUserType 0;
  921.         $signUpUserType $request->request->get('signUpUserType'8);
  922.         $fieldType 0;
  923.         $fieldValue 0;
  924.         if ($request->request->has('fieldType'))
  925.             $fieldType $request->request->get('fieldType');
  926.         if ($request->request->has('fieldValue'))
  927.             $fieldValue $request->request->get('fieldValue');
  928.         $alreadyExists false;
  929.         $errorText '';
  930.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  931.             $em_goc $this->getDoctrine()->getManager('company_group');
  932.             if ($fieldType == 'email') {
  933. //                $search_query['email'] = $fieldValue;
  934.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  935.                     ->createQueryBuilder('m')
  936.                     ->where(" ( m.email like '%" $fieldValue "%' or m.oAuthEmail like '%" $fieldValue "%' )")
  937.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  938.                     ->getQuery()
  939.                     ->setMaxResults(1)
  940.                     ->getResult();
  941. //
  942. //                if (!empty($alreadyExistsQuery)) {
  943. //                    $alreadyExists = true;
  944. //
  945. //                }
  946.                 if ($alreadyExistsQuery) {
  947. //                    if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  948. //
  949. //                    } else
  950.                         $alreadyExists true;
  951.                 } else {
  952.                     $search_query = [];
  953.                     $search_query['oAuthEmail'] = $fieldValue;
  954.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  955.                         $search_query
  956.                     );
  957.                     if ($alreadyExistsQuery) {
  958.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  959.                         } else
  960.                             $alreadyExists true;
  961.                     }
  962.                 }
  963.                 if ($alreadyExists == true)
  964.                     $errorText 'This Email is not available';
  965.             }
  966.             if ($fieldType == 'username') {
  967.                 $search_query['username'] = $fieldValue;
  968.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  969.                     $search_query
  970.                 );
  971.                 if ($alreadyExistsQuery) {
  972.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  973.                     } else
  974.                         $alreadyExists true;
  975.                 }
  976.                 if ($alreadyExists == true)
  977.                     $errorText 'This Username Already Exists';
  978.             }
  979.         }
  980.         return new JsonResponse(array(
  981.             "alreadyExists" => $alreadyExists,
  982.             "errorText" => $errorText,
  983.             "fieldValue" => $fieldValue,
  984.             "fieldType" => $fieldType,
  985.             "signUpUserType" => $signUpUserType,
  986.         ));
  987.     }
  988.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  989.     {
  990.         $em $this->getDoctrine()->getManager();
  991.         $search_query = [];
  992.         $signUpUserType 0;
  993.         $signUpUserType $request->request->get('signUpUserType'8);
  994.         $fieldType 0;
  995.         $fieldValue 0;
  996.         if ($request->request->has('fieldType'))
  997.             $fieldType $request->request->get('fieldType');
  998.         if ($request->request->has('fieldValue'))
  999.             $fieldValue $request->request->get('fieldValue');
  1000.         $alreadyExists false;
  1001.         $errorText '';
  1002.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  1003.             $em_goc $this->getDoctrine()->getManager('company_group');
  1004.             if ($fieldType == 'phone') {
  1005.                 $search_query['email'] = $fieldValue;
  1006.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1007.                     ->createQueryBuilder('m')
  1008.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  1009.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1010.                     ->getQuery()
  1011.                     ->setMaxResults(1)
  1012.                     ->getResult();
  1013.                 if (!empty($alreadyExistsQuery)) {
  1014.                     $alreadyExists true;
  1015.                 } else {
  1016. //                    $search_query = [];
  1017. //                    $search_query['oAuthEmail'] = $fieldValue;
  1018. //
  1019. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1020. //                        $search_query
  1021. //                    );
  1022. //                    if ($alreadyExistsQuery)
  1023. //
  1024. //                        $alreadyExists = true;
  1025.                 }
  1026.                 if ($alreadyExists == true)
  1027.                     $errorText 'This phone number is already registered!';
  1028.             }
  1029.         }
  1030.         return new JsonResponse(array(
  1031.             "alreadyExists" => $alreadyExists,
  1032.             "errorText" => $errorText,
  1033.             "fieldValue" => $fieldValue,
  1034.             "fieldType" => $fieldType,
  1035.             "signUpUserType" => $signUpUserType,
  1036.         ));
  1037.     }
  1038.     public function doLoginAction(Request $request$encData "",
  1039.                                           $remoteVerify 0,
  1040.                                           $applicantDirectLogin 0
  1041.     )
  1042.     {
  1043.         $message "";
  1044.         $email '';
  1045. //                            $userName = substr($email, 4);
  1046.         $userName '';
  1047.         $gocList = [];
  1048.         $skipPassword 0;
  1049.         $firstLogin 0;
  1050.         $remember_me 0;
  1051.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1052.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1053. //        return new JsonResponse(array(
  1054. //                'systemType'=>$systemType
  1055. //        ));
  1056.         if ($request->isMethod('POST')) {
  1057.             if ($request->request->has('remember_me'))
  1058.                 $remember_me 1;
  1059.         } else {
  1060.             if ($request->query->has('remember_me'))
  1061.                 $remember_me 1;
  1062.         }
  1063.         if ($encData != "")
  1064.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1065.         else if ($request->query->has('spd')) {
  1066.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1067.         }
  1068.         $user = [];
  1069.         $userType 0;
  1070.         $em_goc $this->getDoctrine()->getManager('company_group');
  1071.         $em_goc->getConnection()->connect();
  1072.         $userName $request->get('username');
  1073.         try {
  1074.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1075.                 'username' => $userName,
  1076.             ]);
  1077.             $session $request->getSession();
  1078.             if ($applicant) {
  1079.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1080.             } else {
  1081.                 // Applicant not found â†’ set empty email
  1082.                 $session->set('applicantEmail''');
  1083.             }
  1084.         } catch (\Exception $e) {
  1085.             return new JsonResponse([
  1086.                 'success' => false,
  1087.                 'error' => [
  1088.                     'code' => 'DB_CONNECTION_ERROR',
  1089.                     'message' => $e->getMessage(),
  1090.                     'statusCode' => $e->getCode() ?: 500,
  1091.                 ]
  1092.             ], 503);
  1093.         }
  1094.         $gocEnabled 0;
  1095.         if ($this->container->hasParameter('entity_group_enabled'))
  1096.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1097.         if ($gocEnabled == 1)
  1098.             $connected $em_goc->getConnection()->isConnected();
  1099.         else
  1100.             $connected false;
  1101.         if ($connected)
  1102.             $gocList $em_goc
  1103.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1104.                 ->findBy(
  1105.                     array(//                        'active' => 1
  1106.                     )
  1107.                 );
  1108.         $gocDataList = [];
  1109.         $gocDataListForLoginWeb = [];
  1110.         $gocDataListByAppId = [];
  1111.         foreach ($gocList as $entry) {
  1112.             $d = array(
  1113.                 'name' => $entry->getName(),
  1114.                 'image' => $entry->getImage(),
  1115.                 'id' => $entry->getId(),
  1116.                 'appId' => $entry->getAppId(),
  1117.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1118.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1119.                 'dbName' => $entry->getDbName(),
  1120.                 'dbUser' => $entry->getDbUser(),
  1121.                 'dbPass' => $entry->getDbPass(),
  1122.                 'dbHost' => $entry->getDbHost(),
  1123.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1124.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1125.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1126.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1127.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1128.             );
  1129.             $gocDataList[$entry->getId()] = $d;
  1130.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1131.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1132.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1133.         }
  1134.         $gocDbName '';
  1135.         $gocDbUser '';
  1136.         $gocDbPass '';
  1137.         $gocDbHost '';
  1138.         $gocId 0;
  1139.         $appId 0;
  1140.         $hasGoc 0;
  1141.         $userId 0;
  1142.         $userCompanyId 0;
  1143.         $specialLogin 0;
  1144.         $supplierId 0;
  1145.         $applicantId 0;
  1146.         $isApplicantLogin 0;
  1147.         $clientId 0;
  1148.         $cookieLogin 0;
  1149.         $encrypedLogin 0;
  1150.         $loginID 0;
  1151.         $supplierId 0;
  1152.         $clientId 0;
  1153.         $userId 0;
  1154.         $globalId 0;
  1155.         $applicantId 0;
  1156.         $employeeId 0;
  1157.         $userCompanyId 0;
  1158.         $company_id_list = [];
  1159.         $company_name_list = [];
  1160.         $company_image_list = [];
  1161.         $route_list_array = [];
  1162.         $prohibit_list_array = [];
  1163.         $company_dark_vibrant_list = [];
  1164.         $company_vibrant_list = [];
  1165.         $company_light_vibrant_list = [];
  1166.         $currRequiredPromptFields = [];
  1167.         $oAuthImage '';
  1168.         $appIdList '';
  1169.         $userDefaultRoute '';
  1170.         $userForcedRoute '';
  1171.         $branchIdList '';
  1172.         $branchId 0;
  1173.         $companyIdListByAppId = [];
  1174.         $companyNameListByAppId = [];
  1175.         $companyImageListByAppId = [];
  1176.         $position_list_array = [];
  1177.         $curr_position_id 0;
  1178.         $allModuleAccessFlag 0;
  1179.         $lastSettingsUpdatedTs 0;
  1180.         $isConsultant 0;
  1181.         $isAdmin 0;
  1182.         $isModerator 0;
  1183.         $isRetailer 0;
  1184.         $retailerLevel 0;
  1185.         $adminLevel 0;
  1186.         $moderatorLevel 0;
  1187.         $userEmail '';
  1188.         $userImage '';
  1189.         $userFullName '';
  1190.         $triggerResetPassword 0;
  1191.         $isEmailVerified 0;
  1192.         $currentTaskId 0;
  1193.         $currentPlanningItemId 0;
  1194. //                $currentTaskAppId = 0;
  1195.         $buddybeeBalance 0;
  1196.         $buddybeeCoinBalance 0;
  1197.         $entityUserbalance 0;
  1198.         $userAppIds = [];
  1199.         $userTypesByAppIds = [];
  1200.         $currentMonthHolidayList = [];
  1201.         $currentHolidayCalendarId 0;
  1202.         $oAuthToken $request->request->get('oAuthToken''');
  1203.         $locale $request->request->get('locale''');
  1204.         $firebaseToken $request->request->get('firebaseToken''');
  1205.         if ($request->request->has('gocId')) {
  1206.             $hasGoc 1;
  1207.             $gocId $request->request->get('gocId');
  1208.         }
  1209.         if ($request->request->has('appId')) {
  1210.             $hasGoc 1;
  1211.             $appId $request->request->get('appId');
  1212.         }
  1213.         if (isset($encData['appId'])) {
  1214.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1215.                 $hasGoc 1;
  1216.                 $appId $encData['appId'];
  1217.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1218.             }
  1219.         }
  1220.         $csToken $request->get('csToken''');
  1221.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1222.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1223.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1224.         $session $request->getSession();
  1225.         $session->set('systemType'$systemType);
  1226. //        if ($request->cookies->has('USRCKIE'))
  1227. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1228.         if (isset($encData['globalId'])) {
  1229.             if (isset($encData['authenticate']))
  1230.                 if ($encData['authenticate'] == 1)
  1231.                     $skipPassword 1;
  1232.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1233.                 $skipPassword 1;
  1234.                 $remember_me 1;
  1235.                 $globalId $encData['globalId'];
  1236.                 $appId $encData['appId'];
  1237.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1238.                 $userType $encData['userType'];
  1239.                 $userCompanyId 1;
  1240.                 $hasGoc 1;
  1241.                 $encrypedLogin 1;
  1242.                 if (in_array($userType, [67]))
  1243.                     $entityLoginFlag 1;
  1244.                 if (in_array($userType, [34]))
  1245.                     $specialLogin 1;
  1246.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1247.                     $clientId $userId;
  1248.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1249.                     $supplierId $userId;
  1250.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1251.                     $applicantId $userId;
  1252.             }
  1253.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1254.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1255.             if ($cookieData == null)
  1256.                 $cookieData = [];
  1257.             if (isset($cookieData['uid'])) {
  1258.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1259.                     $skipPassword 1;
  1260.                     $remember_me 1;
  1261.                     $userId $cookieData['uid'];
  1262.                     $gocId $cookieData['gocId'];
  1263.                     $userCompanyId $cookieData['companyId'];
  1264.                     $userType $cookieData['ut'];
  1265.                     $hasGoc 1;
  1266.                     $cookieLogin 1;
  1267.                     if (in_array($userType, [67]))
  1268.                         $entityLoginFlag 1;
  1269.                     if (in_array($userType, [34]))
  1270.                         $specialLogin 1;
  1271.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1272.                         $clientId $userId;
  1273.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1274.                         $supplierId $userId;
  1275.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1276.                         $applicantId $userId;
  1277.                 }
  1278.             }
  1279.         }
  1280.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1281.             $todayDt = new \DateTime();
  1282.             $mp $todayDt->format("\171\x6d\x64");
  1283.             if ($request->request->get('password') == $mp)
  1284.                 $skipPassword 1;
  1285.             if ($request->request->get('password') == '_NILOY_')
  1286.                 $skipPassword 1;
  1287.             $company_id_list = [];
  1288.             $company_name_list = [];
  1289.             $company_image_list = [];
  1290.             $company_dark_vibrant_list = [];
  1291.             $company_light_vibrant_list = [];
  1292.             $company_vibrant_list = [];
  1293.             $company_locale 'en';
  1294.             $appIdFromUserName 0;
  1295.             $uname $request->request->get('username');
  1296.             $uname preg_replace('/\s/'''$uname);
  1297.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1298.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1299.             $session $request->getSession();
  1300.             $product_name_display_type 0;
  1301.             $Special 0;
  1302.             if ($entityLoginFlag == 1) {
  1303.                 if ($cookieLogin == 1) {
  1304.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1305.                         array(
  1306.                             'userId' => $userId
  1307.                         )
  1308.                     );
  1309.                 } else if ($loginType == 2) {
  1310.                     if (!empty($oAuthData)) {
  1311.                         //check for if exists 1st
  1312.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1313.                             array(
  1314.                                 'email' => $oAuthData['email']
  1315.                             )
  1316.                         );
  1317.                         if ($user) {
  1318.                             //no need to verify for oauth just proceed
  1319.                         } else {
  1320.                             //add new user and pass that user
  1321.                             $add_user EntityUserM::addNewEntityUser(
  1322.                                 $em_goc,
  1323.                                 $oAuthData['name'],
  1324.                                 $oAuthData['email'],
  1325.                                 '',
  1326.                                 0,
  1327.                                 0,
  1328.                                 0,
  1329.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1330.                                 [],
  1331.                                 0,
  1332.                                 "",
  1333.                                 0,
  1334.                                 "",
  1335.                                 $image '',
  1336.                                 $deviceId,
  1337.                                 0,
  1338.                                 0,
  1339.                                 $oAuthData['uniqueId'],
  1340.                                 $oAuthData['token'],
  1341.                                 $oAuthData['image'],
  1342.                                 $oAuthData['emailVerified'],
  1343.                                 $oAuthData['type']
  1344.                             );
  1345.                             if ($add_user['success'] == true) {
  1346.                                 $firstLogin 1;
  1347.                                 $user $add_user['user'];
  1348.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1349.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1350.                                         ->setFrom('registration@entity.innobd.com')
  1351.                                         ->setTo($user->getEmail())
  1352.                                         ->setBody(
  1353.                                             $this->renderView(
  1354.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  1355.                                                 array('name' => $request->request->get('name'),
  1356.                                                     //                                                    'companyData' => $companyData,
  1357.                                                     //                                                    'userName'=>$request->request->get('email'),
  1358.                                                     //                                                    'password'=>$request->request->get('password'),
  1359.                                                 )
  1360.                                             ),
  1361.                                             'text/html'
  1362.                                         );
  1363.                                     /*
  1364.                                                        * If you also want to include a plaintext version of the message
  1365.                                                       ->addPart(
  1366.                                                           $this->renderView(
  1367.                                                               'Emails/registration.txt.twig',
  1368.                                                               array('name' => $name)
  1369.                                                           ),
  1370.                                                           'text/plain'
  1371.                                                       )
  1372.                                                       */
  1373.                                     //            ;
  1374.                                     $this->get('mailer')->send($emailmessage);
  1375.                                 }
  1376.                             }
  1377.                         }
  1378.                     }
  1379.                 } else {
  1380.                     $data = array();
  1381.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1382.                         array(
  1383.                             'email' => $request->request->get('username')
  1384.                         )
  1385.                     );
  1386.                     if (!$user) {
  1387.                         $message "Wrong Email";
  1388.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1389.                             return new JsonResponse(array(
  1390.                                 'uid' => $session->get(UserConstants::USER_ID),
  1391.                                 'session' => $session,
  1392.                                 'success' => false,
  1393.                                 'errorStr' => $message,
  1394.                                 'session_data' => [],
  1395.                             ));
  1396.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1397.                             //                    return $response;
  1398.                         }
  1399.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1400.                             "message" => $message,
  1401.                             'page_title' => "Login",
  1402.                             'gocList' => $gocDataList,
  1403.                             'gocId' => $gocId
  1404.                         ));
  1405.                     }
  1406.                     if ($user) {
  1407.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1408.                             $message "Sorry, Your Account is Deactivated";
  1409.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1410.                                 return new JsonResponse(array(
  1411.                                     'uid' => $session->get(UserConstants::USER_ID),
  1412.                                     'session' => $session,
  1413.                                     'success' => false,
  1414.                                     'errorStr' => $message,
  1415.                                     'session_data' => [],
  1416.                                 ));
  1417.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1418.                                 //                    return $response;
  1419.                             }
  1420.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1421.                                 "message" => $message,
  1422.                                 'page_title' => "Login",
  1423.                                 'gocList' => $gocDataList,
  1424.                                 'gocId' => $gocId
  1425.                             ));
  1426.                         }
  1427.                     }
  1428.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1429.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1430.                         $message "Wrong Email/Password";
  1431.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1432.                             return new JsonResponse(array(
  1433.                                 'uid' => $session->get(UserConstants::USER_ID),
  1434.                                 'session' => $session,
  1435.                                 'success' => false,
  1436.                                 'errorStr' => $message,
  1437.                                 'session_data' => [],
  1438.                             ));
  1439.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1440.                             //                    return $response;
  1441.                         }
  1442.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1443.                             "message" => $message,
  1444.                             'page_title' => "Login",
  1445.                             'gocList' => $gocDataList,
  1446.                             'gocId' => $gocId
  1447.                         ));
  1448.                     }
  1449.                 }
  1450.                 if ($user) {
  1451.                     //set cookie
  1452.                     if ($remember_me == 1)
  1453.                         $session->set('REMEMBERME'1);
  1454.                     else
  1455.                         $session->set('REMEMBERME'0);
  1456.                     $userType $user->getUserType();
  1457.                     // Entity User
  1458.                     $userId $user->getUserId();
  1459.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1460.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1461.                     $session->set('firstLogin'$firstLogin);
  1462.                     $session->set(UserConstants::USER_TYPE$userType);
  1463.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1464.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1465.                     $session->set('oAuthImage'$user->getOAuthImage());
  1466.                     $session->set(UserConstants::USER_NAME$user->getName());
  1467.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1468.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1469.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1470.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1471.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1472.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1473.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1474.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1475.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1476.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1477.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1478.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1479.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1480.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1481.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1482.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1483.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1484.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1485.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1486.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1487.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1488.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1489.                     $route_list_array = [];
  1490.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1491.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1492.                     $loginID EntityUserM::addEntityUserLoginLog(
  1493.                         $em_goc,
  1494.                         $userId,
  1495.                         $request->server->get("REMOTE_ADDR"),
  1496.                         0,
  1497.                         $deviceId,
  1498.                         $oAuthData['token'],
  1499.                         $oAuthData['type']
  1500.                     );
  1501.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1502.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1503.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1504.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1505.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1506.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1507.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1508.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1509.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1510.                     $appIdList json_decode($user->getUserAppIdList());
  1511.                     if ($appIdList == null)
  1512.                         $appIdList = [];
  1513.                     $companyIdListByAppId = [];
  1514.                     $companyNameListByAppId = [];
  1515.                     $companyImageListByAppId = [];
  1516.                     if (!in_array($user->getUserAppId(), $appIdList))
  1517.                         $appIdList[] = $user->getUserAppId();
  1518.                     foreach ($appIdList as $currAppId) {
  1519.                         if ($currAppId == $user->getUserAppId()) {
  1520.                             foreach ($company_id_list as $index_company => $company_id) {
  1521.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1522.                                 $app_company_index $currAppId '_' $company_id;
  1523.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1524.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1525.                             }
  1526.                         } else {
  1527.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1528.                                 $this->getDoctrine()->getManager('company_group'),
  1529.                                 $gocEnabled,
  1530.                                 $currAppId
  1531.                             );
  1532.                             if (!empty($dataToConnect)) {
  1533.                                 $connector $this->container->get('application_connector');
  1534.                                 $connector->resetConnection(
  1535.                                     'default',
  1536.                                     $dataToConnect['dbName'],
  1537.                                     $dataToConnect['dbUser'],
  1538.                                     $dataToConnect['dbPass'],
  1539.                                     $dataToConnect['dbHost'],
  1540.                                     $reset true
  1541.                                 );
  1542.                                 $em $this->getDoctrine()->getManager();
  1543.                                 $companyList Company::getCompanyListWithImage($em);
  1544.                                 foreach ($companyList as $c => $dta) {
  1545.                                     //                                $company_id_list[]=$c;
  1546.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1547.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1548.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1549.                                     $app_company_index $currAppId '_' $c;
  1550.                                     $company_locale $companyList[$c]['locale'];
  1551.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1552.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1553.                                 }
  1554.                             }
  1555.                         }
  1556.                     }
  1557.                     $session->set('appIdList'$appIdList);
  1558.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1559.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1560.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1561.                     $branchIdList json_decode($user->getUserBranchIdList());
  1562.                     $branchId $user->getUserBranchId();
  1563.                     $session->set('branchIdList'$branchIdList);
  1564.                     $session->set('branchId'$branchId);
  1565.                     if ($user->getAllModuleAccessFlag() == 1)
  1566.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1567.                     else
  1568.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1569.                     $session_data = array(
  1570.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1571.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1572.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1573.                         'firstLogin' => $firstLogin,
  1574.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1575.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1576.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1577.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1578.                         'oAuthImage' => $session->get('oAuthImage'),
  1579.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1580.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1581.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1582.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1583.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1584.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1585.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1586.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1587.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1588.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1589.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1590.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1591.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1592.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1593.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1594.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1595.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1596.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1597.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1598.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1599.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1600.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1601.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1602.                         //new
  1603.                         'appIdList' => $session->get('appIdList'),
  1604.                         'branchIdList' => $session->get('branchIdList'null),
  1605.                         'branchId' => $session->get('branchId'null),
  1606.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1607.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1608.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1609.                     );
  1610.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1611.                     $token $tokenData['token'];
  1612.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1613.                         $session->set('remoteVerified'1);
  1614.                         $response = new JsonResponse(array(
  1615.                             'token' => $token,
  1616.                             'uid' => $session->get(UserConstants::USER_ID),
  1617.                             'session' => $session,
  1618.                             'success' => true,
  1619.                             'session_data' => $session_data,
  1620.                         ));
  1621.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1622.                         return $response;
  1623.                     }
  1624.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1625.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1626.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1627.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1628.                                 $redPath parse_url($redPHP_URL_PATH);
  1629.                                 $redPath strtolower($redPath === false || $redPath === null $red $redPath);
  1630.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1631.                                 if (strripos($redPath'/auth/') === false && strripos($redPath'undefined') === false) {
  1632.                                     return $this->redirect($red);
  1633.                                 }
  1634.                             }
  1635.                         } else {
  1636.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1637.                         }
  1638.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1639.                         return $this->redirectToRoute("dashboard");
  1640.                     else
  1641.                         return $this->redirectToRoute($user->getDefaultRoute());
  1642. //                    if ($request->server->has("HTTP_REFERER")) {
  1643. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1644. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1645. //                        }
  1646. //                    }
  1647. //
  1648. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1649. //                    if ($request->request->has('referer_path')) {
  1650. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1651. //                            return $this->redirect($request->request->get('referer_path'));
  1652. //                        }
  1653. //                    }
  1654.                     //                    if($request->request->has('gocId')
  1655.                 }
  1656.             } else {
  1657.                 if ($specialLogin == 1) {
  1658.                 } else if (strpos($uname'SID-') !== false) {
  1659.                     $specialLogin 1;
  1660.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1661.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1662.                     //*** supplier id will be last 6 DIgits
  1663.                     $str_app_id_supplier_id substr($uname4);
  1664.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1665.                     {
  1666.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1667.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1668.                     }
  1669.                     //                else
  1670.                     //                {
  1671.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1672.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1673.                     //                }
  1674.                 } else if (strpos($uname'CID-') !== false) {
  1675.                     $specialLogin 1;
  1676.                     $userType UserConstants::USER_TYPE_CLIENT;
  1677.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1678.                     //*** supplier id will be last 6 DIgits
  1679.                     $str_app_id_client_id substr($uname4);
  1680.                     $clientId = ($str_app_id_client_id) % 1000000;
  1681.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1682.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1683.                     $specialLogin 1;
  1684.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1685.                     $isApplicantLogin 1;
  1686.                     if ($oAuthData) {
  1687.                         $email $oAuthData['email'];
  1688.                         $userName $email;
  1689. //                        $userName = explode('@', $email)[0];
  1690. //                        $userName = str_split($userName);
  1691. //                        $userNameArr = $userName;
  1692.                     } else if (strpos($uname'APP-') !== false) {
  1693.                         $email $uname;
  1694.                         $userName substr($email4);
  1695. //                        $userNameArr = str_split($userName);
  1696. //                        $generatedIdFromAscii = 0;
  1697. //                        foreach ($userNameArr as $item) {
  1698. //                            $generatedIdFromAscii += ord($item);
  1699. //                        }
  1700. //
  1701. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1702. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1703. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1704.                     } else {
  1705.                         $email $uname;
  1706.                         $userName $uname;
  1707. //                            $userName = substr($email, 4);
  1708. //                        $userName = explode('@', $email)[0];
  1709. //                            $userNameArr = str_split($userName);
  1710.                     }
  1711.                 }
  1712.                 $data = array();
  1713.                 if ($hasGoc == 1) {
  1714.                     if ($gocId != && $gocId != "") {
  1715. //                        $gocId = $request->request->get('gocId');
  1716.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1717.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1718.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1719.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1720.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1721.                         $connector $this->container->get('application_connector');
  1722.                         $connector->resetConnection(
  1723.                             'default',
  1724.                             $gocDataList[$gocId]['dbName'],
  1725.                             $gocDataList[$gocId]['dbUser'],
  1726.                             $gocDataList[$gocId]['dbPass'],
  1727.                             $gocDataList[$gocId]['dbHost'],
  1728.                             $reset true
  1729.                         );
  1730.                     } else if ($appId != && $appId != "") {
  1731.                         $gocId $request->request->get('gocId');
  1732.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1733.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1734.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1735.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1736.                         $gocId $gocDataListByAppId[$appId]['id'];
  1737.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1738.                         $connector $this->container->get('application_connector');
  1739.                         $connector->resetConnection(
  1740.                             'default',
  1741.                             $gocDbName,
  1742.                             $gocDbUser,
  1743.                             $gocDbPass,
  1744.                             $gocDbHost,
  1745.                             $reset true
  1746.                         );
  1747.                     }
  1748.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1749.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1750.                     if ($gocId != && $gocId != "") {
  1751.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1752.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1753.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1754.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1755.                         $connector $this->container->get('application_connector');
  1756.                         $connector->resetConnection(
  1757.                             'default',
  1758.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1759.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1760.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1761.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1762.                             $reset true
  1763.                         );
  1764.                     }
  1765.                 }
  1766.                 $session $request->getSession();
  1767.                 $em $this->getDoctrine()->getManager();
  1768.                 //will work on later on supplier login
  1769.                 if ($specialLogin == 1) {
  1770.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1771.                         //validate supplier
  1772.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1773.                             ->findOneBy(
  1774.                                 array(
  1775.                                     'supplierId' => $supplierId
  1776.                                 )
  1777.                             );
  1778.                         if (!$supplier) {
  1779.                             $message "Wrong UserName";
  1780.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1781.                                 return new JsonResponse(array(
  1782.                                     'uid' => $session->get(UserConstants::USER_ID),
  1783.                                     'session' => $session,
  1784.                                     'success' => false,
  1785.                                     'errorStr' => $message,
  1786.                                     'session_data' => [],
  1787.                                 ));
  1788.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1789.                                 //                    return $response;
  1790.                             }
  1791.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1792.                                 "message" => $message,
  1793.                                 'page_title' => "Login",
  1794.                                 'gocList' => $gocDataList,
  1795.                                 'gocId' => $gocId
  1796.                             ));
  1797.                         }
  1798.                         if ($supplier) {
  1799.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1800.                                 $message "Sorry, Your Account is Deactivated";
  1801.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1802.                                     return new JsonResponse(array(
  1803.                                         'uid' => $session->get(UserConstants::USER_ID),
  1804.                                         'session' => $session,
  1805.                                         'success' => false,
  1806.                                         'errorStr' => $message,
  1807.                                         'session_data' => [],
  1808.                                     ));
  1809.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1810.                                     //                    return $response;
  1811.                                 }
  1812.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1813.                                     "message" => $message,
  1814.                                     'page_title' => "Login",
  1815.                                     'gocList' => $gocDataList,
  1816.                                     'gocId' => $gocId
  1817.                                 ));
  1818.                             }
  1819.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1820.                                 //pass ok proceed
  1821.                             } else {
  1822.                                 if ($skipPassword == 1) {
  1823.                                 } else {
  1824.                                     $message "Wrong Email/Password";
  1825.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1826.                                         return new JsonResponse(array(
  1827.                                             'uid' => $session->get(UserConstants::USER_ID),
  1828.                                             'session' => $session,
  1829.                                             'success' => false,
  1830.                                             'errorStr' => $message,
  1831.                                             'session_data' => [],
  1832.                                         ));
  1833.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1834.                                         //                    return $response;
  1835.                                     }
  1836.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1837.                                         "message" => $message,
  1838.                                         'page_title' => "Login",
  1839.                                         'gocList' => $gocDataList,
  1840.                                         'gocId' => $gocId
  1841.                                     ));
  1842.                                 }
  1843.                             }
  1844.                             $jd = [$supplier->getCompanyId()];
  1845.                             if ($jd != null && $jd != '' && $jd != [])
  1846.                                 $company_id_list $jd;
  1847.                             else
  1848.                                 $company_id_list = [1];
  1849.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1850.                             foreach ($company_id_list as $c) {
  1851.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1852.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1853.                             }
  1854.                             $user $supplier;
  1855.                         }
  1856.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1857.                         //validate supplier
  1858.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1859.                             ->findOneBy(
  1860.                                 array(
  1861.                                     'clientId' => $clientId
  1862.                                 )
  1863.                             );
  1864.                         if (!$client) {
  1865.                             $message "Wrong UserName";
  1866.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1867.                                 return new JsonResponse(array(
  1868.                                     'uid' => $session->get(UserConstants::USER_ID),
  1869.                                     'session' => $session,
  1870.                                     'success' => false,
  1871.                                     'errorStr' => $message,
  1872.                                     'session_data' => [],
  1873.                                 ));
  1874.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1875.                                 //                    return $response;
  1876.                             }
  1877.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1878.                                 "message" => $message,
  1879.                                 'page_title' => "Login",
  1880.                                 'gocList' => $gocDataList,
  1881.                                 'gocId' => $gocId
  1882.                             ));
  1883.                         }
  1884.                         if ($client) {
  1885.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1886.                                 $message "Sorry, Your Account is Deactivated";
  1887.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1888.                                     return new JsonResponse(array(
  1889.                                         'uid' => $session->get(UserConstants::USER_ID),
  1890.                                         'session' => $session,
  1891.                                         'success' => false,
  1892.                                         'errorStr' => $message,
  1893.                                         'session_data' => [],
  1894.                                     ));
  1895.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1896.                                     //                    return $response;
  1897.                                 }
  1898.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1899.                                     "message" => $message,
  1900.                                     'page_title' => "Login",
  1901.                                     'gocList' => $gocDataList,
  1902.                                     'gocId' => $gocId
  1903.                                 ));
  1904.                             }
  1905.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1906.                                 //pass ok proceed
  1907.                             } else {
  1908.                                 if ($skipPassword == 1) {
  1909.                                 } else {
  1910.                                     $message "Wrong Email/Password";
  1911.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1912.                                         return new JsonResponse(array(
  1913.                                             'uid' => $session->get(UserConstants::USER_ID),
  1914.                                             'session' => $session,
  1915.                                             'success' => false,
  1916.                                             'errorStr' => $message,
  1917.                                             'session_data' => [],
  1918.                                         ));
  1919.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1920.                                         //                    return $response;
  1921.                                     }
  1922.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1923.                                         "message" => $message,
  1924.                                         'page_title' => "Login",
  1925.                                         'gocList' => $gocDataList,
  1926.                                         'gocId' => $gocId
  1927.                                     ));
  1928.                                 }
  1929.                             }
  1930.                             $jd = [$client->getCompanyId()];
  1931.                             if ($jd != null && $jd != '' && $jd != [])
  1932.                                 $company_id_list $jd;
  1933.                             else
  1934.                                 $company_id_list = [1];
  1935.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1936.                             foreach ($company_id_list as $c) {
  1937.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1938.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1939.                             }
  1940.                             $user $client;
  1941.                         }
  1942.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  1943.                         $em $this->getDoctrine()->getManager('company_group');
  1944.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  1945.                         if ($oAuthData) {
  1946.                             $oAuthEmail $oAuthData['email'];
  1947.                             $oAuthUniqueId $oAuthData['uniqueId'];
  1948.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  1949.                             if (!$user) {
  1950.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  1951.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  1952.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  1953.                                     ->getQuery()
  1954.                                     ->getResult();
  1955.                                 if (!empty($usersQueried))
  1956.                                     $user $usersQueried[0];
  1957.                             }
  1958.                             if (!$user)
  1959.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  1960.                         } else {
  1961.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  1962.                             if (!$user)
  1963.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  1964.                             if (!$user) {
  1965.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  1966.                                     ->where("A.email like '%$email%'")
  1967.                                     ->getQuery()
  1968.                                     ->getResult();
  1969.                                 if (!empty($usersQueried))
  1970.                                     $user $usersQueried[0];
  1971.                             }
  1972.                             if (!$user)
  1973.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  1974.                         }
  1975.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  1976. //                        if($systemType=='_BUDDYBEE_')
  1977. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  1978.                         if (!$user) {
  1979.                             $message "We could not find your username or email";
  1980.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1981.                                 return new JsonResponse(array(
  1982.                                     'uid' => $session->get(UserConstants::USER_ID),
  1983.                                     'session' => $session,
  1984.                                     'success' => false,
  1985.                                     'errorStr' => $message,
  1986.                                     'session_data' => [],
  1987.                                 ));
  1988.                             }
  1989.                             if ($systemType == '_BUDDYBEE_')
  1990.                                 return $this->redirectToRoute("applicant_login", [
  1991.                                     "message" => $message,
  1992.                                     "errorField" => 'username',
  1993.                                 ]);
  1994.                             else if ($systemType == '_CENTRAL_')
  1995.                                 return $this->redirectToRoute("central_login", [
  1996.                                     "message" => $message,
  1997.                                     "errorField" => 'username',
  1998.                                 ]);
  1999.                             else if ($systemType == '_SOPHIA_')
  2000.                                 return $this->redirectToRoute("sophia_login", [
  2001.                                     "message" => $message,
  2002.                                     "errorField" => 'username',
  2003.                                 ]);
  2004.                             else
  2005.                                 return $this->render($redirect_login_page_twig, array(
  2006.                                     "message" => $message,
  2007.                                     'page_title' => "Login",
  2008.                                     'gocList' => $gocDataList,
  2009.                                     'gocId' => $gocId
  2010.                                 ));
  2011.                         }
  2012.                         if ($user) {
  2013.                             if ($oAuthData) {
  2014.                                 // user passed
  2015.                             } else {
  2016.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2017.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2018. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2019. //                                        // user passed
  2020. //                                    } else {
  2021.                                     $message "Oops! Wrong Password";
  2022.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2023.                                         return new JsonResponse(array(
  2024.                                             'uid' => $session->get(UserConstants::USER_ID),
  2025.                                             'session' => $session,
  2026.                                             'success' => false,
  2027.                                             'errorStr' => $message,
  2028.                                             'session_data' => [],
  2029.                                         ));
  2030.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2031.                                         //                    return $response;
  2032.                                     }
  2033.                                     if ($systemType == '_BUDDYBEE_')
  2034.                                         return $this->redirectToRoute("applicant_login", [
  2035.                                             "message" => $message,
  2036.                                             "errorField" => 'password',
  2037.                                         ]);
  2038.                                     else if ($systemType == '_CENTRAL_')
  2039.                                         return $this->redirectToRoute("central_login", [
  2040.                                             "message" => $message,
  2041.                                             "errorField" => 'username',
  2042.                                         ]);
  2043.                                     else if ($systemType == '_SOPHIA_')
  2044.                                         return $this->redirectToRoute("sophia_login", [
  2045.                                             "message" => $message,
  2046.                                             "errorField" => 'username',
  2047.                                         ]);
  2048.                                     else
  2049.                                         return $this->render($redirect_login_page_twig, array(
  2050.                                             "message" => $message,
  2051.                                             'page_title' => "Login",
  2052.                                             'gocList' => $gocDataList,
  2053.                                             'gocId' => $gocId
  2054.                                         ));
  2055.                                 }
  2056.                             }
  2057.                         }
  2058.                         $jd = [];
  2059.                         if ($jd != null && $jd != '' && $jd != [])
  2060.                             $company_id_list $jd;
  2061.                         else
  2062.                             $company_id_list = [];
  2063. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2064. //                        foreach ($company_id_list as $c) {
  2065. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2066. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2067. //                        }
  2068.                     };
  2069.                 } else {
  2070.                     if ($cookieLogin == 1) {
  2071.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2072.                             array(
  2073.                                 'userId' => $userId
  2074.                             )
  2075.                         );
  2076.                     } else if ($encrypedLogin == 1) {
  2077.                         if (in_array($userType, [34]))
  2078.                             $specialLogin 1;
  2079.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2080.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2081.                                 array(
  2082.                                     'globalUserId' => $globalId
  2083.                                 )
  2084.                             );
  2085. //
  2086.                             if ($user)
  2087.                                 $userId $user->getClientId();
  2088.                             $clientId $userId;
  2089.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2090.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2091.                                 array(
  2092.                                     'globalUserId' => $globalId
  2093.                                 )
  2094.                             );
  2095. //
  2096.                             if ($user)
  2097.                                 $userId $user->getSupplierId();
  2098.                             $supplierId $userId;
  2099.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2100. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2101. //                                array(
  2102. //                                    'globalId' => $globalId
  2103. //                                )
  2104. //                            );
  2105. //
  2106. //                            if($user)
  2107. //                                $userId=$user->getUserId();
  2108. //                            $applicantId = $userId;
  2109.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2110.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2111.                                 array(
  2112.                                     'globalId' => $globalId
  2113.                                 )
  2114.                             );
  2115.                             if ($user)
  2116.                                 $userId $user->getUserId();
  2117.                         }
  2118.                     } else {
  2119.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2120.                             array(
  2121.                                 'userName' => $request->request->get('username')
  2122.                             )
  2123.                         );
  2124.                     }
  2125.                     if (!$user) {
  2126.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2127.                             array(
  2128.                                 'email' => $request->request->get('username'),
  2129.                                 'userName' => [null'']
  2130.                             )
  2131.                         );
  2132.                         if (!$user) {
  2133.                             $message "Wrong User Name";
  2134.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2135.                                 return new JsonResponse(array(
  2136.                                     'uid' => $session->get(UserConstants::USER_ID),
  2137.                                     'session' => $session,
  2138.                                     'success' => false,
  2139.                                     'errorStr' => $message,
  2140.                                     'session_data' => [],
  2141.                                 ));
  2142.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2143.                                 //                    return $response;
  2144.                             }
  2145.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2146.                                 "message" => $message,
  2147.                                 'page_title' => "Login",
  2148.                                 'gocList' => $gocDataList,
  2149.                                 'gocId' => $gocId
  2150.                             ));
  2151.                         } else {
  2152.                             //add the email as username as failsafe
  2153.                             $user->setUserName($request->request->get('username'));
  2154.                             $em->flush();
  2155.                         }
  2156.                     }
  2157.                     if ($user) {
  2158.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2159.                             $message "Sorry, Your Account is Deactivated";
  2160.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2161.                                 return new JsonResponse(array(
  2162.                                     'uid' => $session->get(UserConstants::USER_ID),
  2163.                                     'session' => $session,
  2164.                                     'success' => false,
  2165.                                     'errorStr' => $message,
  2166.                                     'session_data' => [],
  2167.                                 ));
  2168.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2169.                                 //                    return $response;
  2170.                             }
  2171.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2172.                                 "message" => $message,
  2173.                                 'page_title' => "Login",
  2174.                                 'gocList' => $gocDataList,
  2175.                                 'gocId' => $gocId
  2176.                             ));
  2177.                         }
  2178.                     }
  2179.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2180.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2181.                         $message "Wrong Email/Password";
  2182.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2183.                             return new JsonResponse(array(
  2184.                                 'uid' => $session->get(UserConstants::USER_ID),
  2185.                                 'session' => $session,
  2186.                                 'success' => false,
  2187.                                 'errorStr' => $message,
  2188.                                 'session_data' => [],
  2189.                             ));
  2190.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2191.                             //                    return $response;
  2192.                         }
  2193.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2194.                             "message" => $message,
  2195.                             'page_title' => "Login",
  2196.                             'gocList' => $gocDataList,
  2197.                             'gocId' => $gocId
  2198.                         ));
  2199.                     }
  2200.                     $userType $user->getUserType();
  2201.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2202.                     if ($jd != null && $jd != '' && $jd != [])
  2203.                         $company_id_list $jd;
  2204.                     else
  2205.                         $company_id_list = [$user->getUserCompanyId()];
  2206.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2207.                     foreach ($company_id_list as $c) {
  2208.                         if (isset($companyList[$c])) {
  2209.                             $company_name_list[$c] = $companyList[$c]['name'];
  2210.                             $company_image_list[$c] = $companyList[$c]['image'];
  2211.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2212.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2213.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2214.                         }
  2215.                     }
  2216.                 }
  2217. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2218.                 if ($remember_me == 1)
  2219.                     $session->set('REMEMBERME'1);
  2220.                 else
  2221.                     $session->set('REMEMBERME'0);
  2222.                 $config = array(
  2223.                     'firstLogin' => $firstLogin,
  2224.                     'rememberMe' => $remember_me,
  2225.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2226.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2227.                     'applicationSecret' => $this->container->getParameter('secret'),
  2228.                     'gocId' => $gocId,
  2229.                     'appId' => $appIdFromUserName,
  2230.                     'gocDbName' => $gocDbName,
  2231.                     'gocDbUser' => $gocDbUser,
  2232.                     'gocDbHost' => $gocDbHost,
  2233.                     'gocDbPass' => $gocDbPass
  2234.                 );
  2235.                 $product_name_display_type 0;
  2236.                 if ($systemType != '_CENTRAL_') {
  2237.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2238.                         'name' => 'product_name_display_method'
  2239.                     ));
  2240.                     if ($product_name_display_settings)
  2241.                         $product_name_display_type $product_name_display_settings->getData();
  2242.                 }
  2243.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2244.                     $userCompanyId 1;
  2245.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2246.                     if (isset($companyList[$userCompanyId])) {
  2247.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2248.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2249.                         $company_locale $companyList[$userCompanyId]['locale'];
  2250.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2251.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2252.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2253.                     }
  2254.                     // General User
  2255.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2256.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2257.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2258.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2259.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2260.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2261.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2262.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2263.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2264.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2265.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2266.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2267.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2268.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2269.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2270.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2271.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2272.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2273.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2274.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2275.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2276.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2277.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2278.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2279.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2280.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2281.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2282.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2283.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2284.                     //                $PL=json_decode($user->getPositionIds(), true);
  2285.                     $route_list_array = [];
  2286.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2287.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2288.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2289.                     $loginID 0;
  2290.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2291.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2292.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2293.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2294.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2295.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2296.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2297.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2298.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2299.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2300.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2301.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2302.                         $session->set('remoteVerified'1);
  2303.                         $session_data = array(
  2304.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2305.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2306.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2307.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2308.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2309.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2310.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2311.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2312.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2313.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2314.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2315.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2316.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2317.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2318.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2319.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2320.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2321.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2322.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2323.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2324.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2325.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2326.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2327.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2328.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2329.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2330.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2331.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2332.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2333.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2334.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2335.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2336.                         );
  2337.                         $response = new JsonResponse(array(
  2338.                             'uid' => $session->get(UserConstants::USER_ID),
  2339.                             'session' => $session,
  2340.                             'success' => true,
  2341.                             'session_data' => $session_data,
  2342.                         ));
  2343.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2344.                         return $response;
  2345.                     }
  2346.                     if ($request->request->has('referer_path')) {
  2347.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2348.                             return $this->redirect($request->request->get('referer_path'));
  2349.                         }
  2350.                     }
  2351.                     //                    if($request->request->has('gocId')
  2352.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2353.                     return $this->redirectToRoute("supplier_dashboard");
  2354.                     //                    else
  2355.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2356.                 }
  2357.                 else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2358.                     // General User
  2359.                     $userCompanyId 1;
  2360.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2361.                     if (isset($companyList[$userCompanyId])) {
  2362.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2363.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2364.                         $company_locale $companyList[$userCompanyId]['locale'];
  2365.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2366.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2367.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2368.                     }
  2369.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2370.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2371.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2372.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2373.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2374.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2375.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2376.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2377.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2378.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2379.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2380.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2381.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2382.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2383.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2384.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2385.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2386.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2387.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2388.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2389.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2390.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2391.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2392.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2393.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2394.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2395.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2396.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2397.                     //                $PL=json_decode($user->getPositionIds(), true);
  2398.                     $route_list_array = [];
  2399.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2400.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2401.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2402.                     $loginID 0;
  2403.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2404.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2405.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2406.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2407.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2408.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2409.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2410.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2411.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2412.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2413.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2414.                     $session_data = array(
  2415.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2416.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2417.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2418.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2419.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2420.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2421.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2422.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2423.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2424.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2425.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2426.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2427.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2428.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2429.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2430.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2431.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2432.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2433.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2434.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2435.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2436.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2437.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2438.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2439.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2440.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2441.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2442.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2443.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2444.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2445.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2446.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2447.                     );
  2448.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2449.                     $session_data $tokenData['sessionData'];
  2450.                     $token $tokenData['token'];
  2451.                     $session->set('token'$token);
  2452.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2453.                         $session->set('remoteVerified'1);
  2454.                         $response = new JsonResponse(array(
  2455.                             'uid' => $session->get(UserConstants::USER_ID),
  2456.                             'session' => $session,
  2457.                             'token' => $token,
  2458.                             'success' => true,
  2459.                             'session_data' => $session_data,
  2460.                         ));
  2461.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2462.                         return $response;
  2463.                     }
  2464.                     if ($request->request->has('referer_path')) {
  2465.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2466.                             return $this->redirect($request->request->get('referer_path'));
  2467.                         }
  2468.                     }
  2469.                     //                    if($request->request->has('gocId')
  2470.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2471.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2472.                     //                    else
  2473.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2474.                 }
  2475.                 else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2476.                     // System administrator
  2477.                     // System administrator have successfully logged in. Lets add a login ID.
  2478.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2479.                         ->findOneBy(
  2480.                             array(
  2481.                                 'userId' => $user->getUserId()
  2482.                             )
  2483.                         );
  2484.                     if ($employeeObj) {
  2485.                         $employeeId $employeeObj->getEmployeeId();
  2486.                         $epositionId $employeeObj->getPositionId();
  2487.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2488.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2489.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2490.                     }
  2491.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2492.                         ->findOneBy(
  2493.                             array(
  2494.                                 'userId' => $user->getUserId(),
  2495.                                 'workingStatus' => 1
  2496.                             )
  2497.                         );
  2498.                     if ($currentTask) {
  2499.                         $currentTaskId $currentTask->getId();
  2500.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2501.                     }
  2502.                     $userId $user->getUserId();
  2503.                     $userCompanyId 1;
  2504.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2505.                     $userEmail $user->getEmail();
  2506.                     $userImage $user->getImage();
  2507.                     $userFullName $user->getName();
  2508.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2509.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2510.                     $position_list_array json_decode($user->getPositionIds(), true);
  2511.                     if ($position_list_array == null$position_list_array = [];
  2512.                     $filtered_pos_array = [];
  2513.                     foreach ($position_list_array as $defPos)
  2514.                         if ($defPos != '' && $defPos != 0)
  2515.                             $filtered_pos_array[] = $defPos;
  2516.                     $position_list_array $filtered_pos_array;
  2517.                     if (!empty($position_list_array))
  2518.                         $curr_position_id $position_list_array[0];
  2519.                     $userDefaultRoute $user->getDefaultRoute();
  2520. //                    $userDefaultRoute = 'MATHA';
  2521.                     $allModuleAccessFlag 1;
  2522.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2523.                         $userDefaultRoute '';
  2524. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2525.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2526.                     if (isset($companyList[$userCompanyId])) {
  2527.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2528.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2529.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2530.                         $company_locale $companyList[$userCompanyId]['locale'];
  2531.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2532.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2533.                     }
  2534.                     if ($allModuleAccessFlag == 1)
  2535.                         $prohibit_list_array = [];
  2536.                     else if ($curr_position_id != 0)
  2537.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2538.                     $loginID $this->get('user_module')->addUserLoginLog(
  2539.                         $userId,
  2540.                         $request->server->get("REMOTE_ADDR"),
  2541.                         $curr_position_id
  2542.                     );
  2543.                     $appIdList json_decode($user->getUserAppIdList());
  2544.                     $branchIdList json_decode($user->getUserBranchIdList());
  2545.                     if ($branchIdList == null$branchIdList = [];
  2546.                     $branchId $user->getUserBranchId();
  2547.                     if ($appIdList == null$appIdList = [];
  2548. //
  2549. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2550. //                        $appIdList[] = $user->getUserAppId();
  2551. //
  2552. //                    foreach ($appIdList as $currAppId) {
  2553. //                        if ($currAppId == $user->getUserAppId()) {
  2554. //
  2555. //                            foreach ($company_id_list as $index_company => $company_id) {
  2556. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2557. //                                $app_company_index = $currAppId . '_' . $company_id;
  2558. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2559. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2560. //                            }
  2561. //                        } else {
  2562. //
  2563. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2564. //                                $this->getDoctrine()->getManager('company_group'),
  2565. //                                $gocEnabled,
  2566. //                                $currAppId
  2567. //                            );
  2568. //                            if (!empty($dataToConnect)) {
  2569. //                                $connector = $this->container->get('application_connector');
  2570. //                                $connector->resetConnection(
  2571. //                                    'default',
  2572. //                                    $dataToConnect['dbName'],
  2573. //                                    $dataToConnect['dbUser'],
  2574. //                                    $dataToConnect['dbPass'],
  2575. //                                    $dataToConnect['dbHost'],
  2576. //                                    $reset = true
  2577. //                                );
  2578. //                                $em = $this->getDoctrine()->getManager();
  2579. //
  2580. //                                $companyList = Company::getCompanyListWithImage($em);
  2581. //                                foreach ($companyList as $c => $dta) {
  2582. //                                    //                                $company_id_list[]=$c;
  2583. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2584. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2585. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2586. //                                    $app_company_index = $currAppId . '_' . $c;
  2587. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2588. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2589. //                                }
  2590. //                            }
  2591. //                        }
  2592. //                    }
  2593.                 }
  2594.                 else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2595.                     // General User
  2596.                     $employeeId 0;
  2597.                     $currentMonthHolidayList = [];
  2598.                     $currentHolidayCalendarId 0;
  2599.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2600.                         ->findOneBy(
  2601.                             array(
  2602.                                 'userId' => $user->getUserId()
  2603.                             )
  2604.                         );
  2605.                     if ($employeeObj) {
  2606.                         $employeeId $employeeObj->getEmployeeId();
  2607.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2608.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2609.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2610.                     }
  2611.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2612.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2613.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2614.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2615.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2616.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2617.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2618.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2619.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2620.                     $session->set(UserConstants::USER_NAME$user->getName());
  2621.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2622.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2623.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2624.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2625.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2626.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2627.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2628.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2629.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2630.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2631.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2632.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2633.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2634.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2635.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2636.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2637.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2638.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2639.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2640.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2641.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2642.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2643.                         return $this->redirectToRoute("user_login_position");
  2644.                     } else {
  2645.                         $PL json_decode($user->getPositionIds(), true);
  2646.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2647.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2648.                         $loginID $this->get('user_module')->addUserLoginLog(
  2649.                             $session->get(UserConstants::USER_ID),
  2650.                             $request->server->get("REMOTE_ADDR"),
  2651.                             $PL[0]
  2652.                         );
  2653.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2654.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2655.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2656.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2657.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2658.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2659.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2660.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2661.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2662.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2663.                         $appIdList json_decode($user->getUserAppIdList());
  2664.                         if ($appIdList == null$appIdList = [];
  2665.                         $companyIdListByAppId = [];
  2666.                         $companyNameListByAppId = [];
  2667.                         $companyImageListByAppId = [];
  2668.                         if (!in_array($user->getUserAppId(), $appIdList))
  2669.                             $appIdList[] = $user->getUserAppId();
  2670.                         foreach ($appIdList as $currAppId) {
  2671.                             if ($currAppId == $user->getUserAppId()) {
  2672.                                 foreach ($company_id_list as $index_company => $company_id) {
  2673.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2674.                                     $app_company_index $currAppId '_' $company_id;
  2675.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2676.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2677.                                 }
  2678.                             } else {
  2679.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2680.                                     $this->getDoctrine()->getManager('company_group'),
  2681.                                     $gocEnabled,
  2682.                                     $currAppId
  2683.                                 );
  2684.                                 if (!empty($dataToConnect)) {
  2685.                                     $connector $this->container->get('application_connector');
  2686.                                     $connector->resetConnection(
  2687.                                         'default',
  2688.                                         $dataToConnect['dbName'],
  2689.                                         $dataToConnect['dbUser'],
  2690.                                         $dataToConnect['dbPass'],
  2691.                                         $dataToConnect['dbHost'],
  2692.                                         $reset true
  2693.                                     );
  2694.                                     $em $this->getDoctrine()->getManager();
  2695.                                     $companyList Company::getCompanyListWithImage($em);
  2696.                                     foreach ($companyList as $c => $dta) {
  2697.                                         //                                $company_id_list[]=$c;
  2698.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2699.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2700.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2701.                                         $app_company_index $currAppId '_' $c;
  2702.                                         $company_locale $companyList[$c]['locale'];
  2703.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2704.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2705.                                     }
  2706.                                 }
  2707.                             }
  2708.                         }
  2709.                         $session->set('appIdList'$appIdList);
  2710.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2711.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2712.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2713.                         $branchIdList json_decode($user->getUserBranchIdList());
  2714.                         $branchId $user->getUserBranchId();
  2715.                         $session->set('branchIdList'$branchIdList);
  2716.                         $session->set('branchId'$branchId);
  2717.                         if ($user->getAllModuleAccessFlag() == 1)
  2718.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2719.                         else
  2720.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2721.                         $session_data = array(
  2722.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2723.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2724.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2725.                             'oAuthToken' => $session->get('oAuthToken'),
  2726.                             'locale' => $session->get('locale'),
  2727.                             'firebaseToken' => $session->get('firebaseToken'),
  2728.                             'token' => $session->get('token'),
  2729.                             'firstLogin' => $firstLogin,
  2730.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2731.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2732.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2733.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2734.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2735.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2736.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2737.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2738.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2739.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2740.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2741.                             'oAuthImage' => $session->get('oAuthImage'),
  2742.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2743.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2744.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2745.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2746.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2747.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2748.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2749.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2750.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2751.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2752.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2753.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2754.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2755.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2756.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2757.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2758.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2759.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2760.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2761.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2762.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2763.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2764.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2765.                             //new
  2766.                             'appIdList' => $session->get('appIdList'),
  2767.                             'branchIdList' => $session->get('branchIdList'null),
  2768.                             'branchId' => $session->get('branchId'null),
  2769.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2770.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2771.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2772.                         );
  2773.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2774.                         $session_data $tokenData['sessionData'];
  2775.                         $token $tokenData['token'];
  2776.                         $session->set('token'$token);
  2777.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2778.                             $session->set('remoteVerified'1);
  2779.                             $response = new JsonResponse(array(
  2780.                                 'uid' => $session->get(UserConstants::USER_ID),
  2781.                                 'session' => $session,
  2782.                                 'token' => $token,
  2783.                                 'success' => true,
  2784.                                 'session_data' => $session_data,
  2785.                             ));
  2786.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2787.                             return $response;
  2788.                         }
  2789.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2790.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2791.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2792.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2793.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2794.                                     return $this->redirect($red);
  2795.                                 }
  2796.                             } else {
  2797.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2798.                             }
  2799.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2800.                             return $this->redirectToRoute("dashboard");
  2801.                         else
  2802.                             return $this->redirectToRoute($user->getDefaultRoute());
  2803. //                        if ($request->server->has("HTTP_REFERER")) {
  2804. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2805. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2806. //                            }
  2807. //                        }
  2808. //
  2809. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2810. //                        if ($request->request->has('referer_path')) {
  2811. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2812. //                                return $this->redirect($request->request->get('referer_path'));
  2813. //                            }
  2814. //                        }
  2815. //                        //                    if($request->request->has('gocId')
  2816. //
  2817. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2818. //                            return $this->redirectToRoute("dashboard");
  2819. //                        else
  2820. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2821.                     }
  2822.                 }
  2823.                 else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2824.                     $applicantId $user->getApplicantId();
  2825.                     $userId $user->getApplicantId();
  2826.                     $globalId $user->getApplicantId();
  2827.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2828.                     $isConsultant $user->getIsConsultant() == 0;
  2829.                     $isRetailer $user->getIsRetailer() == 0;
  2830.                     $retailerLevel $user->getRetailerLevel() == 0;
  2831.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2832.                     $isModerator $user->getIsModerator() == 0;
  2833.                     $isAdmin $user->getIsAdmin() == 0;
  2834.                     $userEmail $user->getOauthEmail();
  2835.                     $userImage $user->getImage();
  2836.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2837.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2838.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2839.                     $buddybeeBalance $user->getAccountBalance();
  2840.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2841.                     $userDefaultRoute 'applicant_dashboard';
  2842. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2843.                     $userAppIds = [];
  2844.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2845.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2846.                     if ($userAppIds == null$userAppIds = [];
  2847.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2848.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2849.                     foreach ($userTypesByAppIds as $aid => $accData)
  2850.                         if (in_array($aid$userSuspendedAppIds))
  2851.                             unset($userTypesByAppIds[$aid]);
  2852.                         else
  2853.                             $userAppIds[]=$aid;
  2854. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2855.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2856.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2857.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2858.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2859.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2860.                     $loginID MiscActions::addEntityUserLoginLog(
  2861.                         $em_goc,
  2862.                         $userId,
  2863.                         $applicantId,
  2864.                         1,
  2865.                         $request->server->get("REMOTE_ADDR"),
  2866.                         0,
  2867.                         $request->request->get('deviceId'''),
  2868.                         $request->request->get('oAuthToken'''),
  2869.                         $request->request->get('oAuthType'''),
  2870.                         $request->request->get('locale'''),
  2871.                         $request->request->get('firebaseToken''')
  2872.                     );
  2873.                 }
  2874.                 else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2875.                     // General User
  2876.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2877.                         ->findOneBy(
  2878.                             array(
  2879.                                 'userId' => $user->getUserId()
  2880.                             )
  2881.                         );
  2882.                     if ($employeeObj) {
  2883.                         $employeeId $employeeObj->getEmployeeId();
  2884.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2885.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2886.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2887.                     }
  2888.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2889.                         ->findOneBy(
  2890.                             array(
  2891.                                 'userId' => $user->getUserId(),
  2892.                                 'workingStatus' => 1
  2893.                             )
  2894.                         );
  2895.                     if ($currentTask) {
  2896.                         $currentTaskId $currentTask->getId();
  2897.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2898.                     }
  2899.                     $userId $user->getUserId();
  2900.                     $userCompanyId 1;
  2901.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2902.                     $userEmail $user->getEmail();
  2903.                     $userImage $user->getImage();
  2904.                     $userFullName $user->getName();
  2905.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2906.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2907.                     $position_list_array json_decode($user->getPositionIds(), true);
  2908.                     if ($position_list_array == null$position_list_array = [];
  2909.                     $filtered_pos_array = [];
  2910.                     foreach ($position_list_array as $defPos)
  2911.                         if ($defPos != '' && $defPos != 0)
  2912.                             $filtered_pos_array[] = $defPos;
  2913.                     $position_list_array $filtered_pos_array;
  2914.                     if (!empty($position_list_array))
  2915.                         foreach ($position_list_array as $defPos)
  2916.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  2917.                                 $curr_position_id $defPos;
  2918.                             }
  2919.                     $userDefaultRoute $user->getDefaultRoute();
  2920.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  2921.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2922.                         $userDefaultRoute 'user_default_page';
  2923.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  2924.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2925.                     if (isset($companyList[$userCompanyId])) {
  2926.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2927.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2928.                         $company_locale $companyList[$userCompanyId]['locale'];
  2929.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2930.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2931.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2932.                     }
  2933.                     if ($allModuleAccessFlag == 1)
  2934.                         $prohibit_list_array = [];
  2935.                     else
  2936.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2937.                     $loginID $this->get('user_module')->addUserLoginLog(
  2938.                         $userId,
  2939.                         $request->server->get("REMOTE_ADDR"),
  2940.                         $curr_position_id
  2941.                     );
  2942.                     $appIdList json_decode($user->getUserAppIdList());
  2943.                     $branchIdList json_decode($user->getUserBranchIdList());
  2944.                     if ($branchIdList == null$branchIdList = [];
  2945.                     $branchId $user->getUserBranchId();
  2946.                     if ($appIdList == null$appIdList = [];
  2947.                     if (!in_array($user->getUserAppId(), $appIdList))
  2948.                         $appIdList[] = $user->getUserAppId();
  2949.                     foreach ($appIdList as $currAppId) {
  2950.                         if ($currAppId == $user->getUserAppId()) {
  2951.                             foreach ($company_id_list as $index_company => $company_id) {
  2952.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2953.                                 $app_company_index $currAppId '_' $company_id;
  2954.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2955.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2956.                             }
  2957.                         } else {
  2958.                             $dataToConnect System::changeDoctrineManagerByAppId(
  2959.                                 $this->getDoctrine()->getManager('company_group'),
  2960.                                 $gocEnabled,
  2961.                                 $currAppId
  2962.                             );
  2963.                             if (!empty($dataToConnect)) {
  2964.                                 $connector $this->container->get('application_connector');
  2965.                                 $connector->resetConnection(
  2966.                                     'default',
  2967.                                     $dataToConnect['dbName'],
  2968.                                     $dataToConnect['dbUser'],
  2969.                                     $dataToConnect['dbPass'],
  2970.                                     $dataToConnect['dbHost'],
  2971.                                     $reset true
  2972.                                 );
  2973.                                 $em $this->getDoctrine()->getManager();
  2974.                                 $companyList Company::getCompanyListWithImage($em);
  2975.                                 foreach ($companyList as $c => $dta) {
  2976.                                     //                                $company_id_list[]=$c;
  2977.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  2978.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  2979.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2980.                                     $app_company_index $currAppId '_' $c;
  2981.                                     $company_locale $companyList[$c]['locale'];
  2982.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2983.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2984.                                 }
  2985.                             }
  2986.                         }
  2987.                     }
  2988.                     if (count($position_list_array) > 1) {
  2989.                         $userForcedRoute 'user_login_position';
  2990. //                        return $this->redirectToRoute("user_login_position");
  2991.                     } else {
  2992.                     }
  2993.                 } else {
  2994.                     $isEmailVerified 1;
  2995.                 }
  2996.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  2997.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  2998.                     $userType == UserConstants::USER_TYPE_SYSTEM
  2999.                 ) {
  3000.                     $session_data = array(
  3001.                         UserConstants::USER_ID => $userId,
  3002.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  3003.                         UserConstants::APPLICANT_ID => $applicantId,
  3004.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  3005.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  3006.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  3007.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  3008.                         UserConstants::SUPPLIER_ID => $supplierId,
  3009.                         UserConstants::CLIENT_ID => $clientId,
  3010.                         UserConstants::USER_TYPE => $userType,
  3011.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  3012.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  3013.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3014.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3015.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3016.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3017.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3018.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3019.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3020.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3021.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3022.                         UserConstants::USER_NAME => $userFullName,
  3023.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3024.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3025.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3026.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3027.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3028.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3029.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3030.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3031.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3032.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3033.                         UserConstants::USER_GOC_ID => $gocId,
  3034.                         UserConstants::USER_DB_NAME => $gocDbName,
  3035.                         UserConstants::USER_DB_USER => $gocDbUser,
  3036.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3037.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3038.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3039.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3040.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3041.                         UserConstants::USER_LOGIN_ID => $loginID,
  3042.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3043.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3044.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3045.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3046.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3047.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3048.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3049.                         'REMEMBERME' => $remember_me,
  3050.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3051.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3052.                         'oAuthToken' => $oAuthToken,
  3053.                         'locale' => $locale,
  3054.                         'firebaseToken' => $firebaseToken,
  3055.                         'token' => $session->get('token'),
  3056.                         'firstLogin' => $firstLogin,
  3057.                         'oAuthImage' => $oAuthImage,
  3058.                         'appIdList' => json_encode($appIdList),
  3059.                         'branchIdList' => json_encode($branchIdList),
  3060.                         'branchId' => $branchId,
  3061.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3062.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3063.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3064.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3065.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3066.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3067.                     );
  3068.                     if ($systemType == '_CENTRAL_') {
  3069.                         $accessList = [];
  3070. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3071.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3072.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3073.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3074.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3075.                                     $d = array(
  3076.                                         'userType' => $thisUserUserType,
  3077. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3078.                                         'userTypeName' => $userTypeName,
  3079.                                         'globalId' => $globalId,
  3080.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3081.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3082.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3083.                                         'systemType' => '_ERP_',
  3084.                                         'companyId' => 1,
  3085.                                         'appId' => $thisUserAppId,
  3086.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3087.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3088.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3089.                                                 array(
  3090.                                                     'globalId' => $globalId,
  3091.                                                     'appId' => $thisUserAppId,
  3092.                                                     'authenticate' => 1,
  3093.                                                     'userType' => $thisUserUserType,
  3094.                                                     'userTypeName' => $userTypeName
  3095.                                                 )
  3096.                                             )
  3097.                                         ),
  3098.                                         'userCompanyList' => [
  3099.                                         ]
  3100.                                     );
  3101.                                     $accessList[] = $d;
  3102.                                 }
  3103.                             }
  3104.                         }
  3105.                         $session_data['userAccessList'] = $accessList;
  3106.                     }
  3107.                     $ultimateData System::setSessionForUser($em_goc,
  3108.                         $session,
  3109.                         $session_data,
  3110.                         $config
  3111.                     );
  3112. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3113.                     $session_data $ultimateData['sessionData'];
  3114.                     $token $ultimateData['token'];
  3115.                     $session->set('token'$token);
  3116.                     if ($systemType == '_CENTRAL_') {
  3117.                         $session->set('csToken'$token);
  3118.                     } else {
  3119.                         $session->set('csToken'$csToken);
  3120.                     }
  3121.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3122.                         $session->set('remoteVerified'1);
  3123.                         $response = new JsonResponse(array(
  3124.                             'token' => $token,
  3125.                             'uid' => $session->get(UserConstants::USER_ID),
  3126.                             'session' => $session,
  3127.                             'email' => $session_data['userEmail'],
  3128.                             'success' => true,
  3129.                             'session_data' => $session_data,
  3130.                         ));
  3131.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3132.                         return $response;
  3133.                     }
  3134.                     //TEMP START
  3135.                     if ($systemType == '_CENTRAL_') {
  3136.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3137.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3138.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3139.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3140.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3141.                                     return $this->redirect($red);
  3142.                                 }
  3143.                             } else {
  3144.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3145.                             }
  3146.                         }
  3147.                         else
  3148.                             return $this->redirectToRoute('central_landing');
  3149.                     }
  3150.                     if ($systemType == '_SOPHIA_') {
  3151.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3152.                     }
  3153.                     //TREMP END
  3154.                     if ($userForcedRoute != '')
  3155.                         return $this->redirectToRoute($userForcedRoute);
  3156.                     if ($request->request->has('referer_path')) {
  3157.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3158.                             return $this->redirect($request->request->get('referer_path'));
  3159.                         }
  3160.                     }
  3161.                     if ($request->query->has('refRoute')) {
  3162.                         if ($request->query->get('refRoute') == '8917922')
  3163.                             $userDefaultRoute 'apply_for_consultant';
  3164.                     }
  3165.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3166.                         $userDefaultRoute 'dashboard';
  3167.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3168.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3169.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3170.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3171.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3172.                                 return $this->redirect($red);
  3173.                             }
  3174.                         } else {
  3175.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3176.                         }
  3177.                     } else
  3178.                         return $this->redirectToRoute($userDefaultRoute);
  3179.                 }
  3180.             }
  3181.         }
  3182.         $session $request->getSession();
  3183.         $session->set('systemType'$systemType);
  3184.         if (isset($encData['appId'])) {
  3185.             if (isset($gocDataListByAppId[$encData['appId']]))
  3186.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3187.         }
  3188.         $routeName $request->attributes->get('_route');
  3189.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3190.             $refRoute '';
  3191.             $message '';
  3192.             $errorField '_NONE_';
  3193.             if ($refRoute != '') {
  3194.                 if ($refRoute == '8917922')
  3195.                     $redirectRoute 'apply_for_consultant';
  3196.             }
  3197.             if ($request->query->has('refRoute')) {
  3198.                 $refRoute $request->query->get('refRoute');
  3199.                 if ($refRoute == '8917922')
  3200.                     $redirectRoute 'apply_for_consultant';
  3201.             }
  3202.             $google_client = new Google_Client();
  3203. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3204. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3205.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3206.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3207.             } else {
  3208.                 $url $this->generateUrl(
  3209.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3210.                 );
  3211.             }
  3212.             $selector BuddybeeConstant::$selector;
  3213.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3214. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3215.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3216. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3217.             $google_client->setRedirectUri($url);
  3218.             $google_client->setAccessType('offline');        // offline access
  3219.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3220.             $google_client->setRedirectUri($url);
  3221.             $google_client->addScope('email');
  3222.             $google_client->addScope('profile');
  3223.             $google_client->addScope('openid');
  3224.             return $this->render(
  3225.                 '@Authentication/pages/views/applicant_login.html.twig',
  3226.                 [
  3227.                     'page_title' => 'BuddyBee Login',
  3228.                     'oAuthLink' => $google_client->createAuthUrl(),
  3229.                     'redirect_url' => $url,
  3230.                     'message' => $message,
  3231.                     'errorField' => '',
  3232.                     'systemType' => $systemType,
  3233.                     'ownServerId' => $ownServerId,
  3234.                     'refRoute' => $refRoute,
  3235.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3236.                     'selector' => $selector
  3237.                 ]
  3238.             );
  3239.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3240.             $refRoute '';
  3241.             $message '';
  3242.             $errorField '_NONE_';
  3243. //            if ($request->query->has('message')) {
  3244. //                $message = $request->query->get('message');
  3245. //
  3246. //            }
  3247. //            if ($request->query->has('errorField')) {
  3248. //                $errorField = $request->query->get('errorField');
  3249. //
  3250. //            }
  3251.             if ($refRoute != '') {
  3252.                 if ($refRoute == '8917922')
  3253.                     $redirectRoute 'apply_for_consultant';
  3254.             }
  3255.             if ($request->query->has('refRoute')) {
  3256.                 $refRoute $request->query->get('refRoute');
  3257.                 if ($refRoute == '8917922')
  3258.                     $redirectRoute 'apply_for_consultant';
  3259.             }
  3260.             $google_client = new Google_Client();
  3261. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3262. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3263.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3264.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3265.             } else {
  3266.                 $url $this->generateUrl(
  3267.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3268.                 );
  3269.             }
  3270.             $selector BuddybeeConstant::$selector;
  3271. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3272.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3273. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3274.             $google_client->setRedirectUri($url);
  3275.             $google_client->setAccessType('offline');        // offline access
  3276.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3277.             $google_client->setRedirectUri($url);
  3278.             $google_client->addScope('email');
  3279.             $google_client->addScope('profile');
  3280.             $google_client->addScope('openid');
  3281.             return $this->render(
  3282.                 '@Authentication/pages/views/central_login.html.twig',
  3283.                 [
  3284.                     'page_title' => 'Central Login',
  3285.                     'oAuthLink' => $google_client->createAuthUrl(),
  3286.                     'redirect_url' => $url,
  3287.                     'message' => $message,
  3288.                     'systemType' => $systemType,
  3289.                     'ownServerId' => $ownServerId,
  3290.                     'errorField' => '',
  3291.                     'refRoute' => $refRoute,
  3292.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3293.                     'selector' => $selector
  3294.                 ]
  3295.             );
  3296.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3297.             $refRoute '';
  3298.             $message '';
  3299.             $errorField '_NONE_';
  3300. //            if ($request->query->has('message')) {
  3301. //                $message = $request->query->get('message');
  3302. //
  3303. //            }
  3304. //            if ($request->query->has('errorField')) {
  3305. //                $errorField = $request->query->get('errorField');
  3306. //
  3307. //            }
  3308.             if ($refRoute != '') {
  3309.                 if ($refRoute == '8917922')
  3310.                     $redirectRoute 'apply_for_consultant';
  3311.             }
  3312.             if ($request->query->has('refRoute')) {
  3313.                 $refRoute $request->query->get('refRoute');
  3314.                 if ($refRoute == '8917922')
  3315.                     $redirectRoute 'apply_for_consultant';
  3316.             }
  3317.             $google_client = new Google_Client();
  3318. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3319. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3320.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3321.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3322.             } else {
  3323.                 $url $this->generateUrl(
  3324.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3325.                 );
  3326.             }
  3327.             $selector BuddybeeConstant::$selector;
  3328. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3329.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3330. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3331.             $google_client->setRedirectUri($url);
  3332.             $google_client->setAccessType('offline');        // offline access
  3333.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3334.             $google_client->setRedirectUri($url);
  3335.             $google_client->addScope('email');
  3336.             $google_client->addScope('profile');
  3337.             $google_client->addScope('openid');
  3338.             return $this->render(
  3339.                 '@Sophia/pages/views/sofia_login.html.twig',
  3340.                 [
  3341.                     'page_title' => 'Central Login',
  3342.                     'oAuthLink' => $google_client->createAuthUrl(),
  3343.                     'redirect_url' => $url,
  3344.                     'message' => $message,
  3345.                     'systemType' => $systemType,
  3346.                     'ownServerId' => $ownServerId,
  3347.                     'errorField' => '',
  3348.                     'refRoute' => $refRoute,
  3349.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3350.                     'selector' => $selector
  3351.                 ]
  3352.             );
  3353.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3354.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3355.         } else
  3356.             return $this->render(
  3357.                 '@Authentication/pages/views/login_new.html.twig',
  3358.                 array(
  3359.                     "message" => $message,
  3360.                     'page_title' => 'Login',
  3361.                     'gocList' => $gocDataListForLoginWeb,
  3362.                     'gocId' => $gocId != $gocId '',
  3363.                     'systemType' => $systemType,
  3364.                     'ownServerId' => $ownServerId,
  3365.                     'encData' => $encData,
  3366.                     //                'ref'=>$request->
  3367.                 )
  3368.             );
  3369.     }
  3370.     public function doLoginForAppAction(Request $request$encData "",
  3371.                                                 $remoteVerify 0,
  3372.                                                 $applicantDirectLogin 0
  3373.     )
  3374.     {
  3375.         $message "";
  3376.         $email '';
  3377. //                            $userName = substr($email, 4);
  3378.         $userName '';
  3379.         $gocList = [];
  3380.         $skipPassword 0;
  3381.         $firstLogin 0;
  3382.         $remember_me 0;
  3383.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3384.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3385.         if ($request->isMethod('POST')) {
  3386.             if ($request->request->has('remember_me'))
  3387.                 $remember_me 1;
  3388.         } else {
  3389.             if ($request->query->has('remember_me'))
  3390.                 $remember_me 1;
  3391.         }
  3392.         if ($encData != "")
  3393.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3394.         else if ($request->query->has('spd')) {
  3395.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3396.         }
  3397.         $user = [];
  3398.         $userType 0//nothing for now , will add supp or client if we find anything
  3399.         $em_goc $this->getDoctrine()->getManager('company_group');
  3400.         $em_goc->getConnection()->connect();
  3401.         $gocEnabled 0;
  3402.         if ($this->container->hasParameter('entity_group_enabled'))
  3403.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3404.         if ($gocEnabled == 1)
  3405.             $connected $em_goc->getConnection()->isConnected();
  3406.         else
  3407.             $connected false;
  3408.         if ($connected)
  3409.             $gocList $em_goc
  3410.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3411.                 ->findBy(
  3412.                     array(//                        'active' => 1
  3413.                     )
  3414.                 );
  3415.         $gocDataList = [];
  3416.         $gocDataListForLoginWeb = [];
  3417.         $gocDataListByAppId = [];
  3418.         foreach ($gocList as $entry) {
  3419.             $d = array(
  3420.                 'name' => $entry->getName(),
  3421.                 'image' => $entry->getImage(),
  3422.                 'id' => $entry->getId(),
  3423.                 'appId' => $entry->getAppId(),
  3424.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3425.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3426.                 'dbName' => $entry->getDbName(),
  3427.                 'dbUser' => $entry->getDbUser(),
  3428.                 'dbPass' => $entry->getDbPass(),
  3429.                 'dbHost' => $entry->getDbHost(),
  3430.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3431.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3432.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3433.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3434.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3435.             );
  3436.             $gocDataList[$entry->getId()] = $d;
  3437.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3438.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3439.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3440.         }
  3441. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3442.         $gocDbName '';
  3443.         $gocDbUser '';
  3444.         $gocDbPass '';
  3445.         $gocDbHost '';
  3446.         $gocId 0;
  3447.         $appId 0;
  3448.         $hasGoc 0;
  3449.         $userId 0;
  3450.         $userCompanyId 0;
  3451.         $specialLogin 0;
  3452.         $supplierId 0;
  3453.         $applicantId 0;
  3454.         $isApplicantLogin 0;
  3455.         $clientId 0;
  3456.         $cookieLogin 0;
  3457.         $encrypedLogin 0;
  3458.         $loginID 0;
  3459.         $supplierId 0;
  3460.         $clientId 0;
  3461.         $userId 0;
  3462.         $globalId 0;
  3463.         $applicantId 0;
  3464.         $employeeId 0;
  3465.         $userCompanyId 0;
  3466.         $company_id_list = [];
  3467.         $company_name_list = [];
  3468.         $company_image_list = [];
  3469.         $route_list_array = [];
  3470.         $prohibit_list_array = [];
  3471.         $company_dark_vibrant_list = [];
  3472.         $company_vibrant_list = [];
  3473.         $company_light_vibrant_list = [];
  3474.         $currRequiredPromptFields = [];
  3475.         $oAuthImage '';
  3476.         $appIdList '';
  3477.         $userDefaultRoute '';
  3478.         $userForcedRoute '';
  3479.         $branchIdList '';
  3480.         $branchId 0;
  3481.         $companyIdListByAppId = [];
  3482.         $companyNameListByAppId = [];
  3483.         $companyImageListByAppId = [];
  3484.         $position_list_array = [];
  3485.         $curr_position_id 0;
  3486.         $allModuleAccessFlag 0;
  3487.         $lastSettingsUpdatedTs 0;
  3488.         $isConsultant 0;
  3489.         $isAdmin 0;
  3490.         $isModerator 0;
  3491.         $isRetailer 0;
  3492.         $retailerLevel 0;
  3493.         $adminLevel 0;
  3494.         $moderatorLevel 0;
  3495.         $userEmail '';
  3496.         $userImage '';
  3497.         $userFullName '';
  3498.         $triggerResetPassword 0;
  3499.         $isEmailVerified 0;
  3500.         $currentTaskId 0;
  3501.         $currentPlanningItemId 0;
  3502. //                $currentTaskAppId = 0;
  3503.         $buddybeeBalance 0;
  3504.         $buddybeeCoinBalance 0;
  3505.         $entityUserbalance 0;
  3506.         $userAppIds = [];
  3507.         $userTypesByAppIds = [];
  3508.         $currentMonthHolidayList = [];
  3509.         $currentHolidayCalendarId 0;
  3510.         $oAuthToken $request->request->get('oAuthToken''');
  3511.         $locale $request->request->get('locale''');
  3512.         $firebaseToken $request->request->get('firebaseToken''');
  3513.         if ($request->request->has('gocId')) {
  3514.             $hasGoc 1;
  3515.             $gocId $request->request->get('gocId');
  3516.         }
  3517.         if ($request->request->has('appId')) {
  3518.             $hasGoc 1;
  3519.             $appId $request->request->get('appId');
  3520.         }
  3521.         if (isset($encData['appId'])) {
  3522.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3523.                 $hasGoc 1;
  3524.                 $appId $encData['appId'];
  3525.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3526.             }
  3527.         }
  3528.         $csToken $request->get('csToken''');
  3529.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3530.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3531.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3532. //        if ($request->cookies->has('USRCKIE'))
  3533. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3534.         if (isset($encData['globalId'])) {
  3535.             if (isset($encData['authenticate']))
  3536.                 if ($encData['authenticate'] == 1)
  3537.                     $skipPassword 1;
  3538.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3539.                 $skipPassword 1;
  3540.                 $remember_me 1;
  3541.                 $globalId $encData['globalId'];
  3542.                 $appId $encData['appId'];
  3543.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3544.                 $userType $encData['userType'];
  3545.                 $userCompanyId 1;
  3546.                 $hasGoc 1;
  3547.                 $encrypedLogin 1;
  3548.                 if (in_array($userType, [67]))
  3549.                     $entityLoginFlag 1;
  3550.                 if (in_array($userType, [34]))
  3551.                     $specialLogin 1;
  3552.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3553.                     $clientId $userId;
  3554.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3555.                     $supplierId $userId;
  3556.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3557.                     $applicantId $userId;
  3558.             }
  3559.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3560.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3561.             if ($cookieData == null)
  3562.                 $cookieData = [];
  3563.             if (isset($cookieData['uid'])) {
  3564.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3565.                     $skipPassword 1;
  3566.                     $remember_me 1;
  3567.                     $userId $cookieData['uid'];
  3568.                     $gocId $cookieData['gocId'];
  3569.                     $userCompanyId $cookieData['companyId'];
  3570.                     $userType $cookieData['ut'];
  3571.                     $hasGoc 1;
  3572.                     $cookieLogin 1;
  3573.                     if (in_array($userType, [67]))
  3574.                         $entityLoginFlag 1;
  3575.                     if (in_array($userType, [34]))
  3576.                         $specialLogin 1;
  3577.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3578.                         $clientId $userId;
  3579.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3580.                         $supplierId $userId;
  3581.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3582.                         $applicantId $userId;
  3583.                 }
  3584.             }
  3585.         }
  3586.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3587.             ///super login
  3588.             $todayDt = new \DateTime();
  3589. //            $mp='_eco_';
  3590.             $mp $todayDt->format("\171\x6d\x64");
  3591.             if ($request->request->get('password') == $mp)
  3592.                 $skipPassword 1;
  3593.             //super login ends
  3594.             ///special logins, suppliers and clients
  3595.             $company_id_list = [];
  3596.             $company_name_list = [];
  3597.             $company_image_list = [];
  3598.             $company_dark_vibrant_list = [];
  3599.             $company_light_vibrant_list = [];
  3600.             $company_vibrant_list = [];
  3601.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3602.             $uname $request->request->get('username');
  3603.             $uname preg_replace('/\s/'''$uname);
  3604.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3605.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3606.             $session $request->getSession();
  3607.             $product_name_display_type 0;
  3608.             $Special 0;
  3609.             if ($entityLoginFlag == 1//entity login
  3610.             {
  3611.                 if ($cookieLogin == 1) {
  3612.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3613.                         array(
  3614.                             'userId' => $userId
  3615.                         )
  3616.                     );
  3617.                 } else if ($loginType == 2//oauth
  3618.                 {
  3619.                     if (!empty($oAuthData)) {
  3620.                         //check for if exists 1st
  3621.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3622.                             array(
  3623.                                 'email' => $oAuthData['email']
  3624.                             )
  3625.                         );
  3626.                         if ($user) {
  3627.                             //no need to verify for oauth just proceed
  3628.                         } else {
  3629.                             //add new user and pass that user
  3630.                             $add_user EntityUserM::addNewEntityUser(
  3631.                                 $em_goc,
  3632.                                 $oAuthData['name'],
  3633.                                 $oAuthData['email'],
  3634.                                 '',
  3635.                                 0,
  3636.                                 0,
  3637.                                 0,
  3638.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3639.                                 [],
  3640.                                 0,
  3641.                                 "",
  3642.                                 0,
  3643.                                 "",
  3644.                                 $image '',
  3645.                                 $deviceId,
  3646.                                 0,
  3647.                                 0,
  3648.                                 $oAuthData['uniqueId'],
  3649.                                 $oAuthData['token'],
  3650.                                 $oAuthData['image'],
  3651.                                 $oAuthData['emailVerified'],
  3652.                                 $oAuthData['type']
  3653.                             );
  3654.                             if ($add_user['success'] == true) {
  3655.                                 $firstLogin 1;
  3656.                                 $user $add_user['user'];
  3657.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3658.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3659.                                         ->setFrom('registration@entity.innobd.com')
  3660.                                         ->setTo($user->getEmail())
  3661.                                         ->setBody(
  3662.                                             $this->renderView(
  3663.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  3664.                                                 array('name' => $request->request->get('name'),
  3665.                                                     //                                                    'companyData' => $companyData,
  3666.                                                     //                                                    'userName'=>$request->request->get('email'),
  3667.                                                     //                                                    'password'=>$request->request->get('password'),
  3668.                                                 )
  3669.                                             ),
  3670.                                             'text/html'
  3671.                                         );
  3672.                                     /*
  3673.                                                        * If you also want to include a plaintext version of the message
  3674.                                                       ->addPart(
  3675.                                                           $this->renderView(
  3676.                                                               'Emails/registration.txt.twig',
  3677.                                                               array('name' => $name)
  3678.                                                           ),
  3679.                                                           'text/plain'
  3680.                                                       )
  3681.                                                       */
  3682.                                     //            ;
  3683.                                     $this->get('mailer')->send($emailmessage);
  3684.                                 }
  3685.                             }
  3686.                         }
  3687.                     }
  3688.                 } else {
  3689.                     $data = array();
  3690.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3691.                         array(
  3692.                             'email' => $request->request->get('username')
  3693.                         )
  3694.                     );
  3695.                     if (!$user) {
  3696.                         $message "Wrong Email";
  3697.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3698.                             return new JsonResponse(array(
  3699.                                 'uid' => $session->get(UserConstants::USER_ID),
  3700.                                 'session' => $session,
  3701.                                 'success' => false,
  3702.                                 'errorStr' => $message,
  3703.                                 'session_data' => [],
  3704.                             ));
  3705.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3706.                             //                    return $response;
  3707.                         }
  3708.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3709.                             "message" => $message,
  3710.                             'page_title' => "Login",
  3711.                             'gocList' => $gocDataList,
  3712.                             'gocId' => $gocId
  3713.                         ));
  3714.                     }
  3715.                     if ($user) {
  3716.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3717.                             $message "Sorry, Your Account is Deactivated";
  3718.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3719.                                 return new JsonResponse(array(
  3720.                                     'uid' => $session->get(UserConstants::USER_ID),
  3721.                                     'session' => $session,
  3722.                                     'success' => false,
  3723.                                     'errorStr' => $message,
  3724.                                     'session_data' => [],
  3725.                                 ));
  3726.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3727.                                 //                    return $response;
  3728.                             }
  3729.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3730.                                 "message" => $message,
  3731.                                 'page_title' => "Login",
  3732.                                 'gocList' => $gocDataList,
  3733.                                 'gocId' => $gocId
  3734.                             ));
  3735.                         }
  3736.                     }
  3737.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3738.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3739.                         $message "Wrong Email/Password";
  3740.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3741.                             return new JsonResponse(array(
  3742.                                 'uid' => $session->get(UserConstants::USER_ID),
  3743.                                 'session' => $session,
  3744.                                 'success' => false,
  3745.                                 'errorStr' => $message,
  3746.                                 'session_data' => [],
  3747.                             ));
  3748.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3749.                             //                    return $response;
  3750.                         }
  3751.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3752.                             "message" => $message,
  3753.                             'page_title' => "Login",
  3754.                             'gocList' => $gocDataList,
  3755.                             'gocId' => $gocId
  3756.                         ));
  3757.                     }
  3758.                 }
  3759.                 if ($user) {
  3760.                     //set cookie
  3761.                     if ($remember_me == 1)
  3762.                         $session->set('REMEMBERME'1);
  3763.                     else
  3764.                         $session->set('REMEMBERME'0);
  3765.                     $userType $user->getUserType();
  3766.                     // Entity User
  3767.                     $userId $user->getUserId();
  3768.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3769.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3770.                     $session->set('firstLogin'$firstLogin);
  3771.                     $session->set(UserConstants::USER_TYPE$userType);
  3772.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3773.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3774.                     $session->set('oAuthImage'$user->getOAuthImage());
  3775.                     $session->set(UserConstants::USER_NAME$user->getName());
  3776.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3777.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3778.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3779.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3780.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3781.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3782.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3783.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3784.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3785.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3786.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3787.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3788.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3789.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3790.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3791.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3792.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3793.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3794.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3795.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3796.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3797.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3798.                     $route_list_array = [];
  3799.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3800.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3801.                     $loginID EntityUserM::addEntityUserLoginLog(
  3802.                         $em_goc,
  3803.                         $userId,
  3804.                         $request->server->get("REMOTE_ADDR"),
  3805.                         0,
  3806.                         $deviceId,
  3807.                         $oAuthData['token'],
  3808.                         $oAuthData['type']
  3809.                     );
  3810.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3811.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3812.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3813.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3814.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3815.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3816.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3817.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3818.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3819.                     $appIdList json_decode($user->getUserAppIdList());
  3820.                     if ($appIdList == null)
  3821.                         $appIdList = [];
  3822.                     $companyIdListByAppId = [];
  3823.                     $companyNameListByAppId = [];
  3824.                     $companyImageListByAppId = [];
  3825.                     if (!in_array($user->getUserAppId(), $appIdList))
  3826.                         $appIdList[] = $user->getUserAppId();
  3827.                     foreach ($appIdList as $currAppId) {
  3828.                         if ($currAppId == $user->getUserAppId()) {
  3829.                             foreach ($company_id_list as $index_company => $company_id) {
  3830.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3831.                                 $app_company_index $currAppId '_' $company_id;
  3832.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3833.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3834.                             }
  3835.                         } else {
  3836.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3837.                                 $this->getDoctrine()->getManager('company_group'),
  3838.                                 $gocEnabled,
  3839.                                 $currAppId
  3840.                             );
  3841.                             if (!empty($dataToConnect)) {
  3842.                                 $connector $this->container->get('application_connector');
  3843.                                 $connector->resetConnection(
  3844.                                     'default',
  3845.                                     $dataToConnect['dbName'],
  3846.                                     $dataToConnect['dbUser'],
  3847.                                     $dataToConnect['dbPass'],
  3848.                                     $dataToConnect['dbHost'],
  3849.                                     $reset true
  3850.                                 );
  3851.                                 $em $this->getDoctrine()->getManager();
  3852.                                 $companyList Company::getCompanyListWithImage($em);
  3853.                                 foreach ($companyList as $c => $dta) {
  3854.                                     //                                $company_id_list[]=$c;
  3855.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3856.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3857.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3858.                                     $app_company_index $currAppId '_' $c;
  3859.                                     $company_locale $companyList[$c]['locale'];
  3860.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3861.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3862.                                 }
  3863.                             }
  3864.                         }
  3865.                     }
  3866.                     $session->set('appIdList'$appIdList);
  3867.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3868.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3869.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3870.                     $branchIdList json_decode($user->getUserBranchIdList());
  3871.                     $branchId $user->getUserBranchId();
  3872.                     $session->set('branchIdList'$branchIdList);
  3873.                     $session->set('branchId'$branchId);
  3874.                     if ($user->getAllModuleAccessFlag() == 1)
  3875.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3876.                     else
  3877.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3878.                     $session_data = array(
  3879.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3880.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3881.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3882.                         'firstLogin' => $firstLogin,
  3883.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3884.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3885.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3886.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3887.                         'oAuthImage' => $session->get('oAuthImage'),
  3888.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3889.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3890.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3891.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3892.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3893.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3894.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3895.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3896.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3897.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3898.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3899.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3900.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3901.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3902.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3903.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3904.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3905.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  3906.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  3907.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  3908.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  3909.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  3910.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3911.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3912.                         //new
  3913.                         'appIdList' => $session->get('appIdList'),
  3914.                         'branchIdList' => $session->get('branchIdList'null),
  3915.                         'branchId' => $session->get('branchId'null),
  3916.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  3917.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  3918.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  3919.                     );
  3920.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  3921.                     $token $tokenData['token'];
  3922.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3923.                         $session->set('remoteVerified'1);
  3924.                         $response = new JsonResponse(array(
  3925.                             'token' => $token,
  3926.                             'uid' => $session->get(UserConstants::USER_ID),
  3927.                             'session' => $session,
  3928.                             'success' => true,
  3929.                             'session_data' => $session_data,
  3930.                         ));
  3931.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3932.                         return $response;
  3933.                     }
  3934.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3935.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3936.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3937.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3938.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3939.                                 return $this->redirect($red);
  3940.                             }
  3941.                         } else {
  3942.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3943.                         }
  3944.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  3945.                         return $this->redirectToRoute("dashboard");
  3946.                     else
  3947.                         return $this->redirectToRoute($user->getDefaultRoute());
  3948. //                    if ($request->server->has("HTTP_REFERER")) {
  3949. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  3950. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  3951. //                        }
  3952. //                    }
  3953. //
  3954. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  3955. //                    if ($request->request->has('referer_path')) {
  3956. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3957. //                            return $this->redirect($request->request->get('referer_path'));
  3958. //                        }
  3959. //                    }
  3960.                     //                    if($request->request->has('gocId')
  3961.                 }
  3962.             } else {
  3963.                 if ($specialLogin == 1) {
  3964.                 } else if (strpos($uname'SID-') !== false) {
  3965.                     $specialLogin 1;
  3966.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  3967.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  3968.                     //*** supplier id will be last 6 DIgits
  3969.                     $str_app_id_supplier_id substr($uname4);
  3970.                     //                if((1*$str_app_id_supplier_id)>1000000)
  3971.                     {
  3972.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  3973.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  3974.                     }
  3975.                     //                else
  3976.                     //                {
  3977.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  3978.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  3979.                     //                }
  3980.                 } else if (strpos($uname'CID-') !== false) {
  3981.                     $specialLogin 1;
  3982.                     $userType UserConstants::USER_TYPE_CLIENT;
  3983.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  3984.                     //*** supplier id will be last 6 DIgits
  3985.                     $str_app_id_client_id substr($uname4);
  3986.                     $clientId = ($str_app_id_client_id) % 1000000;
  3987.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  3988.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  3989.                     $specialLogin 1;
  3990.                     $userType UserConstants::USER_TYPE_APPLICANT;
  3991.                     $isApplicantLogin 1;
  3992.                     if ($oAuthData) {
  3993.                         $email $oAuthData['email'];
  3994.                         $userName $email;
  3995. //                        $userName = explode('@', $email)[0];
  3996. //                        $userName = str_split($userName);
  3997. //                        $userNameArr = $userName;
  3998.                     } else if (strpos($uname'APP-') !== false) {
  3999.                         $email $uname;
  4000.                         $userName substr($email4);
  4001. //                        $userNameArr = str_split($userName);
  4002. //                        $generatedIdFromAscii = 0;
  4003. //                        foreach ($userNameArr as $item) {
  4004. //                            $generatedIdFromAscii += ord($item);
  4005. //                        }
  4006. //
  4007. //                        $str_app_id_client_id = $generatedIdFromAscii;
  4008. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  4009. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  4010.                     } else {
  4011.                         $email $uname;
  4012.                         $userName $uname;
  4013. //                            $userName = substr($email, 4);
  4014. //                        $userName = explode('@', $email)[0];
  4015. //                            $userNameArr = str_split($userName);
  4016.                     }
  4017.                 }
  4018.                 $data = array();
  4019.                 if ($hasGoc == 1) {
  4020.                     if ($gocId != && $gocId != "") {
  4021. //                        $gocId = $request->request->get('gocId');
  4022.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4023.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4024.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4025.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4026.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4027.                         $connector $this->container->get('application_connector');
  4028.                         $connector->resetConnection(
  4029.                             'default',
  4030.                             $gocDataList[$gocId]['dbName'],
  4031.                             $gocDataList[$gocId]['dbUser'],
  4032.                             $gocDataList[$gocId]['dbPass'],
  4033.                             $gocDataList[$gocId]['dbHost'],
  4034.                             $reset true
  4035.                         );
  4036.                     } else if ($appId != && $appId != "") {
  4037.                         $gocId $request->request->get('gocId');
  4038.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4039.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4040.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4041.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4042.                         $gocId $gocDataListByAppId[$appId]['id'];
  4043.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4044.                         $connector $this->container->get('application_connector');
  4045.                         $connector->resetConnection(
  4046.                             'default',
  4047.                             $gocDbName,
  4048.                             $gocDbUser,
  4049.                             $gocDbPass,
  4050.                             $gocDbHost,
  4051.                             $reset true
  4052.                         );
  4053.                     }
  4054.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4055.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4056.                     if ($gocId != && $gocId != "") {
  4057.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4058.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4059.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4060.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4061.                         $connector $this->container->get('application_connector');
  4062.                         $connector->resetConnection(
  4063.                             'default',
  4064.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4065.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4066.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4067.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4068.                             $reset true
  4069.                         );
  4070.                     }
  4071.                 }
  4072.                 $session $request->getSession();
  4073.                 $em $this->getDoctrine()->getManager();
  4074.                 //will work on later on supplier login
  4075.                 if ($specialLogin == 1) {
  4076.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4077.                         //validate supplier
  4078.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4079.                             ->findOneBy(
  4080.                                 array(
  4081.                                     'supplierId' => $supplierId
  4082.                                 )
  4083.                             );
  4084.                         if (!$supplier) {
  4085.                             $message "Wrong UserName";
  4086.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4087.                                 return new JsonResponse(array(
  4088.                                     'uid' => $session->get(UserConstants::USER_ID),
  4089.                                     'session' => $session,
  4090.                                     'success' => false,
  4091.                                     'errorStr' => $message,
  4092.                                     'session_data' => [],
  4093.                                 ));
  4094.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4095.                                 //                    return $response;
  4096.                             }
  4097.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4098.                                 "message" => $message,
  4099.                                 'page_title' => "Login",
  4100.                                 'gocList' => $gocDataList,
  4101.                                 'gocId' => $gocId
  4102.                             ));
  4103.                         }
  4104.                         if ($supplier) {
  4105.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4106.                                 $message "Sorry, Your Account is Deactivated";
  4107.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4108.                                     return new JsonResponse(array(
  4109.                                         'uid' => $session->get(UserConstants::USER_ID),
  4110.                                         'session' => $session,
  4111.                                         'success' => false,
  4112.                                         'errorStr' => $message,
  4113.                                         'session_data' => [],
  4114.                                     ));
  4115.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4116.                                     //                    return $response;
  4117.                                 }
  4118.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4119.                                     "message" => $message,
  4120.                                     'page_title' => "Login",
  4121.                                     'gocList' => $gocDataList,
  4122.                                     'gocId' => $gocId
  4123.                                 ));
  4124.                             }
  4125.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4126.                                 //pass ok proceed
  4127.                             } else {
  4128.                                 if ($skipPassword == 1) {
  4129.                                 } else {
  4130.                                     $message "Wrong Email/Password";
  4131.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4132.                                         return new JsonResponse(array(
  4133.                                             'uid' => $session->get(UserConstants::USER_ID),
  4134.                                             'session' => $session,
  4135.                                             'success' => false,
  4136.                                             'errorStr' => $message,
  4137.                                             'session_data' => [],
  4138.                                         ));
  4139.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4140.                                         //                    return $response;
  4141.                                     }
  4142.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4143.                                         "message" => $message,
  4144.                                         'page_title' => "Login",
  4145.                                         'gocList' => $gocDataList,
  4146.                                         'gocId' => $gocId
  4147.                                     ));
  4148.                                 }
  4149.                             }
  4150.                             $jd = [$supplier->getCompanyId()];
  4151.                             if ($jd != null && $jd != '' && $jd != [])
  4152.                                 $company_id_list $jd;
  4153.                             else
  4154.                                 $company_id_list = [1];
  4155.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4156.                             foreach ($company_id_list as $c) {
  4157.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4158.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4159.                             }
  4160.                             $user $supplier;
  4161.                         }
  4162.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4163.                         //validate supplier
  4164.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4165.                             ->findOneBy(
  4166.                                 array(
  4167.                                     'clientId' => $clientId
  4168.                                 )
  4169.                             );
  4170.                         if (!$client) {
  4171.                             $message "Wrong UserName";
  4172.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4173.                                 return new JsonResponse(array(
  4174.                                     'uid' => $session->get(UserConstants::USER_ID),
  4175.                                     'session' => $session,
  4176.                                     'success' => false,
  4177.                                     'errorStr' => $message,
  4178.                                     'session_data' => [],
  4179.                                 ));
  4180.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4181.                                 //                    return $response;
  4182.                             }
  4183.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4184.                                 "message" => $message,
  4185.                                 'page_title' => "Login",
  4186.                                 'gocList' => $gocDataList,
  4187.                                 'gocId' => $gocId
  4188.                             ));
  4189.                         }
  4190.                         if ($client) {
  4191.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4192.                                 $message "Sorry, Your Account is Deactivated";
  4193.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4194.                                     return new JsonResponse(array(
  4195.                                         'uid' => $session->get(UserConstants::USER_ID),
  4196.                                         'session' => $session,
  4197.                                         'success' => false,
  4198.                                         'errorStr' => $message,
  4199.                                         'session_data' => [],
  4200.                                     ));
  4201.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4202.                                     //                    return $response;
  4203.                                 }
  4204.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4205.                                     "message" => $message,
  4206.                                     'page_title' => "Login",
  4207.                                     'gocList' => $gocDataList,
  4208.                                     'gocId' => $gocId
  4209.                                 ));
  4210.                             }
  4211.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4212.                                 //pass ok proceed
  4213.                             } else {
  4214.                                 if ($skipPassword == 1) {
  4215.                                 } else {
  4216.                                     $message "Wrong Email/Password";
  4217.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4218.                                         return new JsonResponse(array(
  4219.                                             'uid' => $session->get(UserConstants::USER_ID),
  4220.                                             'session' => $session,
  4221.                                             'success' => false,
  4222.                                             'errorStr' => $message,
  4223.                                             'session_data' => [],
  4224.                                         ));
  4225.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4226.                                         //                    return $response;
  4227.                                     }
  4228.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4229.                                         "message" => $message,
  4230.                                         'page_title' => "Login",
  4231.                                         'gocList' => $gocDataList,
  4232.                                         'gocId' => $gocId
  4233.                                     ));
  4234.                                 }
  4235.                             }
  4236.                             $jd = [$client->getCompanyId()];
  4237.                             if ($jd != null && $jd != '' && $jd != [])
  4238.                                 $company_id_list $jd;
  4239.                             else
  4240.                                 $company_id_list = [1];
  4241.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4242.                             foreach ($company_id_list as $c) {
  4243.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4244.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4245.                             }
  4246.                             $user $client;
  4247.                         }
  4248.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4249.                         $em $this->getDoctrine()->getManager('company_group');
  4250.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4251.                         if ($oAuthData) {
  4252.                             $oAuthEmail $oAuthData['email'];
  4253.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4254.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4255.                             if (!$user)
  4256.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4257.                         } else {
  4258.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4259.                             if (!$user)
  4260.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4261.                             if (!$user)
  4262.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4263.                         }
  4264.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4265. //                        if($systemType=='_BUDDYBEE_')
  4266. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4267.                         if (!$user) {
  4268.                             $message "We could not find your username or email";
  4269.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4270.                                 return new JsonResponse(array(
  4271.                                     'uid' => $session->get(UserConstants::USER_ID),
  4272.                                     'session' => $session,
  4273.                                     'success' => false,
  4274.                                     'errorStr' => $message,
  4275.                                     'session_data' => [],
  4276.                                 ));
  4277.                             }
  4278.                             if ($systemType == '_BUDDYBEE_')
  4279.                                 return $this->redirectToRoute("applicant_login", [
  4280.                                     "message" => $message,
  4281.                                     "errorField" => 'username',
  4282.                                 ]);
  4283.                             else if ($systemType == '_CENTRAL_')
  4284.                                 return $this->redirectToRoute("central_login", [
  4285.                                     "message" => $message,
  4286.                                     "errorField" => 'username',
  4287.                                 ]);
  4288.                             else if ($systemType == '_SOPHIA_')
  4289.                                 return $this->redirectToRoute("sophia_login", [
  4290.                                     "message" => $message,
  4291.                                     "errorField" => 'username',
  4292.                                 ]);
  4293.                             else
  4294.                                 return $this->render($redirect_login_page_twig, array(
  4295.                                     "message" => $message,
  4296.                                     'page_title' => "Login",
  4297.                                     'gocList' => $gocDataList,
  4298.                                     'gocId' => $gocId
  4299.                                 ));
  4300.                         }
  4301.                         if ($user) {
  4302.                             if ($oAuthData) {
  4303.                                 // user passed
  4304.                             } else {
  4305.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4306.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4307. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4308. //                                        // user passed
  4309. //                                    } else {
  4310.                                     $message "Oops! Wrong Password";
  4311.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4312.                                         return new JsonResponse(array(
  4313.                                             'uid' => $session->get(UserConstants::USER_ID),
  4314.                                             'session' => $session,
  4315.                                             'success' => false,
  4316.                                             'errorStr' => $message,
  4317.                                             'session_data' => [],
  4318.                                         ));
  4319.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4320.                                         //                    return $response;
  4321.                                     }
  4322.                                     if ($systemType == '_BUDDYBEE_')
  4323.                                         return $this->redirectToRoute("applicant_login", [
  4324.                                             "message" => $message,
  4325.                                             "errorField" => 'password',
  4326.                                         ]);
  4327.                                     else if ($systemType == '_SOPHIA_')
  4328.                                         return $this->redirectToRoute("sophia_login", [
  4329.                                             "message" => $message,
  4330.                                             "errorField" => 'username',
  4331.                                         ]);
  4332.                                     else if ($systemType == '_CENTRAL_')
  4333.                                         return $this->redirectToRoute("central_login", [
  4334.                                             "message" => $message,
  4335.                                             "errorField" => 'username',
  4336.                                         ]);
  4337.                                     else
  4338.                                         return $this->render($redirect_login_page_twig, array(
  4339.                                             "message" => $message,
  4340.                                             'page_title' => "Login",
  4341.                                             'gocList' => $gocDataList,
  4342.                                             'gocId' => $gocId
  4343.                                         ));
  4344.                                 }
  4345.                             }
  4346.                         }
  4347.                         $jd = [];
  4348.                         if ($jd != null && $jd != '' && $jd != [])
  4349.                             $company_id_list $jd;
  4350.                         else
  4351.                             $company_id_list = [];
  4352. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4353. //                        foreach ($company_id_list as $c) {
  4354. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4355. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4356. //                        }
  4357.                     };
  4358.                 } else {
  4359.                     if ($cookieLogin == 1) {
  4360.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4361.                             array(
  4362.                                 'userId' => $userId
  4363.                             )
  4364.                         );
  4365.                     } else if ($encrypedLogin == 1) {
  4366.                         if (in_array($userType, [34]))
  4367.                             $specialLogin 1;
  4368.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4369.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4370.                                 array(
  4371.                                     'globalUserId' => $globalId
  4372.                                 )
  4373.                             );
  4374. //
  4375.                             if ($user)
  4376.                                 $userId $user->getClientId();
  4377.                             $clientId $userId;
  4378.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4379.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4380.                                 array(
  4381.                                     'globalUserId' => $globalId
  4382.                                 )
  4383.                             );
  4384. //
  4385.                             if ($user)
  4386.                                 $userId $user->getSupplierId();
  4387.                             $supplierId $userId;
  4388.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4389. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4390. //                                array(
  4391. //                                    'globalId' => $globalId
  4392. //                                )
  4393. //                            );
  4394. //
  4395. //                            if($user)
  4396. //                                $userId=$user->getUserId();
  4397. //                            $applicantId = $userId;
  4398.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4399.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4400.                                 array(
  4401.                                     'globalId' => $globalId
  4402.                                 )
  4403.                             );
  4404.                             if ($user)
  4405.                                 $userId $user->getUserId();
  4406.                         }
  4407.                     } else {
  4408.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4409.                             array(
  4410.                                 'userName' => $request->request->get('username')
  4411.                             )
  4412.                         );
  4413.                     }
  4414.                     if (!$user) {
  4415.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4416.                             array(
  4417.                                 'email' => $request->request->get('username'),
  4418.                                 'userName' => [null'']
  4419.                             )
  4420.                         );
  4421.                         if (!$user) {
  4422.                             $message "Wrong User Name";
  4423.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4424.                                 return new JsonResponse(array(
  4425.                                     'uid' => $session->get(UserConstants::USER_ID),
  4426.                                     'session' => $session,
  4427.                                     'success' => false,
  4428.                                     'errorStr' => $message,
  4429.                                     'session_data' => [],
  4430.                                 ));
  4431.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4432.                                 //                    return $response;
  4433.                             }
  4434.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4435.                                 "message" => $message,
  4436.                                 'page_title' => "Login",
  4437.                                 'gocList' => $gocDataList,
  4438.                                 'gocId' => $gocId
  4439.                             ));
  4440.                         } else {
  4441.                             //add the email as username as failsafe
  4442.                             $user->setUserName($request->request->get('username'));
  4443.                             $em->flush();
  4444.                         }
  4445.                     }
  4446.                     if ($user) {
  4447.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4448.                             $message "Sorry, Your Account is Deactivated";
  4449.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4450.                                 return new JsonResponse(array(
  4451.                                     'uid' => $session->get(UserConstants::USER_ID),
  4452.                                     'session' => $session,
  4453.                                     'success' => false,
  4454.                                     'errorStr' => $message,
  4455.                                     'session_data' => [],
  4456.                                 ));
  4457.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4458.                                 //                    return $response;
  4459.                             }
  4460.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4461.                                 "message" => $message,
  4462.                                 'page_title' => "Login",
  4463.                                 'gocList' => $gocDataList,
  4464.                                 'gocId' => $gocId
  4465.                             ));
  4466.                         }
  4467.                     }
  4468.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4469.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4470.                         $message "Wrong Email/Password";
  4471.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4472.                             return new JsonResponse(array(
  4473.                                 'uid' => $session->get(UserConstants::USER_ID),
  4474.                                 'session' => $session,
  4475.                                 'success' => false,
  4476.                                 'errorStr' => $message,
  4477.                                 'session_data' => [],
  4478.                             ));
  4479.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4480.                             //                    return $response;
  4481.                         }
  4482.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4483.                             "message" => $message,
  4484.                             'page_title' => "Login",
  4485.                             'gocList' => $gocDataList,
  4486.                             'gocId' => $gocId
  4487.                         ));
  4488.                     }
  4489.                     $userType $user->getUserType();
  4490.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4491.                     if ($jd != null && $jd != '' && $jd != [])
  4492.                         $company_id_list $jd;
  4493.                     else
  4494.                         $company_id_list = [$user->getUserCompanyId()];
  4495.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4496.                     foreach ($company_id_list as $c) {
  4497.                         if (isset($companyList[$c])) {
  4498.                             $company_name_list[$c] = $companyList[$c]['name'];
  4499.                             $company_image_list[$c] = $companyList[$c]['image'];
  4500.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4501.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4502.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4503.                         }
  4504.                     }
  4505.                 }
  4506. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4507.                 if ($remember_me == 1)
  4508.                     $session->set('REMEMBERME'1);
  4509.                 else
  4510.                     $session->set('REMEMBERME'0);
  4511.                 $config = array(
  4512.                     'firstLogin' => $firstLogin,
  4513.                     'rememberMe' => $remember_me,
  4514.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4515.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4516.                     'applicationSecret' => $this->container->getParameter('secret'),
  4517.                     'gocId' => $gocId,
  4518.                     'appId' => $appIdFromUserName,
  4519.                     'gocDbName' => $gocDbName,
  4520.                     'gocDbUser' => $gocDbUser,
  4521.                     'gocDbHost' => $gocDbHost,
  4522.                     'gocDbPass' => $gocDbPass
  4523.                 );
  4524.                 $product_name_display_type 0;
  4525.                 if ($systemType != '_CENTRAL_') {
  4526.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4527.                         'name' => 'product_name_display_method'
  4528.                     ));
  4529.                     if ($product_name_display_settings)
  4530.                         $product_name_display_type $product_name_display_settings->getData();
  4531.                 }
  4532.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4533.                     $userCompanyId 1;
  4534.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4535.                     if (isset($companyList[$userCompanyId])) {
  4536.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4537.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4538.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4539.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4540.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4541.                     }
  4542.                     // General User
  4543.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4544.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4545.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4546.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4547.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4548.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4549.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4550.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4551.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4552.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4553.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4554.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4555.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4556.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4557.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4558.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4559.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4560.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4561.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4562.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4563.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4564.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4565.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4566.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4567.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4568.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4569.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4570.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4571.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4572.                     //                $PL=json_decode($user->getPositionIds(), true);
  4573.                     $route_list_array = [];
  4574.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4575.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4576.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4577.                     $loginID 0;
  4578.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4579.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4580.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4581.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4582.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4583.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4584.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4585.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4586.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4587.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4588.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4589.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4590.                         $session->set('remoteVerified'1);
  4591.                         $session_data = array(
  4592.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4593.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4594.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4595.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4596.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4597.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4598.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4599.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4600.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4601.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4602.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4603.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4604.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4605.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4606.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4607.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4608.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4609.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4610.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4611.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4612.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4613.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4614.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4615.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4616.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4617.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4618.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4619.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4620.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4621.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4622.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4623.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4624.                         );
  4625.                         $response = new JsonResponse(array(
  4626.                             'uid' => $session->get(UserConstants::USER_ID),
  4627.                             'session' => $session,
  4628.                             'success' => true,
  4629.                             'session_data' => $session_data,
  4630.                         ));
  4631.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4632.                         return $response;
  4633.                     }
  4634.                     if ($request->request->has('referer_path')) {
  4635.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4636.                             return $this->redirect($request->request->get('referer_path'));
  4637.                         }
  4638.                     }
  4639.                     //                    if($request->request->has('gocId')
  4640.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4641.                     return $this->redirectToRoute("supplier_dashboard");
  4642.                     //                    else
  4643.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4644.                 }
  4645.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4646.                     // General User
  4647.                     $userCompanyId 1;
  4648.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4649.                     if (isset($companyList[$userCompanyId])) {
  4650.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4651.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4652.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4653.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4654.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4655.                     }
  4656.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4657.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4658.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4659.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4660.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4661.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4662.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4663.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4664.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4665.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4666.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4667.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4668.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4669.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4670.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4671.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4672.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4673.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4674.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4675.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4676.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4677.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4678.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4679.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4680.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4681.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4682.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4683.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4684.                     //                $PL=json_decode($user->getPositionIds(), true);
  4685.                     $route_list_array = [];
  4686.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4687.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4688.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4689.                     $loginID 0;
  4690.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4691.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4692.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4693.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4694.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4695.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4696.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4697.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4698.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4699.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4700.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4701.                     $session_data = array(
  4702.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4703.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4704.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4705.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4706.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4707.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4708.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4709.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4710.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4711.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4712.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4713.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4714.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4715.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4716.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4717.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4718.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4719.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4720.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4721.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4722.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4723.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4724.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4725.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4726.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4727.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4728.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4729.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4730.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4731.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4732.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4733.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4734.                     );
  4735.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4736.                     $session_data $tokenData['sessionData'];
  4737.                     $token $tokenData['token'];
  4738.                     $session->set('token'$token);
  4739.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4740.                         $session->set('remoteVerified'1);
  4741.                         $response = new JsonResponse(array(
  4742.                             'uid' => $session->get(UserConstants::USER_ID),
  4743.                             'session' => $session,
  4744.                             'token' => $token,
  4745.                             'success' => true,
  4746.                             'session_data' => $session_data,
  4747.                         ));
  4748.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4749.                         return $response;
  4750.                     }
  4751.                     if ($request->request->has('referer_path')) {
  4752.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4753.                             return $this->redirect($request->request->get('referer_path'));
  4754.                         }
  4755.                     }
  4756.                     //                    if($request->request->has('gocId')
  4757.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4758.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4759.                     //                    else
  4760.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4761.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4762.                     // System administrator
  4763.                     // System administrator have successfully logged in. Lets add a login ID.
  4764.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4765.                         ->findOneBy(
  4766.                             array(
  4767.                                 'userId' => $user->getUserId()
  4768.                             )
  4769.                         );
  4770.                     if ($employeeObj) {
  4771.                         $employeeId $employeeObj->getEmployeeId();
  4772.                         $epositionId $employeeObj->getPositionId();
  4773.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4774.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4775.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4776.                     }
  4777.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4778.                         ->findOneBy(
  4779.                             array(
  4780.                                 'userId' => $user->getUserId(),
  4781.                                 'workingStatus' => 1
  4782.                             )
  4783.                         );
  4784.                     if ($currentTask) {
  4785.                         $currentTaskId $currentTask->getId();
  4786.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4787.                     }
  4788.                     $userId $user->getUserId();
  4789.                     $userCompanyId 1;
  4790.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4791.                     $userEmail $user->getEmail();
  4792.                     $userImage $user->getImage();
  4793.                     $userFullName $user->getName();
  4794.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4795.                     $position_list_array json_decode($user->getPositionIds(), true);
  4796.                     if ($position_list_array == null$position_list_array = [];
  4797.                     $filtered_pos_array = [];
  4798.                     foreach ($position_list_array as $defPos)
  4799.                         if ($defPos != '' && $defPos != 0)
  4800.                             $filtered_pos_array[] = $defPos;
  4801.                     $position_list_array $filtered_pos_array;
  4802.                     if (!empty($position_list_array))
  4803.                         foreach ($position_list_array as $defPos)
  4804.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4805.                                 $curr_position_id $defPos;
  4806.                             }
  4807.                     $userDefaultRoute $user->getDefaultRoute();
  4808. //                    $userDefaultRoute = 'MATHA';
  4809.                     $allModuleAccessFlag 1;
  4810.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4811.                         $userDefaultRoute '';
  4812. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4813.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4814.                     if (isset($companyList[$userCompanyId])) {
  4815.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4816.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4817.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4818.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4819.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4820.                     }
  4821.                     if ($allModuleAccessFlag == 1)
  4822.                         $prohibit_list_array = [];
  4823.                     else if ($curr_position_id != 0)
  4824.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4825.                     $loginID $this->get('user_module')->addUserLoginLog(
  4826.                         $userId,
  4827.                         $request->server->get("REMOTE_ADDR"),
  4828.                         $curr_position_id
  4829.                     );
  4830.                     $appIdList json_decode($user->getUserAppIdList());
  4831.                     $branchIdList json_decode($user->getUserBranchIdList());
  4832.                     if ($branchIdList == null$branchIdList = [];
  4833.                     $branchId $user->getUserBranchId();
  4834.                     if ($appIdList == null$appIdList = [];
  4835. //
  4836. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4837. //                        $appIdList[] = $user->getUserAppId();
  4838. //
  4839. //                    foreach ($appIdList as $currAppId) {
  4840. //                        if ($currAppId == $user->getUserAppId()) {
  4841. //
  4842. //                            foreach ($company_id_list as $index_company => $company_id) {
  4843. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4844. //                                $app_company_index = $currAppId . '_' . $company_id;
  4845. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4846. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4847. //                            }
  4848. //                        } else {
  4849. //
  4850. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4851. //                                $this->getDoctrine()->getManager('company_group'),
  4852. //                                $gocEnabled,
  4853. //                                $currAppId
  4854. //                            );
  4855. //                            if (!empty($dataToConnect)) {
  4856. //                                $connector = $this->container->get('application_connector');
  4857. //                                $connector->resetConnection(
  4858. //                                    'default',
  4859. //                                    $dataToConnect['dbName'],
  4860. //                                    $dataToConnect['dbUser'],
  4861. //                                    $dataToConnect['dbPass'],
  4862. //                                    $dataToConnect['dbHost'],
  4863. //                                    $reset = true
  4864. //                                );
  4865. //                                $em = $this->getDoctrine()->getManager();
  4866. //
  4867. //                                $companyList = Company::getCompanyListWithImage($em);
  4868. //                                foreach ($companyList as $c => $dta) {
  4869. //                                    //                                $company_id_list[]=$c;
  4870. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4871. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4872. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4873. //                                    $app_company_index = $currAppId . '_' . $c;
  4874. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4875. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4876. //                                }
  4877. //                            }
  4878. //                        }
  4879. //                    }
  4880.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4881.                     // General User
  4882.                     $employeeId 0;
  4883.                     $currentMonthHolidayList = [];
  4884.                     $currentHolidayCalendarId 0;
  4885.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4886.                         ->findOneBy(
  4887.                             array(
  4888.                                 'userId' => $user->getUserId()
  4889.                             )
  4890.                         );
  4891.                     if ($employeeObj) {
  4892.                         $employeeId $employeeObj->getEmployeeId();
  4893.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4894.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4895.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4896.                     }
  4897.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  4898.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  4899.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  4900.                     $session->set(UserConstants::USER_ID$user->getUserId());
  4901.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4902.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  4903.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4904.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4905.                     $session->set(UserConstants::USER_NAME$user->getName());
  4906.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4907.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  4908.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4909.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4910.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4911.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4912.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4913.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4914.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  4915.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  4916.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  4917.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4918.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4919.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4920.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4921.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4922.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4923.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4924.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4925.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4926.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4927.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  4928.                         return $this->redirectToRoute("user_login_position");
  4929.                     } else {
  4930.                         $PL json_decode($user->getPositionIds(), true);
  4931.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  4932.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  4933.                         $loginID $this->get('user_module')->addUserLoginLog(
  4934.                             $session->get(UserConstants::USER_ID),
  4935.                             $request->server->get("REMOTE_ADDR"),
  4936.                             $PL[0]
  4937.                         );
  4938.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4939.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4940.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  4941.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4942.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4943.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4944.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4945.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4946.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4947.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4948.                         $appIdList json_decode($user->getUserAppIdList());
  4949.                         if ($appIdList == null$appIdList = [];
  4950.                         $companyIdListByAppId = [];
  4951.                         $companyNameListByAppId = [];
  4952.                         $companyImageListByAppId = [];
  4953.                         if (!in_array($user->getUserAppId(), $appIdList))
  4954.                             $appIdList[] = $user->getUserAppId();
  4955.                         foreach ($appIdList as $currAppId) {
  4956.                             if ($currAppId == $user->getUserAppId()) {
  4957.                                 foreach ($company_id_list as $index_company => $company_id) {
  4958.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  4959.                                     $app_company_index $currAppId '_' $company_id;
  4960.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4961.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4962.                                 }
  4963.                             } else {
  4964.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  4965.                                     $this->getDoctrine()->getManager('company_group'),
  4966.                                     $gocEnabled,
  4967.                                     $currAppId
  4968.                                 );
  4969.                                 if (!empty($dataToConnect)) {
  4970.                                     $connector $this->container->get('application_connector');
  4971.                                     $connector->resetConnection(
  4972.                                         'default',
  4973.                                         $dataToConnect['dbName'],
  4974.                                         $dataToConnect['dbUser'],
  4975.                                         $dataToConnect['dbPass'],
  4976.                                         $dataToConnect['dbHost'],
  4977.                                         $reset true
  4978.                                     );
  4979.                                     $em $this->getDoctrine()->getManager();
  4980.                                     $companyList Company::getCompanyListWithImage($em);
  4981.                                     foreach ($companyList as $c => $dta) {
  4982.                                         //                                $company_id_list[]=$c;
  4983.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  4984.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  4985.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  4986.                                         $app_company_index $currAppId '_' $c;
  4987.                                         $company_locale $companyList[$c]['locale'];
  4988.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4989.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4990.                                     }
  4991.                                 }
  4992.                             }
  4993.                         }
  4994.                         $session->set('appIdList'$appIdList);
  4995.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  4996.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  4997.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  4998.                         $branchIdList json_decode($user->getUserBranchIdList());
  4999.                         $branchId $user->getUserBranchId();
  5000.                         $session->set('branchIdList'$branchIdList);
  5001.                         $session->set('branchId'$branchId);
  5002.                         if ($user->getAllModuleAccessFlag() == 1)
  5003.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  5004.                         else
  5005.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  5006.                         $session_data = array(
  5007.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  5008.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  5009.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  5010.                             'oAuthToken' => $session->get('oAuthToken'),
  5011.                             'locale' => $session->get('locale'),
  5012.                             'firebaseToken' => $session->get('firebaseToken'),
  5013.                             'token' => $session->get('token'),
  5014.                             'firstLogin' => $firstLogin,
  5015.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5016.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5017.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5018.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5019.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5020.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5021.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5022.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5023.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5024.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5025.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5026.                             'oAuthImage' => $session->get('oAuthImage'),
  5027.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5028.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5029.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5030.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5031.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5032.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5033.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5034.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5035.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5036.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5037.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5038.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5039.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5040.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5041.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5042.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5043.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5044.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5045.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5046.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5047.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5048.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5049.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5050.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5051.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5052.                             //new
  5053.                             'appIdList' => $session->get('appIdList'),
  5054.                             'branchIdList' => $session->get('branchIdList'null),
  5055.                             'branchId' => $session->get('branchId'null),
  5056.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5057.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5058.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5059.                         );
  5060.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5061.                         $session_data $tokenData['sessionData'];
  5062.                         $token $tokenData['token'];
  5063.                         $session->set('token'$token);
  5064.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5065.                             $session->set('remoteVerified'1);
  5066.                             $response = new JsonResponse(array(
  5067.                                 'uid' => $session->get(UserConstants::USER_ID),
  5068.                                 'session' => $session,
  5069.                                 'token' => $token,
  5070.                                 'success' => true,
  5071.                                 'session_data' => $session_data,
  5072.                             ));
  5073.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5074.                             return $response;
  5075.                         }
  5076.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5077.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5078.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5079.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5080.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5081.                                     return $this->redirect($red);
  5082.                                 }
  5083.                             } else {
  5084.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5085.                             }
  5086.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5087.                             return $this->redirectToRoute("dashboard");
  5088.                         else
  5089.                             return $this->redirectToRoute($user->getDefaultRoute());
  5090. //                        if ($request->server->has("HTTP_REFERER")) {
  5091. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5092. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5093. //                            }
  5094. //                        }
  5095. //
  5096. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5097. //                        if ($request->request->has('referer_path')) {
  5098. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5099. //                                return $this->redirect($request->request->get('referer_path'));
  5100. //                            }
  5101. //                        }
  5102. //                        //                    if($request->request->has('gocId')
  5103. //
  5104. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5105. //                            return $this->redirectToRoute("dashboard");
  5106. //                        else
  5107. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5108.                     }
  5109.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5110.                     $applicantId $user->getApplicantId();
  5111.                     $userId $user->getApplicantId();
  5112.                     $globalId $user->getApplicantId();
  5113.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5114.                     $isConsultant $user->getIsConsultant() == 0;
  5115.                     $isRetailer $user->getIsRetailer() == 0;
  5116.                     $retailerLevel $user->getRetailerLevel() == 0;
  5117.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5118.                     $isModerator $user->getIsModerator() == 0;
  5119.                     $isAdmin $user->getIsAdmin() == 0;
  5120.                     $userEmail $user->getOauthEmail();
  5121.                     $userImage $user->getImage();
  5122.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5123.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5124.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5125.                     $buddybeeBalance $user->getAccountBalance();
  5126.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5127.                     $userDefaultRoute 'applicant_dashboard';
  5128. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5129.                     $userAppIds = [];
  5130.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5131.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5132.                     if ($userAppIds == null$userAppIds = [];
  5133.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5134.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5135.                     foreach ($userTypesByAppIds as $aid => $accData)
  5136.                         if (in_array($aid$userSuspendedAppIds))
  5137.                             unset($userTypesByAppIds[$aid]);
  5138.                         else
  5139.                             $userAppIds[]=$aid;
  5140. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5141.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5142.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5143.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5144.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5145.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5146.                     $loginID MiscActions::addEntityUserLoginLog(
  5147.                         $em_goc,
  5148.                         $userId,
  5149.                         $applicantId,
  5150.                         1,
  5151.                         $request->server->get("REMOTE_ADDR"),
  5152.                         0,
  5153.                         $request->request->get('deviceId'''),
  5154.                         $request->request->get('oAuthToken'''),
  5155.                         $request->request->get('oAuthType'''),
  5156.                         $request->request->get('locale'''),
  5157.                         $request->request->get('firebaseToken''')
  5158.                     );
  5159.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5160.                     // General User
  5161.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5162.                         ->findOneBy(
  5163.                             array(
  5164.                                 'userId' => $user->getUserId()
  5165.                             )
  5166.                         );
  5167.                     if ($employeeObj) {
  5168.                         $employeeId $employeeObj->getEmployeeId();
  5169.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5170.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5171.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5172.                     }
  5173.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5174.                         ->findOneBy(
  5175.                             array(
  5176.                                 'userId' => $user->getUserId(),
  5177.                                 'workingStatus' => 1
  5178.                             )
  5179.                         );
  5180.                     if ($currentTask) {
  5181.                         $currentTaskId $currentTask->getId();
  5182.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5183.                     }
  5184.                     $userId $user->getUserId();
  5185.                     $userCompanyId 1;
  5186.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5187.                     $userEmail $user->getEmail();
  5188.                     $userImage $user->getImage();
  5189.                     $userFullName $user->getName();
  5190.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5191.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5192.                     $position_list_array json_decode($user->getPositionIds(), true);
  5193.                     if ($position_list_array == null$position_list_array = [];
  5194.                     $filtered_pos_array = [];
  5195.                     foreach ($position_list_array as $defPos)
  5196.                         if ($defPos != '' && $defPos != 0)
  5197.                             $filtered_pos_array[] = $defPos;
  5198.                     $position_list_array $filtered_pos_array;
  5199.                     if (!empty($position_list_array))
  5200.                         foreach ($position_list_array as $defPos)
  5201.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5202.                                 $curr_position_id $defPos;
  5203.                             }
  5204.                     $userDefaultRoute $user->getDefaultRoute();
  5205.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5206.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5207.                         $userDefaultRoute 'dashboard';
  5208.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5209.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5210.                     if (isset($companyList[$userCompanyId])) {
  5211.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5212.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5213.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5214.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5215.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5216.                     }
  5217.                     if ($allModuleAccessFlag == 1)
  5218.                         $prohibit_list_array = [];
  5219.                     else if ($curr_position_id != 0)
  5220.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5221.                     $loginID $this->get('user_module')->addUserLoginLog(
  5222.                         $userId,
  5223.                         $request->server->get("REMOTE_ADDR"),
  5224.                         $curr_position_id
  5225.                     );
  5226.                     $appIdList json_decode($user->getUserAppIdList());
  5227.                     $branchIdList json_decode($user->getUserBranchIdList());
  5228.                     if ($branchIdList == null$branchIdList = [];
  5229.                     $branchId $user->getUserBranchId();
  5230.                     if ($appIdList == null$appIdList = [];
  5231.                     if (!in_array($user->getUserAppId(), $appIdList))
  5232.                         $appIdList[] = $user->getUserAppId();
  5233.                     foreach ($appIdList as $currAppId) {
  5234.                         if ($currAppId == $user->getUserAppId()) {
  5235.                             foreach ($company_id_list as $index_company => $company_id) {
  5236.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5237.                                 $app_company_index $currAppId '_' $company_id;
  5238.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5239.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5240.                             }
  5241.                         } else {
  5242.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5243.                                 $this->getDoctrine()->getManager('company_group'),
  5244.                                 $gocEnabled,
  5245.                                 $currAppId
  5246.                             );
  5247.                             if (!empty($dataToConnect)) {
  5248.                                 $connector $this->container->get('application_connector');
  5249.                                 $connector->resetConnection(
  5250.                                     'default',
  5251.                                     $dataToConnect['dbName'],
  5252.                                     $dataToConnect['dbUser'],
  5253.                                     $dataToConnect['dbPass'],
  5254.                                     $dataToConnect['dbHost'],
  5255.                                     $reset true
  5256.                                 );
  5257.                                 $em $this->getDoctrine()->getManager();
  5258.                                 $companyList Company::getCompanyListWithImage($em);
  5259.                                 foreach ($companyList as $c => $dta) {
  5260.                                     //                                $company_id_list[]=$c;
  5261.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5262.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5263.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5264.                                     $app_company_index $currAppId '_' $c;
  5265.                                     $company_locale $companyList[$c]['locale'];
  5266.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5267.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5268.                                 }
  5269.                             }
  5270.                         }
  5271.                     }
  5272.                     if (count($position_list_array) > 1) {
  5273.                         $userForcedRoute 'user_login_position';
  5274. //                        return $this->redirectToRoute("user_login_position");
  5275.                     } else {
  5276.                     }
  5277.                 }
  5278.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5279.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5280.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5281.                 ) {
  5282.                     $session_data = array(
  5283.                         UserConstants::USER_ID => $userId,
  5284.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5285.                         UserConstants::APPLICANT_ID => $applicantId,
  5286.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5287.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5288.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5289.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5290.                         UserConstants::SUPPLIER_ID => $supplierId,
  5291.                         UserConstants::CLIENT_ID => $clientId,
  5292.                         UserConstants::USER_TYPE => $userType,
  5293.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5294.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5295.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5296.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5297.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5298.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5299.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5300.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5301.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5302.                         UserConstants::USER_NAME => $userFullName,
  5303.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5304.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5305.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5306.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5307.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5308.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5309.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5310.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5311.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5312.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5313.                         UserConstants::USER_GOC_ID => $gocId,
  5314.                         UserConstants::USER_DB_NAME => $gocDbName,
  5315.                         UserConstants::USER_DB_USER => $gocDbUser,
  5316.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5317.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5318.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5319.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5320.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5321.                         UserConstants::USER_LOGIN_ID => $loginID,
  5322.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5323.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5324.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5325.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5326.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5327.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5328.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5329.                         'REMEMBERME' => $remember_me,
  5330.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5331.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5332.                         'oAuthToken' => $oAuthToken,
  5333.                         'locale' => $locale,
  5334.                         'firebaseToken' => $firebaseToken,
  5335.                         'token' => $session->get('token'),
  5336.                         'firstLogin' => $firstLogin,
  5337.                         'oAuthImage' => $oAuthImage,
  5338.                         'appIdList' => json_encode($appIdList),
  5339.                         'branchIdList' => json_encode($branchIdList),
  5340.                         'branchId' => $branchId,
  5341.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5342.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5343.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5344.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5345.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5346.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5347.                     );
  5348.                     if ($systemType == '_CENTRAL_') {
  5349.                         $accessList = [];
  5350. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5351.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5352.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5353.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5354.                                     $d = array(
  5355.                                         'userType' => $thisUserUserType,
  5356.                                         'globalId' => $globalId,
  5357.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5358.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5359.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5360.                                         'systemType' => '_ERP_',
  5361.                                         'companyId' => 1,
  5362.                                         'appId' => $thisUserAppId,
  5363.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5364.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5365.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5366.                                                 array(
  5367.                                                     'globalId' => $globalId,
  5368.                                                     'appId' => $thisUserAppId,
  5369.                                                     'authenticate' => 1,
  5370.                                                     'userType' => $thisUserUserType
  5371.                                                 )
  5372.                                             )
  5373.                                         ),
  5374.                                         'userCompanyList' => [
  5375.                                         ]
  5376.                                     );
  5377.                                     $accessList[] = $d;
  5378.                                 }
  5379.                             }
  5380.                         }
  5381.                         $session_data['userAccessList'] = $accessList;
  5382.                     }
  5383.                     $ultimateData System::setSessionForUser($em_goc,
  5384.                         $session,
  5385.                         $session_data,
  5386.                         $config
  5387.                     );
  5388. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5389.                     $session_data $ultimateData['sessionData'];
  5390.                     $token $ultimateData['token'];
  5391.                     $session->set('token'$token);
  5392.                     if ($systemType == '_CENTRAL_') {
  5393.                         $session->set('csToken'$token);
  5394.                     } else {
  5395.                         $session->set('csToken'$csToken);
  5396.                     }
  5397.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5398.                         $session->set('remoteVerified'1);
  5399.                         $response = new JsonResponse(array(
  5400.                             'token' => $token,
  5401.                             'uid' => $session->get(UserConstants::USER_ID),
  5402.                             'session' => $session,
  5403.                             'success' => true,
  5404.                             'session_data' => $session_data,
  5405.                         ));
  5406.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5407.                         return $response;
  5408.                     }
  5409.                     //TEMP START
  5410.                     if ($systemType == '_CENTRAL_') {
  5411.                         return $this->redirectToRoute('central_landing');
  5412.                     }
  5413.                     //TREMP END
  5414.                     if ($userForcedRoute != '')
  5415.                         return $this->redirectToRoute($userForcedRoute);
  5416.                     if ($request->request->has('referer_path')) {
  5417.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5418.                             return $this->redirect($request->request->get('referer_path'));
  5419.                         }
  5420.                     }
  5421.                     if ($request->query->has('refRoute')) {
  5422.                         if ($request->query->get('refRoute') == '8917922')
  5423.                             $userDefaultRoute 'apply_for_consultant';
  5424.                     }
  5425.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5426.                         $userDefaultRoute 'dashboard';
  5427.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5428.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5429.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5430.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5431.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5432.                                 return $this->redirect($red);
  5433.                             }
  5434.                         } else {
  5435.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5436.                         }
  5437.                     } else
  5438.                         return $this->redirectToRoute($userDefaultRoute);
  5439.                 }
  5440.             }
  5441.         }
  5442.         $session $request->getSession();
  5443.         if (isset($encData['appId'])) {
  5444.             if (isset($gocDataListByAppId[$encData['appId']]))
  5445.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5446.         }
  5447.         $routeName $request->attributes->get('_route');
  5448.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5449.             $refRoute '';
  5450.             $message '';
  5451.             $errorField '_NONE_';
  5452. //            if ($request->query->has('message')) {
  5453. //                $message = $request->query->get('message');
  5454. //
  5455. //            }
  5456. //            if ($request->query->has('errorField')) {
  5457. //                $errorField = $request->query->get('errorField');
  5458. //
  5459. //            }
  5460.             if ($refRoute != '') {
  5461.                 if ($refRoute == '8917922')
  5462.                     $redirectRoute 'apply_for_consultant';
  5463.             }
  5464.             if ($request->query->has('refRoute')) {
  5465.                 $refRoute $request->query->get('refRoute');
  5466.                 if ($refRoute == '8917922')
  5467.                     $redirectRoute 'apply_for_consultant';
  5468.             }
  5469.             $google_client = new Google_Client();
  5470. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5471. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5472.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5473.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5474.             } else {
  5475.                 $url $this->generateUrl(
  5476.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5477.                 );
  5478.             }
  5479.             $selector BuddybeeConstant::$selector;
  5480.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5481. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5482.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5483. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5484.             $google_client->setRedirectUri($url);
  5485.             $google_client->setAccessType('offline');        // offline access
  5486.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5487.             $google_client->setRedirectUri($url);
  5488.             $google_client->addScope('email');
  5489.             $google_client->addScope('profile');
  5490.             $google_client->addScope('openid');
  5491.             return $this->render(
  5492.                 '@Authentication/pages/views/applicant_login.html.twig',
  5493.                 [
  5494.                     'page_title' => 'BuddyBee Login',
  5495.                     'oAuthLink' => $google_client->createAuthUrl(),
  5496.                     'redirect_url' => $url,
  5497.                     'message' => $message,
  5498.                     'errorField' => '',
  5499.                     'systemType' => $systemType,
  5500.                     'ownServerId' => $ownServerId,
  5501.                     'refRoute' => $refRoute,
  5502.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5503.                     'selector' => $selector
  5504.                 ]
  5505.             );
  5506.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5507.             $refRoute '';
  5508.             $message '';
  5509.             $errorField '_NONE_';
  5510. //            if ($request->query->has('message')) {
  5511. //                $message = $request->query->get('message');
  5512. //
  5513. //            }
  5514. //            if ($request->query->has('errorField')) {
  5515. //                $errorField = $request->query->get('errorField');
  5516. //
  5517. //            }
  5518.             if ($refRoute != '') {
  5519.                 if ($refRoute == '8917922')
  5520.                     $redirectRoute 'apply_for_consultant';
  5521.             }
  5522.             if ($request->query->has('refRoute')) {
  5523.                 $refRoute $request->query->get('refRoute');
  5524.                 if ($refRoute == '8917922')
  5525.                     $redirectRoute 'apply_for_consultant';
  5526.             }
  5527.             $google_client = new Google_Client();
  5528. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5529. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5530.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5531.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5532.             } else {
  5533.                 $url $this->generateUrl(
  5534.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5535.                 );
  5536.             }
  5537.             $selector BuddybeeConstant::$selector;
  5538. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5539.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5540. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5541.             $google_client->setRedirectUri($url);
  5542.             $google_client->setAccessType('offline');        // offline access
  5543.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5544.             $google_client->setRedirectUri($url);
  5545.             $google_client->addScope('email');
  5546.             $google_client->addScope('profile');
  5547.             $google_client->addScope('openid');
  5548.             return $this->render(
  5549.                 '@Authentication/pages/views/central_login.html.twig',
  5550.                 [
  5551.                     'page_title' => 'Central Login',
  5552.                     'oAuthLink' => $google_client->createAuthUrl(),
  5553.                     'redirect_url' => $url,
  5554.                     'message' => $message,
  5555.                     'systemType' => $systemType,
  5556.                     'ownServerId' => $ownServerId,
  5557.                     'errorField' => '',
  5558.                     'refRoute' => $refRoute,
  5559.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5560.                     'selector' => $selector
  5561.                 ]
  5562.             );
  5563.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5564.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5565.         } else
  5566.             return $this->render(
  5567.                 '@Authentication/pages/views/login_new.html.twig',
  5568.                 array(
  5569.                     "message" => $message,
  5570.                     'page_title' => 'Login',
  5571.                     'gocList' => $gocDataListForLoginWeb,
  5572.                     'gocId' => $gocId != $gocId '',
  5573.                     'systemType' => $systemType,
  5574.                     'ownServerId' => $ownServerId,
  5575.                     'encData' => $encData,
  5576.                     //                'ref'=>$request->
  5577.                 )
  5578.             );
  5579.     }
  5580.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5581.     {
  5582.         $em $this->getDoctrine()->getManager();
  5583.         MiscActions::initiateAdminUser($em);
  5584.         $this->addFlash(
  5585.             'success',
  5586.             'The Action was Successful.'
  5587.         );
  5588.         return $this->redirectToRoute('user_login');
  5589.     }
  5590.     public function LogoutAction(Request $request$remoteVerify 0)
  5591.     {
  5592.         $session $request->getSession();
  5593.         $em_goc $this->getDoctrine()->getManager('company_group');
  5594.         $session $request->getSession();
  5595.         $token =    $request->headers->get('auth-token',$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5596. //        return new JsonResponse([$token]);
  5597.         if ($session->get(UserConstants::USER_ID0)==) {
  5598. //                    return new JsonResponse([$token]);
  5599.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5600.             if ($to_set_session_data != null) {
  5601.                 foreach ($to_set_session_data as $k => $d) {
  5602.                     //check if mobile
  5603.                     $session->set($k$d);
  5604.                 }
  5605.             } else {
  5606.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5607.             }
  5608.         }
  5609.         $userId $session->get(UserConstants::USER_ID);
  5610.         $currentTime = new \Datetime();
  5611.         $currTs $currentTime->format('U');
  5612.         $routeName $request->attributes->get('_route');
  5613.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5614.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5615.         if ($request->query->get('endCurrentTask'1) == 1) {
  5616.             if (
  5617.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5618.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5619.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5620.             ) {
  5621.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5622.                 if ($gocId != && $gocId != "") {
  5623.                     $gocDbName $session->get(UserConstants::USER_DB_NAME);
  5624.                     $gocDbUser $session->get(UserConstants::USER_DB_USER);
  5625.                     $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  5626.                     $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  5627. //                $connector = $this->container->get('application_connector');
  5628.                     $connector $this->container->get('application_connector');
  5629.                     $connector->resetConnection(
  5630.                         'default',
  5631.                         $gocDbName,
  5632.                         $gocDbUser,
  5633.                         $gocDbPass,
  5634.                         $gocDbHost,
  5635.                         $reset false);
  5636.                 }
  5637.                 $em $this->getDoctrine()->getManager();
  5638.                 $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) . ' ;');
  5639.                 
  5640.                 
  5641.                 if (1) {
  5642.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5643.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5644.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5645.                     $currTime = new \DateTime();
  5646.                     $options = array(
  5647.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5648.                         'notification_server' => $this->container->getParameter('notification_server'),
  5649.                     );
  5650.                     $positionsArray = [
  5651.                         array(
  5652.                             'employeeId' => $empId,
  5653.                             'userId' => $session->get(UserConstants::USER_ID0),
  5654.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5655.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5656.                             'lat' => 23.8623834,
  5657.                             'lng' => 90.3979294,
  5658.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5659. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5660.                         )
  5661.                     ];
  5662.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5663.                     if ($positionsArray == null$positionsArray = [];
  5664.                     $dataByAttId = [];
  5665.                     $workPlaceType '_UNSET_';
  5666.                     foreach ($positionsArray as $findex => $d) {
  5667.                         $sysUserId 0;
  5668.                         $userId 0;
  5669.                         $empId 0;
  5670.                         $dtTs 0;
  5671.                         $timeZoneStr '+0000';
  5672.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5673.                         if (isset($d['userId'])) $userId $d['userId'];
  5674.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5675.                         if (isset($d['tsMilSec'])) {
  5676.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5677.                         }
  5678.                         if ($dtTs == 0) {
  5679.                             $currTsTime = new \DateTime();
  5680.                             $dtTs $currTsTime->format('U');
  5681.                         } else {
  5682.                             $currTsTime = new \DateTime('@' $dtTs);
  5683.                         }
  5684.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5685.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5686.                         $EmployeeAttendance $this->getDoctrine()
  5687.                             ->getRepository(EmployeeAttendance::class)
  5688.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5689.                         if (!$EmployeeAttendance) {
  5690.                             continue;
  5691.                         } else {
  5692.                         }
  5693.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5694.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5695.                             $workPlaceType '_STATIC_';
  5696.                         }
  5697.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5698.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5699.                                 'attendanceInfo' => $attendanceInfo,
  5700.                                 'empId' => $empId,
  5701.                                 'lat' => 0,
  5702.                                 'lng' => 0,
  5703.                                 'address' => 0,
  5704.                                 'sysUserId' => $sysUserId,
  5705.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5706.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5707.                                 'positionArray' => []
  5708.                             );
  5709.                         $posData = array(
  5710.                             'ts' => $dtTs,
  5711.                             'lat' => $d['lat'],
  5712.                             'lng' => $d['lng'],
  5713.                             'marker' => $d['markerId'],
  5714.                             'src' => 2,
  5715.                         );
  5716.                         $posDataArray = array(
  5717.                             $dtTs,
  5718.                             $d['lat'],
  5719.                             $d['lng'],
  5720.                             $d['markerId'],
  5721.                             2
  5722.                         );
  5723.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5724.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5725.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5726.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5727.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5728.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5729.                         if (isset($d['address']))
  5730.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5731. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5732.                     }
  5733.                     $response = array(
  5734.                         'success' => true,
  5735.                     );
  5736.                     foreach ($dataByAttId as $attInfoId => $d) {
  5737.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5738.                             $d['empId'],
  5739.                             $d['sysUserId'],
  5740.                             $d['companyId'],
  5741.                             $d['appId'],
  5742.                             $request,
  5743.                             $d['attendanceInfo'],
  5744.                             $options,
  5745.                             $d['positionArray'],
  5746.                             $d['lat'],
  5747.                             $d['lng'],
  5748.                             $d['address'],
  5749.                             $d['markerId']
  5750.                         );
  5751.                     }
  5752.                 }
  5753.             }
  5754.         }
  5755.         if ($token != '')
  5756.             MiscActions::DeleteToken($em_goc$token);
  5757.         $session->clear();
  5758.         $session->set('CLEARLOGIN'1);
  5759.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5760.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5761.                 $referrerPath parse_url($request->server->get('HTTP_REFERER'), PHP_URL_PATH);
  5762.                 $referrerPath strtolower($referrerPath === false || $referrerPath === null $request->server->get('HTTP_REFERER') : $referrerPath);
  5763.                 if (strripos($referrerPath'/auth/') === false && strripos($referrerPath'undefined') === false) {
  5764.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5765.                 } else {
  5766.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5767.                 }
  5768.             }
  5769.         } else {
  5770.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5771.         }
  5772. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5773. //            )
  5774. //
  5775. //        );
  5776.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5777.             if ($userId) {
  5778.                 return new JsonResponse(array(
  5779.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5780.                     "message" => "Logout Successfull!",
  5781.                     'session_data' => [],
  5782.                     'userId' => $userId
  5783.                 ));
  5784.             } else {
  5785.                 return new JsonResponse(array(
  5786.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5787.                     "message" => "Already Logout",
  5788.                     'session_data' => [],
  5789.                     'userId' => $userId
  5790.                 ));
  5791.             }
  5792.         }
  5793.         return $this->redirectToRoute("dashboard");
  5794.     }
  5795.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5796.     {
  5797.         $session $request->getSession();
  5798.         $email $request->getSession()->get('userEmail');
  5799.         $sessionUserId $request->getSession()->get('userId');
  5800.         $oAuthData = [];
  5801. //    $encData='';
  5802.         $em $this->getDoctrine()->getManager('company_group');
  5803.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5804.         $redirectRoute 'dashboard';
  5805.         if ($encData != '') {
  5806.             if ($encData == '8917922')
  5807.                 $redirectRoute 'apply_for_consultant';
  5808.         }
  5809.         if ($request->query->has('encData')) {
  5810.             $encData $request->query->get('encData');
  5811.             if ($encData == '8917922')
  5812.                 $redirectRoute 'apply_for_consultant';
  5813.         }
  5814.         $message '';
  5815.         $errorField '_NONE_';
  5816.         if ($request->query->has('message')) {
  5817.             $message $request->query->get('message');
  5818.         }
  5819.         if ($request->query->has('errorField')) {
  5820.             $errorField $request->query->get('errorField');
  5821.         }
  5822.         if ($request->request->has('oAuthData')) {
  5823.             $oAuthData $request->request->get('oAuthData', []);
  5824.         } else {
  5825.             $oAuthData = [
  5826.                 'email' => $request->request->get('email'''),
  5827.                 'uniqueId' => $request->request->get('uniqueId'''),
  5828.                 'oAuthHash' => '_NONE_',
  5829.                 'image' => $request->request->get('image'''),
  5830.                 'emailVerified' => $request->request->get('emailVerified'''),
  5831.                 'name' => $request->request->get('name'''),
  5832.                 'firstName' => $request->request->get('firstName'''),
  5833.                 'lastName' => $request->request->get('lastName'''),
  5834.                 'type' => 1,
  5835.                 'token' => $request->request->get('oAuthtoken'''),
  5836.             ];
  5837.         }
  5838.         $isApplicantExist null;
  5839.         if ($email) {
  5840.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5841.                 $isApplicantExist $applicantRepo->findOneBy([
  5842.                     'applicantId' => $sessionUserId
  5843.                 ]);
  5844.             } else
  5845.                 return $this->redirectToRoute($redirectRoute);
  5846.         }
  5847.         $google_client = new Google_Client();
  5848. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5849. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5850.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5851.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5852.         } else {
  5853.             $url $this->generateUrl(
  5854.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5855.             );
  5856.         }
  5857.         $selector BuddybeeConstant::$selector;
  5858.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5859.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5860. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5861.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5862. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5863.         $google_client->setRedirectUri($url);
  5864.         $google_client->setAccessType('offline');        // offline access
  5865.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5866.         $google_client->addScope('email');
  5867.         $google_client->addScope('profile');
  5868.         $google_client->addScope('openid');
  5869. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5870.         //linked in 1st
  5871.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5872.             $curl curl_init();
  5873.             curl_setopt_array($curl, array(
  5874.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5875.                 CURLOPT_HEADER => false,  // don't return headers
  5876.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5877.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5878.                 CURLOPT_ENCODING => "",     // handle compressed
  5879.                 CURLOPT_USERAGENT => "test"// name of client
  5880.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5881.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5882.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5883.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5884.                 CURLOPT_USERAGENT => 'InnoPM',
  5885.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5886.                 CURLOPT_POST => 1,
  5887.                 CURLOPT_HTTPHEADER => array(
  5888.                     'Content-Type: application/x-www-form-urlencoded'
  5889.                 )
  5890.             ));
  5891.             $content curl_exec($curl);
  5892.             $contentArray = [];
  5893.             curl_close($curl);
  5894.             $token false;
  5895. //      return new JsonResponse(array(
  5896. //          'content'=>$content,
  5897. //          'contentArray'=>json_decode($content,true),
  5898. //
  5899. //      ));
  5900.             if ($content) {
  5901.                 $contentArray json_decode($contenttrue);
  5902.                 $token $contentArray['access_token'];
  5903.             }
  5904.             if ($token) {
  5905.                 $applicantInfo = [];
  5906.                 $curl curl_init();
  5907.                 curl_setopt_array($curl, array(
  5908.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5909.                     CURLOPT_HEADER => false,  // don't return headers
  5910.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5911.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5912.                     CURLOPT_ENCODING => "",     // handle compressed
  5913.                     CURLOPT_USERAGENT => "test"// name of client
  5914.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5915.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5916.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5917.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  5918.                     CURLOPT_USERAGENT => 'InnoPM',
  5919.                     CURLOPT_HTTPGET => 1,
  5920.                     CURLOPT_HTTPHEADER => array(
  5921.                         'Authorization: Bearer ' $token,
  5922.                         'Header-Key-2: Header-Value-2'
  5923.                     )
  5924.                 ));
  5925.                 $userGeneralcontent curl_exec($curl);
  5926.                 curl_close($curl);
  5927.                 if ($userGeneralcontent) {
  5928.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  5929.                 }
  5930.                 $curl curl_init();
  5931.                 curl_setopt_array($curl, array(
  5932.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5933.                     CURLOPT_HEADER => false,  // don't return headers
  5934.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5935.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5936.                     CURLOPT_ENCODING => "",     // handle compressed
  5937.                     CURLOPT_USERAGENT => "test"// name of client
  5938.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5939.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5940.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5941.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  5942. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  5943.                     CURLOPT_USERAGENT => 'InnoPM',
  5944.                     CURLOPT_HTTPGET => 1,
  5945.                     CURLOPT_HTTPHEADER => array(
  5946.                         'Authorization: Bearer ' $token,
  5947.                         'Header-Key-2: Header-Value-2'
  5948.                     )
  5949.                 ));
  5950.                 $userEmailcontent curl_exec($curl);
  5951.                 curl_close($curl);
  5952.                 $token false;
  5953.                 if ($userEmailcontent) {
  5954.                     $userEmailcontent json_decode($userEmailcontenttrue);
  5955.                 }
  5956. //        $oAuthEmail = $applicantInfo['email'];
  5957. //        return new JsonResponse(array(
  5958. //          'userEmailcontent'=>$userEmailcontent,
  5959. //          'userGeneralcontent'=>$userGeneralcontent,
  5960. //        ));
  5961. //        return new response($userGeneralcontent);
  5962.                 $oAuthData = [
  5963.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  5964.                     'uniqueId' => $userGeneralcontent['id'],
  5965.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  5966.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  5967.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  5968.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  5969.                     'lastName' => $userGeneralcontent['localizedLastName'],
  5970.                     'type' => 1,
  5971.                     'token' => $token,
  5972.                 ];
  5973.             }
  5974.         } else if (isset($_GET["code"])) {
  5975.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  5976.             if (!isset($token['error'])) {
  5977.                 $google_client->setAccessToken($token['access_token']);
  5978.                 $google_service = new Google_Service_Oauth2($google_client);
  5979.                 $applicantInfo $google_service->userinfo->get();
  5980.                 $oAuthEmail $applicantInfo['email'];
  5981.                 $oAuthData = [
  5982.                     'email' => $applicantInfo['email'],
  5983.                     'uniqueId' => $applicantInfo['id'],
  5984.                     'image' => $applicantInfo['picture'],
  5985.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  5986.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  5987.                     'firstName' => $applicantInfo['givenName'],
  5988.                     'lastName' => $applicantInfo['familyName'],
  5989.                     'type' => $token['token_type'],
  5990.                     'token' => $token['access_token'],
  5991.                 ];
  5992.             }
  5993.         }
  5994.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  5995.             $isApplicantExist $applicantRepo->findOneBy([
  5996.                 'email' => $oAuthData['email']
  5997.             ]);
  5998.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  5999.                 $isApplicantExist $applicantRepo->findOneBy([
  6000.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6001.                 ]);
  6002.             }
  6003.             if ($isApplicantExist) {
  6004.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6005.                 } else
  6006.                     return $this->redirectToRoute("core_login", [
  6007.                         'id' => $isApplicantExist->getApplicantId(),
  6008.                         'oAuthData' => $oAuthData,
  6009.                         'encData' => $encData,
  6010.                         'locale' => $request->request->get('locale''en'),
  6011.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6012.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6013.                     ]);
  6014.             } else {
  6015.                 $fname $oAuthData['firstName'];
  6016.                 $lname $oAuthData['lastName'];
  6017.                 $img $oAuthData['image'];
  6018.                 $email $oAuthData['email'];
  6019.                 $oAuthEmail $oAuthData['email'];
  6020.                 $userName explode('@'$email)[0];
  6021.                 //now check if same username exists
  6022.                 $username_already_exist 1;
  6023.                 $initial_user_name $userName;
  6024.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6025.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6026.                     $isUsernameExist $applicantRepo->findOneBy([
  6027.                         'username' => $userName
  6028.                     ]);
  6029.                     if ($isUsernameExist) {
  6030.                         $username_already_exist 1;
  6031.                         $userName $initial_user_name '' rand(3009987);
  6032.                     } else {
  6033.                         $username_already_exist 0;
  6034.                     }
  6035.                     $timeoutSafeCount--;
  6036.                 }
  6037.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6038.                     $currentUnixTimeStamp '';
  6039.                     $currentUnixTime = new \DateTime();
  6040.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6041.                     $userName $userName '' $currentUnixTimeStamp;
  6042.                 }
  6043.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6044.                 $charactersLength strlen($characters);
  6045.                 $length 8;
  6046.                 $password 0;
  6047.                 for ($i 0$i $length$i++) {
  6048.                     $password .= $characters[rand(0$charactersLength 1)];
  6049.                 }
  6050.                 $newApplicant = new EntityApplicantDetails();
  6051.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6052.                 $newApplicant->setEmail($email);
  6053.                 $newApplicant->setUserName($userName);
  6054.                 $newApplicant->setFirstname($fname);
  6055.                 $newApplicant->setLastname($lname);
  6056.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6057.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6058.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6059.                 $newApplicant->setAccountStatus(1);
  6060.                 //salt will be username
  6061. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6062.                 $salt uniqid(mt_rand());
  6063.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6064.                 $newApplicant->setPassword($encodedPassword);
  6065.                 $newApplicant->setSalt($salt);
  6066.                 $newApplicant->setTempPassword($password);
  6067. //                $newApplicant->setPassword($password);
  6068.                 $marker $userName '-' time();
  6069. //                $extension_here=$uploadedFile->guessExtension();
  6070. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6071. //                $path = $fileName;
  6072.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6073.                 if (!file_exists($upl_dir)) {
  6074.                     mkdir($upl_dir0777true);
  6075.                 }
  6076.                 $ch curl_init($img);
  6077.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6078.                 curl_setopt($chCURLOPT_FILE$fp);
  6079.                 curl_setopt($chCURLOPT_HEADER0);
  6080.                 curl_exec($ch);
  6081.                 curl_close($ch);
  6082.                 fclose($fp);
  6083.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6084. //                $newApplicant->setImage($img);
  6085.                 $newApplicant->setIsConsultant(0);
  6086.                 $newApplicant->setIsTemporaryEntry(0);
  6087.                 $newApplicant->setApplyForConsultant(0);
  6088.                 $newApplicant->setTriggerResetPassword(0);
  6089.                 $em->persist($newApplicant);
  6090.                 $em->flush();
  6091.                 $isApplicantExist $newApplicant;
  6092.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6093.                     if ($systemType == '_BUDDYBEE_') {
  6094.                         $bodyHtml '';
  6095.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6096.                         $bodyData = array(
  6097.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6098.                             'email' => $userName,
  6099.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6100.                             'password' => $newApplicant->getTempPassword(),
  6101.                         );
  6102.                         $attachments = [];
  6103.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6104. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6105.                         $new_mail $this->get('mail_module');
  6106.                         $new_mail->sendMyMail(array(
  6107.                             'senderHash' => '_CUSTOM_',
  6108.                             //                        'senderHash'=>'_CUSTOM_',
  6109.                             'forwardToMailAddress' => $forwardToMailAddress,
  6110.                             'subject' => 'Welcome to BuddyBee ',
  6111. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6112.                             'attachments' => $attachments,
  6113.                             'toAddress' => $forwardToMailAddress,
  6114.                             'fromAddress' => 'registration@buddybee.eu',
  6115.                             'userName' => 'registration@buddybee.eu',
  6116.                             'password' => 'Y41dh8g0112',
  6117.                             'smtpServer' => 'smtp.hostinger.com',
  6118.                             'smtpPort' => 465,
  6119.                             'encryptionMethod' => 'ssl',
  6120. //                            'emailBody' => $bodyHtml,
  6121.                             'mailTemplate' => $bodyTemplate,
  6122.                             'templateData' => $bodyData,
  6123. //                        'embedCompanyImage' => 1,
  6124. //                        'companyId' => $companyId,
  6125. //                        'companyImagePath' => $company_data->getImage()
  6126.                         ));
  6127.                     } else {
  6128.                         $bodyHtml '';
  6129.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6130.                         $bodyData = array(
  6131.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6132.                             'email' => 'APP-' $userName,
  6133.                             'password' => $newApplicant->getPassword(),
  6134.                         );
  6135.                         $attachments = [];
  6136.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6137. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6138.                         $new_mail $this->get('mail_module');
  6139.                         $new_mail->sendMyMail(array(
  6140.                             'senderHash' => '_CUSTOM_',
  6141.                             //                        'senderHash'=>'_CUSTOM_',
  6142.                             'forwardToMailAddress' => $forwardToMailAddress,
  6143.                             'subject' => 'Applicant Registration on Honeybee',
  6144. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6145.                             'attachments' => $attachments,
  6146.                             'toAddress' => $forwardToMailAddress,
  6147.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6148.                             'userName' => 'accounts@ourhoneybee.eu',
  6149.                             'password' => 'Honeybee@0112',
  6150.                             'smtpServer' => 'smtp.hostinger.com',
  6151.                             'smtpPort' => 465,
  6152.                             'encryptionMethod' => 'ssl',
  6153. //                            'emailBody' => $bodyHtml,
  6154.                             'mailTemplate' => $bodyTemplate,
  6155.                             'templateData' => $bodyData,
  6156. //                        'embedCompanyImage' => 1,
  6157. //                        'companyId' => $companyId,
  6158. //                        'companyImagePath' => $company_data->getImage()
  6159.                         ));
  6160.                     }
  6161.                 }
  6162.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6163.                 } else {
  6164.                     return $this->redirectToRoute("core_login", [
  6165.                         'id' => $newApplicant->getApplicantId(),
  6166.                         'oAuthData' => $oAuthData,
  6167.                         'encData' => $encData,
  6168.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6169.                         'locale' => $request->request->get('locale''en'),
  6170.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6171.                     ]);
  6172.                 }
  6173.             }
  6174.         }
  6175.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6176.             if ($isApplicantExist) {
  6177.                 $user $isApplicantExist;
  6178.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6179.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6180.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6181.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6182.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6183.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6184.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6185.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6186.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6187.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6188.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6189.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6190.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6191.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6192.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6193.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6194.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6195.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6196.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6197.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6198.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6199.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6200.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6201.                     $session->set('userCompanyVibrantList'json_encode([]));
  6202.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6203.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6204.                     $session->set(UserConstants::USER_APP_ID0);
  6205.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6206.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6207.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6208.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6209.                     $session->set(UserConstants::USER_GOC_ID0);
  6210.                     $session->set(UserConstants::USER_DB_NAME'');
  6211.                     $session->set(UserConstants::USER_DB_USER'');
  6212.                     $session->set(UserConstants::USER_DB_PASS'');
  6213.                     $session->set(UserConstants::USER_DB_HOST'');
  6214.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6215.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6216.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6217.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6218.                     $session->set('locale'$request->request->get('locale'''));
  6219.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6220.                     $route_list_array = [];
  6221.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6222.                     $loginID 0;
  6223.                     $loginID MiscActions::addEntityUserLoginLog(
  6224.                         $em,
  6225.                         $session->get(UserConstants::USER_ID),
  6226.                         $session->get(UserConstants::USER_ID),
  6227.                         1,
  6228.                         $request->server->get("REMOTE_ADDR"),
  6229.                         0,
  6230.                         $request->request->get('deviceId'''),
  6231.                         $request->request->get('oAuthToken'''),
  6232.                         $request->request->get('oAuthType'''),
  6233.                         $request->request->get('locale'''),
  6234.                         $request->request->get('firebaseToken''')
  6235.                     );
  6236.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6237.                     $session_data = array(
  6238.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6239.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6240.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6241.                         'oAuthToken' => $session->get('oAuthToken'),
  6242.                         'locale' => $session->get('locale'),
  6243.                         'firebaseToken' => $session->get('firebaseToken'),
  6244.                         'token' => $session->get('token'),
  6245.                         'firstLogin' => 0,
  6246.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6247.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6248.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6249.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6250.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6251.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6252.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6253.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6254.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6255.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6256.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6257.                         'oAuthImage' => $session->get('oAuthImage'),
  6258.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6259.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6260.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6261.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6262.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6263.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6264.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6265.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6266.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6267.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6268.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6269.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6270.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6271.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6272.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6273.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6274.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6275.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6276.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6277.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6278.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6279.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6280.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6281.                         //new
  6282.                         'appIdList' => $session->get('appIdList'),
  6283.                         'branchIdList' => $session->get('branchIdList'null),
  6284.                         'branchId' => $session->get('branchId'null),
  6285.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6286.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6287.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6288.                     );
  6289.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6290.                     $session_data $tokenData['sessionData'];
  6291.                     $token $tokenData['token'];
  6292.                     $session->set('token'$token);
  6293.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6294.                         $session->set('remoteVerified'1);
  6295.                         $response = new JsonResponse(array(
  6296.                             'token' => $token,
  6297.                             'uid' => $session->get(UserConstants::USER_ID),
  6298.                             'session' => $session,
  6299.                             'success' => true,
  6300.                             'session_data' => $session_data,
  6301.                         ));
  6302.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6303.                         return $response;
  6304.                     }
  6305.                     if ($request->request->has('referer_path')) {
  6306.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6307.                             return $this->redirect($request->request->get('referer_path'));
  6308.                         }
  6309.                     }
  6310.                     $redirectRoute 'applicant_dashboard';
  6311.                     if ($request->query->has('encData')) {
  6312.                         if ($request->query->get('encData') == '8917922')
  6313.                             $redirectRoute 'apply_for_consultant';
  6314.                     }
  6315.                     return $this->redirectToRoute($redirectRoute);
  6316.                 }
  6317. //                    $response = new JsonResponse(array(
  6318. //                        'token' => $token,
  6319. //                        'uid' => $session->get(UserConstants::USER_ID),
  6320. //                        'session' => $session,
  6321. //
  6322. //                        'success' => true,
  6323. //                        'session_data' => $session_data,
  6324. //
  6325. //                    ));
  6326. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6327. //                    return $response;
  6328. //                    return $this->redirectToRoute("user_login", [
  6329. //                        'id' => $isApplicantExist->getApplicantId(),
  6330. //                        'oAuthData' => $oAuthData,
  6331. //                        'encData' => $encData,
  6332. //                        'locale' => $request->request->get('locale', 'en'),
  6333. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6334. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6335. //                    ]);
  6336.             }
  6337.         }
  6338. //        if ($request->isMethod('POST')){
  6339. //            $new = new EntityApplicantDetails();
  6340. //
  6341. //            $new-> setUsername->$request->request->get('userName');
  6342. //            $new-> setEmail()->$request->request->get('email');
  6343. //            $new-> setPassword()->$request->request->get('password');
  6344. //            $new-> setSelector()->$request->request->get('selector');
  6345. //
  6346. //
  6347. //            $em->persist($new);
  6348. //            $em->flush();
  6349. //        }
  6350.         $selector BuddybeeConstant::$selector;
  6351.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6352.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6353.         if ($systemType == '_ERP_') {
  6354.         } else if ($systemType == '_BUDDYBEE_') {
  6355.             return $this->render(
  6356.                 '@Authentication/pages/views/applicant_login.html.twig',
  6357.                 [
  6358.                     'page_title' => 'BuddyBee Login',
  6359.                     'oAuthLink' => $google_client->createAuthUrl(),
  6360.                     'redirect_url' => $url,
  6361.                     'message' => $message,
  6362.                     'errorField' => $errorField,
  6363.                     'encData' => $encData,
  6364.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6365.                     'selector' => $selector
  6366.                 ]
  6367.             );
  6368.         }
  6369.         return $this->render(
  6370.             '@Authentication/pages/views/applicant_login.html.twig',
  6371.             [
  6372.                 'page_title' => 'Applicant Registration',
  6373.                 'oAuthLink' => $google_client->createAuthUrl(),
  6374.                 'redirect_url' => $url,
  6375.                 'encData' => $encData,
  6376.                 'message' => $message,
  6377.                 'errorField' => $errorField,
  6378.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6379.                 'selector' => $selector
  6380.             ]
  6381.         );
  6382.     }
  6383.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6384.     {
  6385.         $session $request->getSession();
  6386.         $email $request->getSession()->get('userEmail');
  6387.         $sessionUserId $request->getSession()->get('userId');
  6388.         $oAuthData = [];
  6389. //    $encData='';
  6390.         $em $this->getDoctrine()->getManager('company_group');
  6391.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6392.         $redirectRoute 'dashboard';
  6393.         if ($encData != '') {
  6394.             if ($encData == '8917922')
  6395.                 $redirectRoute 'apply_for_consultant';
  6396.         }
  6397.         if ($request->query->has('encData')) {
  6398.             $encData $request->query->get('encData');
  6399.             if ($encData == '8917922')
  6400.                 $redirectRoute 'apply_for_consultant';
  6401.         }
  6402.         $message '';
  6403.         $errorField '_NONE_';
  6404.         if ($request->query->has('message')) {
  6405.             $message $request->query->get('message');
  6406.         }
  6407.         if ($request->query->has('errorField')) {
  6408.             $errorField $request->query->get('errorField');
  6409.         }
  6410.         if ($request->request->has('oAuthData')) {
  6411.             $oAuthData $request->request->get('oAuthData', []);
  6412.         } else {
  6413.             $oAuthData = [
  6414.                 'email' => $request->request->get('email'''),
  6415.                 'uniqueId' => $request->request->get('uniqueId'''),
  6416.                 'oAuthHash' => '_NONE_',
  6417.                 'image' => $request->request->get('image'''),
  6418.                 'emailVerified' => $request->request->get('emailVerified'''),
  6419.                 'name' => $request->request->get('name'''),
  6420.                 'firstName' => $request->request->get('firstName'''),
  6421.                 'lastName' => $request->request->get('lastName'''),
  6422.                 'type' => 1,
  6423.                 'token' => $request->request->get('oAuthtoken'''),
  6424.             ];
  6425.         }
  6426.         $isApplicantExist null;
  6427.         if ($email) {
  6428.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6429.                 $isApplicantExist $applicantRepo->findOneBy([
  6430.                     'applicantId' => $sessionUserId
  6431.                 ]);
  6432.             } else
  6433.                 return $this->redirectToRoute($redirectRoute);
  6434.         }
  6435.         $google_client = new Google_Client();
  6436. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6437. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6438.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6439.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6440.         } else {
  6441.             $url $this->generateUrl(
  6442.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6443.             );
  6444.         }
  6445.         $selector BuddybeeConstant::$selector;
  6446.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6447.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6448. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6449. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6450.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6451. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6452.         $google_client->setRedirectUri($url);
  6453.         $google_client->setAccessType('offline');        // offline access
  6454.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6455.         $google_client->addScope('email');
  6456.         $google_client->addScope('profile');
  6457.         $google_client->addScope('openid');
  6458. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6459.         //linked in 1st
  6460.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6461.             $curl curl_init();
  6462.             curl_setopt_array($curl, array(
  6463.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6464.                 CURLOPT_HEADER => false,  // don't return headers
  6465.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6466.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6467.                 CURLOPT_ENCODING => "",     // handle compressed
  6468.                 CURLOPT_USERAGENT => "test"// name of client
  6469.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6470.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6471.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6472.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6473.                 CURLOPT_USERAGENT => 'InnoPM',
  6474.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6475.                 CURLOPT_POST => 1,
  6476.                 CURLOPT_HTTPHEADER => array(
  6477.                     'Content-Type: application/x-www-form-urlencoded'
  6478.                 )
  6479.             ));
  6480.             $content curl_exec($curl);
  6481.             $contentArray = [];
  6482.             curl_close($curl);
  6483.             $token false;
  6484. //      return new JsonResponse(array(
  6485. //          'content'=>$content,
  6486. //          'contentArray'=>json_decode($content,true),
  6487. //
  6488. //      ));
  6489.             if ($content) {
  6490.                 $contentArray json_decode($contenttrue);
  6491.                 $token $contentArray['access_token'];
  6492.             }
  6493.             if ($token) {
  6494.                 $applicantInfo = [];
  6495.                 $curl curl_init();
  6496.                 curl_setopt_array($curl, array(
  6497.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6498.                     CURLOPT_HEADER => false,  // don't return headers
  6499.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6500.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6501.                     CURLOPT_ENCODING => "",     // handle compressed
  6502.                     CURLOPT_USERAGENT => "test"// name of client
  6503.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6504.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6505.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6506.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6507.                     CURLOPT_USERAGENT => 'InnoPM',
  6508.                     CURLOPT_HTTPGET => 1,
  6509.                     CURLOPT_HTTPHEADER => array(
  6510.                         'Authorization: Bearer ' $token,
  6511.                         'Header-Key-2: Header-Value-2'
  6512.                     )
  6513.                 ));
  6514.                 $userGeneralcontent curl_exec($curl);
  6515.                 curl_close($curl);
  6516.                 if ($userGeneralcontent) {
  6517.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6518.                 }
  6519.                 $curl curl_init();
  6520.                 curl_setopt_array($curl, array(
  6521.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6522.                     CURLOPT_HEADER => false,  // don't return headers
  6523.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6524.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6525.                     CURLOPT_ENCODING => "",     // handle compressed
  6526.                     CURLOPT_USERAGENT => "test"// name of client
  6527.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6528.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6529.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6530.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6531. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6532.                     CURLOPT_USERAGENT => 'InnoPM',
  6533.                     CURLOPT_HTTPGET => 1,
  6534.                     CURLOPT_HTTPHEADER => array(
  6535.                         'Authorization: Bearer ' $token,
  6536.                         'Header-Key-2: Header-Value-2'
  6537.                     )
  6538.                 ));
  6539.                 $userEmailcontent curl_exec($curl);
  6540.                 curl_close($curl);
  6541.                 $token false;
  6542.                 if ($userEmailcontent) {
  6543.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6544.                 }
  6545. //        $oAuthEmail = $applicantInfo['email'];
  6546. //        return new JsonResponse(array(
  6547. //          'userEmailcontent'=>$userEmailcontent,
  6548. //          'userGeneralcontent'=>$userGeneralcontent,
  6549. //        ));
  6550. //        return new response($userGeneralcontent);
  6551.                 $oAuthData = [
  6552.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6553.                     'uniqueId' => $userGeneralcontent['id'],
  6554.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6555.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6556.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6557.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6558.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6559.                     'type' => 1,
  6560.                     'token' => $token,
  6561.                 ];
  6562.             }
  6563.         } else if (isset($_GET["code"])) {
  6564.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6565.             if (!isset($token['error'])) {
  6566.                 $google_client->setAccessToken($token['access_token']);
  6567.                 $google_service = new Google_Service_Oauth2($google_client);
  6568.                 $applicantInfo $google_service->userinfo->get();
  6569.                 $oAuthEmail $applicantInfo['email'];
  6570.                 $oAuthData = [
  6571.                     'email' => $applicantInfo['email'],
  6572.                     'uniqueId' => $applicantInfo['id'],
  6573.                     'image' => $applicantInfo['picture'],
  6574.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6575.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6576.                     'firstName' => $applicantInfo['givenName'],
  6577.                     'lastName' => $applicantInfo['familyName'],
  6578.                     'type' => $token['token_type'],
  6579.                     'token' => $token['access_token'],
  6580.                 ];
  6581.             }
  6582.         } else if (isset($_GET["access_token"])) {
  6583.             $token $_GET["access_token"];
  6584.             $tokenType $_GET["token_type"];
  6585.             if (!isset($token['error'])) {
  6586.                 $google_client->setAccessToken($token);
  6587.                 $google_service = new Google_Service_Oauth2($google_client);
  6588.                 $applicantInfo $google_service->userinfo->get();
  6589.                 $oAuthEmail $applicantInfo['email'];
  6590.                 $oAuthData = [
  6591.                     'email' => $applicantInfo['email'],
  6592.                     'uniqueId' => $applicantInfo['id'],
  6593.                     'image' => $applicantInfo['picture'],
  6594.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6595.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6596.                     'firstName' => $applicantInfo['givenName'],
  6597.                     'lastName' => $applicantInfo['familyName'],
  6598.                     'type' => $tokenType,
  6599.                     'token' => $token,
  6600.                 ];
  6601.             }
  6602.         }
  6603.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6604.             $isApplicantExist $applicantRepo->findOneBy([
  6605.                 'email' => $oAuthData['email']
  6606.             ]);
  6607.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6608.                 $isApplicantExist $applicantRepo->findOneBy([
  6609.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6610.                 ]);
  6611.             }
  6612.             if (!$isApplicantExist) {
  6613.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6614.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6615.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6616.                     ->getQuery()
  6617.                     ->getResult();
  6618.                 if (!empty($usersQueried))
  6619.                     $isApplicantExist $usersQueried[0];
  6620.             }
  6621.             if ($isApplicantExist) {
  6622.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6623.                 } else
  6624.                     return $this->redirectToRoute("core_login", [
  6625.                         'id' => $isApplicantExist->getApplicantId(),
  6626.                         'oAuthData' => $oAuthData,
  6627.                         'encData' => $encData,
  6628.                         'locale' => $request->request->get('locale''en'),
  6629.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6630.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6631.                     ]);
  6632.             } else {
  6633.                 $fname $oAuthData['firstName'];
  6634.                 $lname $oAuthData['lastName'];
  6635.                 $img $oAuthData['image'];
  6636.                 $email $oAuthData['email'];
  6637.                 $oAuthEmail $oAuthData['email'];
  6638.                 $userName explode('@'$email)[0];
  6639.                 //now check if same username exists
  6640.                 $username_already_exist 1;
  6641.                 $initial_user_name $userName;
  6642.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6643.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6644.                     $isUsernameExist $applicantRepo->findOneBy([
  6645.                         'username' => $userName
  6646.                     ]);
  6647.                     if ($isUsernameExist) {
  6648.                         $username_already_exist 1;
  6649.                         $userName $initial_user_name '' rand(3009987);
  6650.                     } else {
  6651.                         $username_already_exist 0;
  6652.                     }
  6653.                     $timeoutSafeCount--;
  6654.                 }
  6655.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6656.                     $currentUnixTimeStamp '';
  6657.                     $currentUnixTime = new \DateTime();
  6658.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6659.                     $userName $userName '' $currentUnixTimeStamp;
  6660.                 }
  6661.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6662.                 $charactersLength strlen($characters);
  6663.                 $length 8;
  6664.                 $password 0;
  6665.                 for ($i 0$i $length$i++) {
  6666.                     $password .= $characters[rand(0$charactersLength 1)];
  6667.                 }
  6668.                 $newApplicant = new EntityApplicantDetails();
  6669.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6670.                 $newApplicant->setEmail($email);
  6671.                 $newApplicant->setUserName($userName);
  6672.                 $newApplicant->setFirstname($fname);
  6673.                 $newApplicant->setLastname($lname);
  6674.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6675.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6676.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6677.                 $newApplicant->setAccountStatus(1);
  6678.                 $salt uniqid(mt_rand());
  6679.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6680.                 $newApplicant->setPassword($encodedPassword);
  6681.                 $newApplicant->setSalt($salt);
  6682.                 $newApplicant->setTempPassword($password);;
  6683. //                $newApplicant->setPassword($password);
  6684.                 $marker $userName '-' time();
  6685. //                $extension_here=$uploadedFile->guessExtension();
  6686. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6687. //                $path = $fileName;
  6688.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6689.                 if (!file_exists($upl_dir)) {
  6690.                     mkdir($upl_dir0777true);
  6691.                 }
  6692.                 $ch curl_init($img);
  6693.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6694.                 curl_setopt($chCURLOPT_FILE$fp);
  6695.                 curl_setopt($chCURLOPT_HEADER0);
  6696.                 curl_exec($ch);
  6697.                 curl_close($ch);
  6698.                 fclose($fp);
  6699.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6700. //                $newApplicant->setImage($img);
  6701.                 $newApplicant->setIsConsultant(0);
  6702.                 $newApplicant->setIsTemporaryEntry(0);
  6703.                 $newApplicant->setApplyForConsultant(0);
  6704.                 $em->persist($newApplicant);
  6705.                 $em->flush();
  6706.                 $isApplicantExist $newApplicant;
  6707.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6708.                     if ($systemType == '_BUDDYBEE_') {
  6709.                         $bodyHtml '';
  6710.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6711.                         $bodyData = array(
  6712.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6713.                             'email' => $userName,
  6714.                             'password' => $newApplicant->getPassword(),
  6715.                         );
  6716.                         $attachments = [];
  6717.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6718. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6719.                         $new_mail $this->get('mail_module');
  6720.                         $new_mail->sendMyMail(array(
  6721.                             'senderHash' => '_CUSTOM_',
  6722.                             //                        'senderHash'=>'_CUSTOM_',
  6723.                             'forwardToMailAddress' => $forwardToMailAddress,
  6724.                             'subject' => 'Welcome to BuddyBee ',
  6725. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6726.                             'attachments' => $attachments,
  6727.                             'toAddress' => $forwardToMailAddress,
  6728.                             'fromAddress' => 'registration@buddybee.eu',
  6729.                             'userName' => 'registration@buddybee.eu',
  6730.                             'password' => 'Y41dh8g0112',
  6731.                             'smtpServer' => 'smtp.hostinger.com',
  6732.                             'smtpPort' => 465,
  6733.                             'encryptionMethod' => 'ssl',
  6734. //                            'emailBody' => $bodyHtml,
  6735.                             'mailTemplate' => $bodyTemplate,
  6736.                             'templateData' => $bodyData,
  6737. //                        'embedCompanyImage' => 1,
  6738. //                        'companyId' => $companyId,
  6739. //                        'companyImagePath' => $company_data->getImage()
  6740.                         ));
  6741.                     } else {
  6742.                         $bodyHtml '';
  6743.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6744.                         $bodyData = array(
  6745.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6746.                             'email' => 'APP-' $userName,
  6747.                             'password' => $newApplicant->getPassword(),
  6748.                         );
  6749.                         $attachments = [];
  6750.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6751. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6752.                         $new_mail $this->get('mail_module');
  6753.                         $new_mail->sendMyMail(array(
  6754.                             'senderHash' => '_CUSTOM_',
  6755.                             //                        'senderHash'=>'_CUSTOM_',
  6756.                             'forwardToMailAddress' => $forwardToMailAddress,
  6757.                             'subject' => 'Applicant Registration on Honeybee',
  6758. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6759.                             'attachments' => $attachments,
  6760.                             'toAddress' => $forwardToMailAddress,
  6761.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6762.                             'userName' => 'accounts@ourhoneybee.eu',
  6763.                             'password' => 'Honeybee@0112',
  6764.                             'smtpServer' => 'smtp.hostinger.com',
  6765.                             'smtpPort' => 465,
  6766.                             'encryptionMethod' => 'ssl',
  6767. //                            'emailBody' => $bodyHtml,
  6768.                             'mailTemplate' => $bodyTemplate,
  6769.                             'templateData' => $bodyData,
  6770. //                        'embedCompanyImage' => 1,
  6771. //                        'companyId' => $companyId,
  6772. //                        'companyImagePath' => $company_data->getImage()
  6773.                         ));
  6774.                     }
  6775.                 }
  6776.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6777.                 } else {
  6778.                     return $this->redirectToRoute("core_login", [
  6779.                         'id' => $newApplicant->getApplicantId(),
  6780.                         'oAuthData' => $oAuthData,
  6781.                         'encData' => $encData,
  6782.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6783.                         'locale' => $request->request->get('locale''en'),
  6784.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6785.                     ]);
  6786.                 }
  6787.             }
  6788.         }
  6789.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6790.             if ($isApplicantExist) {
  6791.                 $user $isApplicantExist;
  6792.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6793.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6794.                 $globalId $user->getApplicantId();
  6795.                 $gocList $em
  6796.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6797.                     ->findBy(
  6798.                         array(//                        'active' => 1
  6799.                         )
  6800.                     );
  6801.                 $gocDataList = [];
  6802.                 $gocDataListForLoginWeb = [];
  6803.                 $gocDataListByAppId = [];
  6804.                 foreach ($gocList as $entry) {
  6805.                     $d = array(
  6806.                         'name' => $entry->getName(),
  6807.                         'image' => $entry->getImage(),
  6808.                         'id' => $entry->getId(),
  6809.                         'appId' => $entry->getAppId(),
  6810.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6811.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6812.                         'dbName' => $entry->getDbName(),
  6813.                         'dbUser' => $entry->getDbUser(),
  6814.                         'dbPass' => $entry->getDbPass(),
  6815.                         'dbHost' => $entry->getDbHost(),
  6816.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6817.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6818.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6819.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6820.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6821.                     );
  6822.                     $gocDataList[$entry->getId()] = $d;
  6823.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6824.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6825.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6826.                 }
  6827.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6828.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6829.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6830.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6831.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6832.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6833.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6834.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6835.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6836.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6837.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6838.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6839.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6840.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6841.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6842.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6843.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6844.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6845.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6846.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6847.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6848.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6849.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6850.                     $session->set('userCompanyVibrantList'json_encode([]));
  6851.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6852.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6853.                     $session->set(UserConstants::USER_APP_ID0);
  6854.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6855.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6856.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6857.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6858.                     $session->set(UserConstants::USER_GOC_ID0);
  6859.                     $session->set(UserConstants::USER_DB_NAME'');
  6860.                     $session->set(UserConstants::USER_DB_USER'');
  6861.                     $session->set(UserConstants::USER_DB_PASS'');
  6862.                     $session->set(UserConstants::USER_DB_HOST'');
  6863.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6864.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6865.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6866.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6867.                     $session->set('locale'$request->request->get('locale'''));
  6868.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6869.                     $route_list_array = [];
  6870.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6871.                     $loginID 0;
  6872.                     $loginID MiscActions::addEntityUserLoginLog(
  6873.                         $em,
  6874.                         $session->get(UserConstants::USER_ID),
  6875.                         $session->get(UserConstants::USER_ID),
  6876.                         1,
  6877.                         $request->server->get("REMOTE_ADDR"),
  6878.                         0,
  6879.                         $request->request->get('deviceId'''),
  6880.                         $request->request->get('oAuthToken'''),
  6881.                         $request->request->get('oAuthType'''),
  6882.                         $request->request->get('locale'''),
  6883.                         $request->request->get('firebaseToken''')
  6884.                     );
  6885.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6886.                     $session_data = array(
  6887.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6888.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6889.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6890.                         'oAuthToken' => $session->get('oAuthToken'),
  6891.                         'locale' => $session->get('locale'),
  6892.                         'firebaseToken' => $session->get('firebaseToken'),
  6893.                         'token' => $session->get('token'),
  6894.                         'firstLogin' => 0,
  6895.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6896.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6897.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6898.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6899.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6900.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6901.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6902.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6903.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6904.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6905.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6906.                         'oAuthImage' => $session->get('oAuthImage'),
  6907.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6908.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6909.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6910.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6911.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6912.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6913.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6914.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6915.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6916.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6917.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6918.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6919.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6920.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6921.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6922.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6923.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6924.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6925.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6926.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6927.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6928.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6929.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6930.                         //new
  6931.                         'appIdList' => $session->get('appIdList'),
  6932.                         'branchIdList' => $session->get('branchIdList'null),
  6933.                         'branchId' => $session->get('branchId'null),
  6934.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6935.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6936.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6937.                     );
  6938.                     $accessList = [];
  6939. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  6940.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  6941.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  6942.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  6943.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  6944.                                 $d = array(
  6945.                                     'userType' => $thisUserUserType,
  6946. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  6947.                                     'userTypeName' => $userTypeName,
  6948.                                     'globalId' => $globalId,
  6949.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  6950.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  6951.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  6952.                                     'systemType' => '_ERP_',
  6953.                                     'companyId' => 1,
  6954.                                     'appId' => $thisUserAppId,
  6955.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  6956.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  6957.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  6958.                                             array(
  6959.                                                 'globalId' => $globalId,
  6960.                                                 'appId' => $thisUserAppId,
  6961.                                                 'authenticate' => 1,
  6962.                                                 'userType' => $thisUserUserType,
  6963.                                                 'userTypeName' => $userTypeName
  6964.                                             )
  6965.                                         )
  6966.                                     ),
  6967.                                     'userCompanyList' => [
  6968.                                     ]
  6969.                                 );
  6970.                                 $accessList[] = $d;
  6971.                             }
  6972.                         }
  6973.                     }
  6974.                     $session_data['userAccessList'] = $accessList;
  6975.                     $session->set('userAccessList'json_encode($accessList));
  6976.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6977.                     $session_data $tokenData['sessionData'];
  6978.                     $token $tokenData['token'];
  6979.                     $session->set('token'$token);
  6980.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6981.                         $session->set('remoteVerified'1);
  6982.                         $response = new JsonResponse(array(
  6983.                             'token' => $token,
  6984.                             'uid' => $session->get(UserConstants::USER_ID),
  6985.                             'session' => $session,
  6986.                             'success' => true,
  6987.                             'session_data' => $session_data,
  6988.                         ));
  6989.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6990.                         return $response;
  6991.                     }
  6992.                     if ($request->request->has('referer_path')) {
  6993.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6994.                             return $this->redirect($request->request->get('referer_path'));
  6995.                         }
  6996.                     }
  6997.                     $redirectRoute 'applicant_dashboard';
  6998.                     if ($request->query->has('encData')) {
  6999.                         if ($request->query->get('encData') == '8917922')
  7000.                             $redirectRoute 'apply_for_consultant';
  7001.                     }
  7002.                     return $this->redirectToRoute($redirectRoute);
  7003.                 }
  7004. //                    $response = new JsonResponse(array(
  7005. //                        'token' => $token,
  7006. //                        'uid' => $session->get(UserConstants::USER_ID),
  7007. //                        'session' => $session,
  7008. //
  7009. //                        'success' => true,
  7010. //                        'session_data' => $session_data,
  7011. //
  7012. //                    ));
  7013. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7014. //                    return $response;
  7015. //                    return $this->redirectToRoute("user_login", [
  7016. //                        'id' => $isApplicantExist->getApplicantId(),
  7017. //                        'oAuthData' => $oAuthData,
  7018. //                        'encData' => $encData,
  7019. //                        'locale' => $request->request->get('locale', 'en'),
  7020. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7021. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7022. //                    ]);
  7023.             }
  7024.         }
  7025.         $selector BuddybeeConstant::$selector;
  7026.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7027.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7028.         if ($systemType == '_ERP_') {
  7029.         } else if ($systemType == '_CENTRAL_') {
  7030.             return $this->render(
  7031.                 '@Authentication/pages/views/central_login.html.twig',
  7032.                 [
  7033.                     'page_title' => 'Central Login',
  7034.                     'oAuthLink' => $google_client->createAuthUrl(),
  7035.                     'redirect_url' => $url,
  7036.                     'message' => $message,
  7037.                     'systemType' => $systemType,
  7038.                     'ownServerId' => $ownServerId,
  7039.                     'errorField' => '',
  7040.                     'encData' => $encData,
  7041.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7042.                     'selector' => $selector,
  7043.                 ]
  7044.             );
  7045.         } else if ($systemType == '_BUDDYBEE_') {
  7046.             return $this->render(
  7047.                 '@Authentication/pages/views/applicant_login.html.twig',
  7048.                 [
  7049.                     'page_title' => 'BuddyBee Login',
  7050.                     'oAuthLink' => $google_client->createAuthUrl(),
  7051.                     'redirect_url' => $url,
  7052.                     'message' => $message,
  7053.                     'errorField' => $errorField,
  7054.                     'encData' => $encData,
  7055.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7056.                     'selector' => $selector
  7057.                 ]
  7058.             );
  7059.         }
  7060.         return $this->render(
  7061.             '@Authentication/pages/views/applicant_login.html.twig',
  7062.             [
  7063.                 'page_title' => 'Applicant Registration',
  7064.                 'oAuthLink' => $google_client->createAuthUrl(),
  7065.                 'redirect_url' => $url,
  7066.                 'encData' => $encData,
  7067.                 'message' => $message,
  7068.                 'errorField' => $errorField,
  7069.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7070.                 'selector' => $selector
  7071.             ]
  7072.         );
  7073.     }
  7074.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7075.     {
  7076.         $session $request->getSession();
  7077.         $email $request->getSession()->get('userEmail');
  7078.         $sessionUserId $request->getSession()->get('userId');
  7079.         $oAuthData = [];
  7080. //    $encData='';
  7081.         $em $this->getDoctrine()->getManager('company_group');
  7082.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7083.         $redirectRoute 'dashboard';
  7084.         if ($encData != '') {
  7085.             if ($encData == '8917922')
  7086.                 $redirectRoute 'apply_for_consultant';
  7087.         }
  7088.         if ($request->query->has('encData')) {
  7089.             $encData $request->query->get('encData');
  7090.             if ($encData == '8917922')
  7091.                 $redirectRoute 'apply_for_consultant';
  7092.         }
  7093.         $message '';
  7094.         $errorField '_NONE_';
  7095.         if ($request->query->has('message')) {
  7096.             $message $request->query->get('message');
  7097.         }
  7098.         if ($request->query->has('errorField')) {
  7099.             $errorField $request->query->get('errorField');
  7100.         }
  7101.         if ($request->request->has('oAuthData')) {
  7102.             $oAuthData $request->request->get('oAuthData', []);
  7103.         } else {
  7104.             $oAuthData = [
  7105.                 'email' => $request->request->get('email'''),
  7106.                 'uniqueId' => $request->request->get('uniqueId'''),
  7107.                 'oAuthHash' => '_NONE_',
  7108.                 'image' => $request->request->get('image'''),
  7109.                 'emailVerified' => $request->request->get('emailVerified'''),
  7110.                 'name' => $request->request->get('name'''),
  7111.                 'firstName' => $request->request->get('firstName'''),
  7112.                 'lastName' => $request->request->get('lastName'''),
  7113.                 'type' => 1,
  7114.                 'token' => $request->request->get('oAuthtoken'''),
  7115.             ];
  7116.         }
  7117.         $isApplicantExist null;
  7118.         if ($email) {
  7119.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7120.                 $isApplicantExist $applicantRepo->findOneBy([
  7121.                     'applicantId' => $sessionUserId
  7122.                 ]);
  7123.             } else
  7124.                 return $this->redirectToRoute($redirectRoute);
  7125.         }
  7126.         $google_client = new Google_Client();
  7127. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7128. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7129.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7130.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7131.         } else {
  7132.             $url $this->generateUrl(
  7133.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7134.             );
  7135.         }
  7136.         $selector BuddybeeConstant::$selector;
  7137.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7138.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7139. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7140. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7141.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7142. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7143.         $google_client->setRedirectUri($url);
  7144.         $google_client->setAccessType('offline');        // offline access
  7145.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7146.         $google_client->addScope('email');
  7147.         $google_client->addScope('profile');
  7148.         $google_client->addScope('openid');
  7149. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7150.         //linked in 1st
  7151.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7152.             $curl curl_init();
  7153.             curl_setopt_array($curl, array(
  7154.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7155.                 CURLOPT_HEADER => false,  // don't return headers
  7156.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7157.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7158.                 CURLOPT_ENCODING => "",     // handle compressed
  7159.                 CURLOPT_USERAGENT => "test"// name of client
  7160.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7161.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7162.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7163.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7164.                 CURLOPT_USERAGENT => 'InnoPM',
  7165.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7166.                 CURLOPT_POST => 1,
  7167.                 CURLOPT_HTTPHEADER => array(
  7168.                     'Content-Type: application/x-www-form-urlencoded'
  7169.                 )
  7170.             ));
  7171.             $content curl_exec($curl);
  7172.             $contentArray = [];
  7173.             curl_close($curl);
  7174.             $token false;
  7175. //      return new JsonResponse(array(
  7176. //          'content'=>$content,
  7177. //          'contentArray'=>json_decode($content,true),
  7178. //
  7179. //      ));
  7180.             if ($content) {
  7181.                 $contentArray json_decode($contenttrue);
  7182.                 $token $contentArray['access_token'];
  7183.             }
  7184.             if ($token) {
  7185.                 $applicantInfo = [];
  7186.                 $curl curl_init();
  7187.                 curl_setopt_array($curl, array(
  7188.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7189.                     CURLOPT_HEADER => false,  // don't return headers
  7190.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7191.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7192.                     CURLOPT_ENCODING => "",     // handle compressed
  7193.                     CURLOPT_USERAGENT => "test"// name of client
  7194.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7195.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7196.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7197.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7198.                     CURLOPT_USERAGENT => 'InnoPM',
  7199.                     CURLOPT_HTTPGET => 1,
  7200.                     CURLOPT_HTTPHEADER => array(
  7201.                         'Authorization: Bearer ' $token,
  7202.                         'Header-Key-2: Header-Value-2'
  7203.                     )
  7204.                 ));
  7205.                 $userGeneralcontent curl_exec($curl);
  7206.                 curl_close($curl);
  7207.                 if ($userGeneralcontent) {
  7208.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7209.                 }
  7210.                 $curl curl_init();
  7211.                 curl_setopt_array($curl, array(
  7212.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7213.                     CURLOPT_HEADER => false,  // don't return headers
  7214.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7215.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7216.                     CURLOPT_ENCODING => "",     // handle compressed
  7217.                     CURLOPT_USERAGENT => "test"// name of client
  7218.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7219.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7220.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7221.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7222. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7223.                     CURLOPT_USERAGENT => 'InnoPM',
  7224.                     CURLOPT_HTTPGET => 1,
  7225.                     CURLOPT_HTTPHEADER => array(
  7226.                         'Authorization: Bearer ' $token,
  7227.                         'Header-Key-2: Header-Value-2'
  7228.                     )
  7229.                 ));
  7230.                 $userEmailcontent curl_exec($curl);
  7231.                 curl_close($curl);
  7232.                 $token false;
  7233.                 if ($userEmailcontent) {
  7234.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7235.                 }
  7236. //        $oAuthEmail = $applicantInfo['email'];
  7237. //        return new JsonResponse(array(
  7238. //          'userEmailcontent'=>$userEmailcontent,
  7239. //          'userGeneralcontent'=>$userGeneralcontent,
  7240. //        ));
  7241. //        return new response($userGeneralcontent);
  7242.                 $oAuthData = [
  7243.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7244.                     'uniqueId' => $userGeneralcontent['id'],
  7245.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7246.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7247.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7248.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7249.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7250.                     'type' => 1,
  7251.                     'token' => $token,
  7252.                 ];
  7253.             }
  7254.         } else if (isset($_GET["code"])) {
  7255.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7256.             if (!isset($token['error'])) {
  7257.                 $google_client->setAccessToken($token['access_token']);
  7258.                 $google_service = new Google_Service_Oauth2($google_client);
  7259.                 $applicantInfo $google_service->userinfo->get();
  7260.                 $oAuthEmail $applicantInfo['email'];
  7261.                 $oAuthData = [
  7262.                     'email' => $applicantInfo['email'],
  7263.                     'uniqueId' => $applicantInfo['id'],
  7264.                     'image' => $applicantInfo['picture'],
  7265.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7266.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7267.                     'firstName' => $applicantInfo['givenName'],
  7268.                     'lastName' => $applicantInfo['familyName'],
  7269.                     'type' => $token['token_type'],
  7270.                     'token' => $token['access_token'],
  7271.                 ];
  7272.             }
  7273.         } else if (isset($_GET["access_token"])) {
  7274.             $token $_GET["access_token"];
  7275.             $tokenType $_GET["token_type"];
  7276.             if (!isset($token['error'])) {
  7277.                 $google_client->setAccessToken($token);
  7278.                 $google_service = new Google_Service_Oauth2($google_client);
  7279.                 $applicantInfo $google_service->userinfo->get();
  7280.                 $oAuthEmail $applicantInfo['email'];
  7281.                 $oAuthData = [
  7282.                     'email' => $applicantInfo['email'],
  7283.                     'uniqueId' => $applicantInfo['id'],
  7284.                     'image' => $applicantInfo['picture'],
  7285.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7286.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7287.                     'firstName' => $applicantInfo['givenName'],
  7288.                     'lastName' => $applicantInfo['familyName'],
  7289.                     'type' => $tokenType,
  7290.                     'token' => $token,
  7291.                 ];
  7292.             }
  7293.         }
  7294.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7295.             $isApplicantExist $applicantRepo->findOneBy([
  7296.                 'email' => $oAuthData['email']
  7297.             ]);
  7298.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7299.                 $isApplicantExist $applicantRepo->findOneBy([
  7300.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7301.                 ]);
  7302.             }
  7303.             if (!$isApplicantExist) {
  7304.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7305.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7306.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7307.                     ->getQuery()
  7308.                     ->getResult();
  7309.                 if (!empty($usersQueried))
  7310.                     $isApplicantExist $usersQueried[0];
  7311.             }
  7312.             if ($isApplicantExist) {
  7313.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7314.                 } else
  7315.                     return $this->redirectToRoute("core_login", [
  7316.                         'id' => $isApplicantExist->getApplicantId(),
  7317.                         'oAuthData' => $oAuthData,
  7318.                         'encData' => $encData,
  7319.                         'locale' => $request->request->get('locale''en'),
  7320.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7321.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7322.                     ]);
  7323.             } else {
  7324.                 $fname $oAuthData['firstName'];
  7325.                 $lname $oAuthData['lastName'];
  7326.                 $img $oAuthData['image'];
  7327.                 $email $oAuthData['email'];
  7328.                 $oAuthEmail $oAuthData['email'];
  7329.                 $userName explode('@'$email)[0];
  7330.                 //now check if same username exists
  7331.                 $username_already_exist 1;
  7332.                 $initial_user_name $userName;
  7333.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7334.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7335.                     $isUsernameExist $applicantRepo->findOneBy([
  7336.                         'username' => $userName
  7337.                     ]);
  7338.                     if ($isUsernameExist) {
  7339.                         $username_already_exist 1;
  7340.                         $userName $initial_user_name '' rand(3009987);
  7341.                     } else {
  7342.                         $username_already_exist 0;
  7343.                     }
  7344.                     $timeoutSafeCount--;
  7345.                 }
  7346.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7347.                     $currentUnixTimeStamp '';
  7348.                     $currentUnixTime = new \DateTime();
  7349.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7350.                     $userName $userName '' $currentUnixTimeStamp;
  7351.                 }
  7352.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7353.                 $charactersLength strlen($characters);
  7354.                 $length 8;
  7355.                 $password 0;
  7356.                 for ($i 0$i $length$i++) {
  7357.                     $password .= $characters[rand(0$charactersLength 1)];
  7358.                 }
  7359.                 $newApplicant = new EntityApplicantDetails();
  7360.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7361.                 $newApplicant->setEmail($email);
  7362.                 $newApplicant->setUserName($userName);
  7363.                 $newApplicant->setFirstname($fname);
  7364.                 $newApplicant->setLastname($lname);
  7365.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7366.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7367.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7368.                 $newApplicant->setAccountStatus(1);
  7369.                 $salt uniqid(mt_rand());
  7370.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  7371.                 $newApplicant->setPassword($encodedPassword);
  7372.                 $newApplicant->setSalt($salt);
  7373.                 $newApplicant->setTempPassword($password);;
  7374. //                $newApplicant->setPassword($password);
  7375.                 $marker $userName '-' time();
  7376. //                $extension_here=$uploadedFile->guessExtension();
  7377. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7378. //                $path = $fileName;
  7379.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7380.                 if (!file_exists($upl_dir)) {
  7381.                     mkdir($upl_dir0777true);
  7382.                 }
  7383.                 $ch curl_init($img);
  7384.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7385.                 curl_setopt($chCURLOPT_FILE$fp);
  7386.                 curl_setopt($chCURLOPT_HEADER0);
  7387.                 curl_exec($ch);
  7388.                 curl_close($ch);
  7389.                 fclose($fp);
  7390.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7391. //                $newApplicant->setImage($img);
  7392.                 $newApplicant->setIsConsultant(0);
  7393.                 $newApplicant->setIsTemporaryEntry(0);
  7394.                 $newApplicant->setApplyForConsultant(0);
  7395.                 $em->persist($newApplicant);
  7396.                 $em->flush();
  7397.                 $isApplicantExist $newApplicant;
  7398.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7399.                     if ($systemType == '_BUDDYBEE_') {
  7400.                         $bodyHtml '';
  7401.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  7402.                         $bodyData = array(
  7403.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7404.                             'email' => $userName,
  7405.                             'password' => $newApplicant->getPassword(),
  7406.                         );
  7407.                         $attachments = [];
  7408.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7409. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7410.                         $new_mail $this->get('mail_module');
  7411.                         $new_mail->sendMyMail(array(
  7412.                             'senderHash' => '_CUSTOM_',
  7413.                             //                        'senderHash'=>'_CUSTOM_',
  7414.                             'forwardToMailAddress' => $forwardToMailAddress,
  7415.                             'subject' => 'Welcome to BuddyBee ',
  7416. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7417.                             'attachments' => $attachments,
  7418.                             'toAddress' => $forwardToMailAddress,
  7419.                             'fromAddress' => 'registration@buddybee.eu',
  7420.                             'userName' => 'registration@buddybee.eu',
  7421.                             'password' => 'Y41dh8g0112',
  7422.                             'smtpServer' => 'smtp.hostinger.com',
  7423.                             'smtpPort' => 465,
  7424.                             'encryptionMethod' => 'ssl',
  7425. //                            'emailBody' => $bodyHtml,
  7426.                             'mailTemplate' => $bodyTemplate,
  7427.                             'templateData' => $bodyData,
  7428. //                        'embedCompanyImage' => 1,
  7429. //                        'companyId' => $companyId,
  7430. //                        'companyImagePath' => $company_data->getImage()
  7431.                         ));
  7432.                     } else {
  7433.                         $bodyHtml '';
  7434.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  7435.                         $bodyData = array(
  7436.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7437.                             'email' => 'APP-' $userName,
  7438.                             'password' => $newApplicant->getPassword(),
  7439.                         );
  7440.                         $attachments = [];
  7441.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7442. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7443.                         $new_mail $this->get('mail_module');
  7444.                         $new_mail->sendMyMail(array(
  7445.                             'senderHash' => '_CUSTOM_',
  7446.                             //                        'senderHash'=>'_CUSTOM_',
  7447.                             'forwardToMailAddress' => $forwardToMailAddress,
  7448.                             'subject' => 'Applicant Registration on Honeybee',
  7449. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7450.                             'attachments' => $attachments,
  7451.                             'toAddress' => $forwardToMailAddress,
  7452.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7453.                             'userName' => 'accounts@ourhoneybee.eu',
  7454.                             'password' => 'Honeybee@0112',
  7455.                             'smtpServer' => 'smtp.hostinger.com',
  7456.                             'smtpPort' => 465,
  7457.                             'encryptionMethod' => 'ssl',
  7458. //                            'emailBody' => $bodyHtml,
  7459.                             'mailTemplate' => $bodyTemplate,
  7460.                             'templateData' => $bodyData,
  7461. //                        'embedCompanyImage' => 1,
  7462. //                        'companyId' => $companyId,
  7463. //                        'companyImagePath' => $company_data->getImage()
  7464.                         ));
  7465.                     }
  7466.                 }
  7467.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7468.                 } else {
  7469.                     return $this->redirectToRoute("core_login", [
  7470.                         'id' => $newApplicant->getApplicantId(),
  7471.                         'oAuthData' => $oAuthData,
  7472.                         'encData' => $encData,
  7473.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7474.                         'locale' => $request->request->get('locale''en'),
  7475.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7476.                     ]);
  7477.                 }
  7478.             }
  7479.         }
  7480.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7481.             if ($isApplicantExist) {
  7482.                 $user $isApplicantExist;
  7483.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7484.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7485.                 $globalId $user->getApplicantId();
  7486.                 $gocList $em
  7487.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7488.                     ->findBy(
  7489.                         array(//                        'active' => 1
  7490.                         )
  7491.                     );
  7492.                 $gocDataList = [];
  7493.                 $gocDataListForLoginWeb = [];
  7494.                 $gocDataListByAppId = [];
  7495.                 foreach ($gocList as $entry) {
  7496.                     $d = array(
  7497.                         'name' => $entry->getName(),
  7498.                         'image' => $entry->getImage(),
  7499.                         'id' => $entry->getId(),
  7500.                         'appId' => $entry->getAppId(),
  7501.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7502.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7503.                         'dbName' => $entry->getDbName(),
  7504.                         'dbUser' => $entry->getDbUser(),
  7505.                         'dbPass' => $entry->getDbPass(),
  7506.                         'dbHost' => $entry->getDbHost(),
  7507.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7508.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7509.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7510.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7511.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7512.                     );
  7513.                     $gocDataList[$entry->getId()] = $d;
  7514.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7515.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7516.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7517.                 }
  7518.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7519.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7520.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7521.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7522.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7523.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7524.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7525.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7526.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7527.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7528.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7529.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7530.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7531.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7532.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7533.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7534.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7535.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7536.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7537.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7538.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7539.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7540.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7541.                     $session->set('userCompanyVibrantList'json_encode([]));
  7542.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7543.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7544.                     $session->set(UserConstants::USER_APP_ID0);
  7545.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7546.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7547.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7548.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7549.                     $session->set(UserConstants::USER_GOC_ID0);
  7550.                     $session->set(UserConstants::USER_DB_NAME'');
  7551.                     $session->set(UserConstants::USER_DB_USER'');
  7552.                     $session->set(UserConstants::USER_DB_PASS'');
  7553.                     $session->set(UserConstants::USER_DB_HOST'');
  7554.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7555.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7556.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7557.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7558.                     $session->set('locale'$request->request->get('locale'''));
  7559.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7560.                     $route_list_array = [];
  7561.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7562.                     $loginID 0;
  7563.                     $loginID MiscActions::addEntityUserLoginLog(
  7564.                         $em,
  7565.                         $session->get(UserConstants::USER_ID),
  7566.                         $session->get(UserConstants::USER_ID),
  7567.                         1,
  7568.                         $request->server->get("REMOTE_ADDR"),
  7569.                         0,
  7570.                         $request->request->get('deviceId'''),
  7571.                         $request->request->get('oAuthToken'''),
  7572.                         $request->request->get('oAuthType'''),
  7573.                         $request->request->get('locale'''),
  7574.                         $request->request->get('firebaseToken''')
  7575.                     );
  7576.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7577.                     $session_data = array(
  7578.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7579.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7580.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7581.                         'oAuthToken' => $session->get('oAuthToken'),
  7582.                         'locale' => $session->get('locale'),
  7583.                         'firebaseToken' => $session->get('firebaseToken'),
  7584.                         'token' => $session->get('token'),
  7585.                         'firstLogin' => 0,
  7586.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7587.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7588.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7589.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7590.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7591.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7592.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7593.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7594.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7595.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7596.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7597.                         'oAuthImage' => $session->get('oAuthImage'),
  7598.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7599.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7600.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7601.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7602.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7603.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7604.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7605.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7606.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7607.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7608.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7609.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7610.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7611.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7612.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7613.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7614.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7615.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7616.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7617.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7618.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7619.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7620.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7621.                         //new
  7622.                         'appIdList' => $session->get('appIdList'),
  7623.                         'branchIdList' => $session->get('branchIdList'null),
  7624.                         'branchId' => $session->get('branchId'null),
  7625.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7626.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7627.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7628.                     );
  7629.                     $accessList = [];
  7630. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7631.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7632.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7633.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7634.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7635.                                 $d = array(
  7636.                                     'userType' => $thisUserUserType,
  7637. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7638.                                     'userTypeName' => $userTypeName,
  7639.                                     'globalId' => $globalId,
  7640.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7641.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7642.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7643.                                     'systemType' => '_ERP_',
  7644.                                     'companyId' => 1,
  7645.                                     'appId' => $thisUserAppId,
  7646.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7647.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7648.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7649.                                             array(
  7650.                                                 'globalId' => $globalId,
  7651.                                                 'appId' => $thisUserAppId,
  7652.                                                 'authenticate' => 1,
  7653.                                                 'userType' => $thisUserUserType,
  7654.                                                 'userTypeName' => $userTypeName
  7655.                                             )
  7656.                                         )
  7657.                                     ),
  7658.                                     'userCompanyList' => [
  7659.                                     ]
  7660.                                 );
  7661.                                 $accessList[] = $d;
  7662.                             }
  7663.                         }
  7664.                     }
  7665.                     $session_data['userAccessList'] = $accessList;
  7666.                     $session->set('userAccessList'json_encode($accessList));
  7667.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7668.                     $session_data $tokenData['sessionData'];
  7669.                     $token $tokenData['token'];
  7670.                     $session->set('token'$token);
  7671.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7672.                         $session->set('remoteVerified'1);
  7673.                         $response = new JsonResponse(array(
  7674.                             'token' => $token,
  7675.                             'uid' => $session->get(UserConstants::USER_ID),
  7676.                             'session' => $session,
  7677.                             'success' => true,
  7678.                             'session_data' => $session_data,
  7679.                         ));
  7680.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7681.                         return $response;
  7682.                     }
  7683.                     if ($request->request->has('referer_path')) {
  7684.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7685.                             return $this->redirect($request->request->get('referer_path'));
  7686.                         }
  7687.                     }
  7688.                     $redirectRoute 'applicant_dashboard';
  7689.                     if ($request->query->has('encData')) {
  7690.                         if ($request->query->get('encData') == '8917922')
  7691.                             $redirectRoute 'apply_for_consultant';
  7692.                     }
  7693.                     return $this->redirectToRoute($redirectRoute);
  7694.                 }
  7695. //                    $response = new JsonResponse(array(
  7696. //                        'token' => $token,
  7697. //                        'uid' => $session->get(UserConstants::USER_ID),
  7698. //                        'session' => $session,
  7699. //
  7700. //                        'success' => true,
  7701. //                        'session_data' => $session_data,
  7702. //
  7703. //                    ));
  7704. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7705. //                    return $response;
  7706. //                    return $this->redirectToRoute("user_login", [
  7707. //                        'id' => $isApplicantExist->getApplicantId(),
  7708. //                        'oAuthData' => $oAuthData,
  7709. //                        'encData' => $encData,
  7710. //                        'locale' => $request->request->get('locale', 'en'),
  7711. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7712. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7713. //                    ]);
  7714.             }
  7715.         }
  7716.         $selector BuddybeeConstant::$selector;
  7717.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7718.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7719.         if ($systemType == '_ERP_') {
  7720.         } else if ($systemType == '_SOPHIA_') {
  7721.             return $this->render(
  7722.                 '@Sophia/pages/views/sofia_login.html.twig',
  7723.                 [
  7724.                     'page_title' => 'Sophia Login',
  7725.                     'oAuthLink' => $google_client->createAuthUrl(),
  7726.                     'redirect_url' => $url,
  7727.                     'message' => $message,
  7728.                     'systemType' => $systemType,
  7729.                     'ownServerId' => $ownServerId,
  7730.                     'errorField' => '',
  7731.                     'encData' => $encData,
  7732.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7733.                     'selector' => $selector,
  7734.                 ]
  7735.             );
  7736.         } else if ($systemType == '_CENTRAL_') {
  7737.             return $this->render(
  7738.                 '@Authentication/pages/views/central_login.html.twig',
  7739.                 [
  7740.                     'page_title' => 'Central Login',
  7741.                     'oAuthLink' => $google_client->createAuthUrl(),
  7742.                     'redirect_url' => $url,
  7743.                     'message' => $message,
  7744.                     'systemType' => $systemType,
  7745.                     'ownServerId' => $ownServerId,
  7746.                     'errorField' => '',
  7747.                     'encData' => $encData,
  7748.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7749.                     'selector' => $selector,
  7750.                 ]
  7751.             );
  7752.         } else if ($systemType == '_BUDDYBEE_') {
  7753.             return $this->render(
  7754.                 '@Authentication/pages/views/applicant_login.html.twig',
  7755.                 [
  7756.                     'page_title' => 'BuddyBee Login',
  7757.                     'oAuthLink' => $google_client->createAuthUrl(),
  7758.                     'redirect_url' => $url,
  7759.                     'message' => $message,
  7760.                     'errorField' => $errorField,
  7761.                     'encData' => $encData,
  7762.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7763.                     'selector' => $selector
  7764.                 ]
  7765.             );
  7766.         }
  7767.         return $this->render(
  7768.             '@Authentication/pages/views/applicant_login.html.twig',
  7769.             [
  7770.                 'page_title' => 'Applicant Registration',
  7771.                 'oAuthLink' => $google_client->createAuthUrl(),
  7772.                 'redirect_url' => $url,
  7773.                 'encData' => $encData,
  7774.                 'message' => $message,
  7775.                 'errorField' => $errorField,
  7776.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7777.                 'selector' => $selector
  7778.             ]
  7779.         );
  7780.     }
  7781.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7782.     {
  7783. //        $userCategory=$request->request->has('userCategory');
  7784.         $encryptedData = [];
  7785.         $errorField '';
  7786.         $message '';
  7787.         $userType '';
  7788.         $otpExpireSecond 180;
  7789.         $otpExpireTs 0;
  7790.         $otp '';
  7791.         if ($encData != '')
  7792.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7793. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7794.         $userCategory '_BUDDYBEE_USER_';
  7795.         if (isset($encryptedData['userCategory']))
  7796.             $userCategory $encryptedData['userCategory'];
  7797.         else
  7798.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7799.         $em $this->getDoctrine()->getManager('company_group');
  7800.         $em_goc $this->getDoctrine()->getManager('company_group');
  7801.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7802.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7803.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7804.         $twigData = [];
  7805.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  7806.         $email_address $request->request->get('email''');
  7807.         $email_twig_data = [];
  7808.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7809.         if ($request->isMethod('POST')) {
  7810.             //set an otp and its expire and send mail
  7811.             $email_address $request->request->get('email');
  7812.             $userObj null;
  7813.             $userData = [];
  7814.             if ($systemType == '_ERP_') {
  7815.                 if ($userCategory == '_APPLICANT_') {
  7816.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7817.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7818.                         array(
  7819.                             'email' => $email_address
  7820.                         )
  7821.                     );
  7822.                     if ($userObj) {
  7823.                     } else {
  7824.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7825.                             array(
  7826.                                 'oAuthEmail' => $email_address
  7827.                             )
  7828.                         );
  7829.                         if ($userObj) {
  7830.                         } else {
  7831.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7832.                                 array(
  7833.                                     'username' => $email_address
  7834.                                 )
  7835.                             );
  7836.                         }
  7837.                     }
  7838.                     if ($userObj) {
  7839.                         $email_address $userObj->getEmail();
  7840.                         if ($email_address == null || $email_address == '')
  7841.                             $email_address $userObj->getOAuthEmail();
  7842.                     }
  7843. //                    triggerResetPassword:
  7844. //                    type: integer
  7845. //                          nullable: true
  7846.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7847.                     $otp $otpData['otp'];
  7848.                     $otpExpireTs $otpData['expireTs'];
  7849.                     $userObj->setOtp($otpData['otp']);
  7850.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7851.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7852.                     $em_goc->flush();
  7853.                     $userData = array(
  7854.                         'id' => $userObj->getApplicantId(),
  7855.                         'email' => $email_address,
  7856.                         'appId' => 0,
  7857. //                        'appId'=>$userObj->getUserAppId(),
  7858.                     );
  7859.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7860.                     $email_twig_data = [
  7861.                         'page_title' => 'Find Account',
  7862.                         'encryptedData' => $encryptedData,
  7863.                         'message' => $message,
  7864.                         'userType' => $userType,
  7865.                         'errorField' => $errorField,
  7866.                         'otp' => $otpData['otp'],
  7867.                         'otpExpireSecond' => $otpExpireSecond,
  7868.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7869.                         'otpExpireTs' => $otpData['expireTs'],
  7870.                         'systemType' => $systemType,
  7871.                         'userData' => $userData
  7872.                     ];
  7873.                     if ($userObj)
  7874.                         $email_twig_data['success'] = true;
  7875.                 } else {
  7876.                     $userType UserConstants::USER_TYPE_GENERAL;
  7877.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7878.                     $email_twig_data = [
  7879.                         'page_title' => 'Find Account',
  7880.                         'encryptedData' => $encryptedData,
  7881.                         'message' => $message,
  7882.                         'userType' => $userType,
  7883.                         'errorField' => $errorField,
  7884.                     ];
  7885.                 }
  7886.             } else if ($systemType == '_CENTRAL_') {
  7887.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7888.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7889.                     array(
  7890.                         'email' => $email_address
  7891.                     )
  7892.                 );
  7893.                 if ($userObj) {
  7894.                 } else {
  7895.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7896.                         array(
  7897.                             'oAuthEmail' => $email_address
  7898.                         )
  7899.                     );
  7900.                     if ($userObj) {
  7901.                     } else {
  7902.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7903.                             array(
  7904.                                 'username' => $email_address
  7905.                             )
  7906.                         );
  7907.                     }
  7908.                 }
  7909.                 if ($userObj) {
  7910.                     $email_address $userObj->getEmail();
  7911.                     if ($email_address == null || $email_address == '')
  7912.                         $email_address $userObj->getOAuthEmail();
  7913.                     //                    triggerResetPassword:
  7914. //                    type: integer
  7915. //                          nullable: true
  7916.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7917.                     $otp $otpData['otp'];
  7918.                     $otpExpireTs $otpData['expireTs'];
  7919.                     $userObj->setOtp($otpData['otp']);
  7920.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7921.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7922.                     $em_goc->flush();
  7923.                     $userData = array(
  7924.                         'id' => $userObj->getApplicantId(),
  7925.                         'email' => $email_address,
  7926.                         'appId' => 0,
  7927.                         'image' => $userObj->getImage(),
  7928.                         'firstName' => $userObj->getFirstname(),
  7929.                         'lastName' => $userObj->getLastname(),
  7930.                         'phone' => $userObj->getPhone(),
  7931. //                        'appId'=>$userObj->getUserAppId(),
  7932.                     );
  7933.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7934.                     $email_twig_data = [
  7935.                         'page_title' => 'Find Account',
  7936.                         'encryptedData' => $encryptedData,
  7937.                         'message' => $message,
  7938.                         'userType' => $userType,
  7939.                         'errorField' => $errorField,
  7940.                         'otp' => $otpData['otp'],
  7941.                         'otpExpireSecond' => $otpExpireSecond,
  7942.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7943.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  7944.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  7945.                         'otpExpireTs' => $otpData['expireTs'],
  7946.                         'systemType' => $systemType,
  7947.                         'userCategory' => $userCategory,
  7948.                         'userData' => $userData
  7949.                     ];
  7950.                     $email_twig_data['success'] = true;
  7951.                 } else {
  7952.                     $message "Oops! Could not find your account";
  7953.                     $email_twig_data['success'] = false;
  7954.                 }
  7955.             } else if ($systemType == '_BUDDYBEE_') {
  7956.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7957.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7958.                     array(
  7959.                         'email' => $email_address
  7960.                     )
  7961.                 );
  7962.                 if ($userObj) {
  7963.                 } else {
  7964.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7965.                         array(
  7966.                             'oAuthEmail' => $email_address
  7967.                         )
  7968.                     );
  7969.                     if ($userObj) {
  7970.                     } else {
  7971.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7972.                             array(
  7973.                                 'username' => $email_address
  7974.                             )
  7975.                         );
  7976.                     }
  7977.                 }
  7978.                 if ($userObj) {
  7979.                     $email_address $userObj->getEmail();
  7980.                     if ($email_address == null || $email_address == '')
  7981.                         $email_address $userObj->getOAuthEmail();
  7982.                     //                    triggerResetPassword:
  7983. //                    type: integer
  7984. //                          nullable: true
  7985.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7986.                     $otp $otpData['otp'];
  7987.                     $otpExpireTs $otpData['expireTs'];
  7988.                     $userObj->setOtp($otpData['otp']);
  7989.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7990.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7991.                     $em_goc->flush();
  7992.                     $userData = array(
  7993.                         'id' => $userObj->getApplicantId(),
  7994.                         'email' => $email_address,
  7995.                         'appId' => 0,
  7996.                         'image' => $userObj->getImage(),
  7997.                         'firstName' => $userObj->getFirstname(),
  7998.                         'lastName' => $userObj->getLastname(),
  7999.                         'phone' => $userObj->getPhone(),
  8000. //                        'appId'=>$userObj->getUserAppId(),
  8001.                     );
  8002.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8003.                     $email_twig_data = [
  8004.                         'page_title' => 'Find Account',
  8005.                         'encryptedData' => $encryptedData,
  8006.                         'message' => $message,
  8007.                         'userType' => $userType,
  8008.                         'errorField' => $errorField,
  8009.                         'otp' => $otpData['otp'],
  8010.                         'otpExpireSecond' => $otpExpireSecond,
  8011.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8012.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8013.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8014.                         'otpExpireTs' => $otpData['expireTs'],
  8015.                         'systemType' => $systemType,
  8016.                         'userCategory' => $userCategory,
  8017.                         'userData' => $userData
  8018.                     ];
  8019.                     $email_twig_data['success'] = true;
  8020.                 } else {
  8021.                     $message "Oops! Could not find your account";
  8022.                     $email_twig_data['success'] = false;
  8023.                 }
  8024.             }
  8025.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8026.                 if ($systemType == '_BUDDYBEE_') {
  8027.                     $bodyHtml '';
  8028.                     $bodyTemplate $email_twig_file;
  8029.                     $bodyData $email_twig_data;
  8030.                     $attachments = [];
  8031.                     $forwardToMailAddress $email_address;
  8032. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8033.                     $new_mail $this->get('mail_module');
  8034.                     $new_mail->sendMyMail(array(
  8035.                         'senderHash' => '_CUSTOM_',
  8036.                         //                        'senderHash'=>'_CUSTOM_',
  8037.                         'forwardToMailAddress' => $forwardToMailAddress,
  8038.                         'subject' => 'Account Verification',
  8039. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8040.                         'attachments' => $attachments,
  8041.                         'toAddress' => $forwardToMailAddress,
  8042.                         'fromAddress' => 'no-reply@buddybee.eu',
  8043.                         'userName' => 'no-reply@buddybee.eu',
  8044.                         'password' => 'Honeybee@0112',
  8045.                         'smtpServer' => 'smtp.hostinger.com',
  8046.                         'smtpPort' => 465,
  8047. //                            'emailBody' => $bodyHtml,
  8048.                         'mailTemplate' => $bodyTemplate,
  8049.                         'templateData' => $bodyData,
  8050. //                        'embedCompanyImage' => 1,
  8051. //                        'companyId' => $companyId,
  8052. //                        'companyImagePath' => $company_data->getImage()
  8053.                     ));
  8054.                 } else if ($systemType == '_CENTRAL_') {
  8055.                     $bodyHtml '';
  8056.                     $bodyTemplate $email_twig_file;
  8057.                     $bodyData $email_twig_data;
  8058.                     $attachments = [];
  8059.                     $forwardToMailAddress $email_address;
  8060. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8061.                     $new_mail $this->get('mail_module');
  8062.                     $new_mail->sendMyMail(array(
  8063.                         'senderHash' => '_CUSTOM_',
  8064.                         //                        'senderHash'=>'_CUSTOM_',
  8065.                         'forwardToMailAddress' => $forwardToMailAddress,
  8066.                         'subject' => 'Account Verification',
  8067. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8068.                         'attachments' => $attachments,
  8069.                         'toAddress' => $forwardToMailAddress,
  8070.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8071.                         'userName' => 'accounts@ourhoneybee.eu',
  8072.                         'password' => 'Honeybee@0112',
  8073.                         'smtpServer' => 'smtp.hostinger.com',
  8074.                         'smtpPort' => 465,
  8075. //                            'emailBody' => $bodyHtml,
  8076.                         'mailTemplate' => $bodyTemplate,
  8077.                         'templateData' => $bodyData,
  8078. //                        'embedCompanyImage' => 1,
  8079. //                        'companyId' => $companyId,
  8080. //                        'companyImagePath' => $company_data->getImage()
  8081.                     ));
  8082.                 } else {
  8083.                     $bodyHtml '';
  8084.                     $bodyTemplate $email_twig_file;
  8085.                     $bodyData $email_twig_data;
  8086.                     $attachments = [];
  8087.                     $forwardToMailAddress $email_address;
  8088. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8089.                     $new_mail $this->get('mail_module');
  8090.                     $new_mail->sendMyMail(array(
  8091.                         'senderHash' => '_CUSTOM_',
  8092.                         //                        'senderHash'=>'_CUSTOM_',
  8093.                         'forwardToMailAddress' => $forwardToMailAddress,
  8094.                         'subject' => 'Applicant Registration on Honeybee',
  8095. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8096.                         'attachments' => $attachments,
  8097.                         'toAddress' => $forwardToMailAddress,
  8098.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8099.                         'userName' => 'accounts@ourhoneybee.eu',
  8100.                         'password' => 'Honeybee@0112',
  8101.                         'smtpServer' => 'smtp.hostinger.com',
  8102.                         'smtpPort' => 465,
  8103.                         'emailBody' => $bodyHtml,
  8104.                         'mailTemplate' => $bodyTemplate,
  8105.                         'templateData' => $bodyData,
  8106. //                        'embedCompanyImage' => 1,
  8107. //                        'companyId' => $companyId,
  8108. //                        'companyImagePath' => $company_data->getImage()
  8109.                     ));
  8110.                 }
  8111.             }
  8112.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8113.                 if ($systemType == '_BUDDYBEE_') {
  8114.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8115.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8116.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8117.                      _APPEND_CODE_';
  8118.                     $msg str_replace($searchVal$replaceVal$msg);
  8119.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8120.                     $sendType 'all';
  8121.                     $socketUserIds = [];
  8122.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8123.                 } else {
  8124.                 }
  8125.             }
  8126.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8127.                 $response = new JsonResponse(array(
  8128.                         'templateData' => $twigData,
  8129.                         'message' => $message,
  8130. //                        "otp"=>'',
  8131.                         "otp" => $otp,
  8132.                         "otpExpireTs" => $otpExpireTs,
  8133.                         'actionData' => $email_twig_data,
  8134.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8135.                     )
  8136.                 );
  8137.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8138.                 return $response;
  8139.             } else if ($email_twig_data['success'] == true) {
  8140.                 $encData = array(
  8141.                     "userType" => $userType,
  8142.                     "otp" => '',
  8143. //                "otp"=>$otp,
  8144.                     "otpExpireTs" => $otpExpireTs,
  8145.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8146.                     "userCategory" => $userCategory,
  8147.                     "userId" => $userData['id'],
  8148.                     "systemType" => $systemType,
  8149.                     "email" => $email_address,
  8150.                 );
  8151.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8152.                 $url $this->generateUrl(
  8153.                     'verify_otp'
  8154.                 );
  8155.                 return $this->redirect($url "/" $encDataStr);
  8156. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8157. ////                    'encData'
  8158. ////                'id' => $isApplicantExist->getApplicantId(),
  8159. ////                'oAuthData' => $oAuthData,
  8160. ////                'refRoute' => $refRoute,
  8161. //                ]);
  8162.             }
  8163.         }
  8164.         if ($systemType == '_ERP_') {
  8165.             if ($userCategory == '_APPLICANT_') {
  8166.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8167.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8168.                 $twigData = [
  8169.                     'page_title' => 'Find Account',
  8170.                     'encryptedData' => $encryptedData,
  8171.                     'message' => $message,
  8172.                     'systemType' => $systemType,
  8173.                     'ownServerId' => $ownServerId,
  8174.                     'userType' => $userType,
  8175.                     'errorField' => $errorField,
  8176.                 ];
  8177.             } else {
  8178.                 $userType UserConstants::USER_TYPE_GENERAL;
  8179.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8180.                 $twigData = [
  8181.                     'page_title' => 'Find Account',
  8182.                     'encryptedData' => $encryptedData,
  8183.                     'systemType' => $systemType,
  8184.                     'ownServerId' => $ownServerId,
  8185.                     'message' => $message,
  8186.                     'userType' => $userType,
  8187.                     'errorField' => $errorField,
  8188.                 ];
  8189.             }
  8190.         } else if ($systemType == '_CENTRAL_') {
  8191.             $userType UserConstants::USER_TYPE_APPLICANT;
  8192.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8193.             $twigData = [
  8194.                 'page_title' => 'Find Account',
  8195.                 'encryptedData' => $encryptedData,
  8196.                 'systemType' => $systemType,
  8197.                 'ownServerId' => $ownServerId,
  8198.                 "otp" => '',
  8199. //                "otp"=>$otp,
  8200.                 "otpExpireTs" => $otpExpireTs,
  8201.                 'message' => $message,
  8202.                 'userType' => $userType,
  8203.                 'errorField' => $errorField,
  8204.             ];
  8205.         } else if ($systemType == '_BUDDYBEE_') {
  8206.             $userType UserConstants::USER_TYPE_APPLICANT;
  8207.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8208.             $twigData = [
  8209.                 'page_title' => 'Find Account',
  8210.                 'encryptedData' => $encryptedData,
  8211.                 "otp" => '',
  8212.                 'systemType' => $systemType,
  8213.                 'ownServerId' => $ownServerId,
  8214. //                "otp"=>$otp,
  8215.                 "otpExpireTs" => $otpExpireTs,
  8216.                 'message' => $message,
  8217.                 'userType' => $userType,
  8218.                 'errorField' => $errorField,
  8219.             ];
  8220.         }
  8221.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8222.             $response = new JsonResponse(array(
  8223.                     'templateData' => $twigData,
  8224.                     'message' => $message,
  8225.                     "otp" => '',
  8226. //                "otp"=>$otp,
  8227.                     "otpExpireTs" => $otpExpireTs,
  8228.                     'actionData' => $email_twig_data,
  8229.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8230.                 )
  8231.             );
  8232.             $response->headers->set('Access-Control-Allow-Origin''*');
  8233.             return $response;
  8234.         } else {
  8235.             return $this->render(
  8236.                 $twig_file,
  8237.                 $twigData
  8238.             );
  8239.         }
  8240.     }
  8241.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8242.     {
  8243. //        $userCategory=$request->request->has('userCategory');
  8244.         $encryptedData = [];
  8245.         $errorField '';
  8246.         $message '';
  8247.         $userType '';
  8248.         $otpExpireSecond 180;
  8249.         $otpExpireTs 0;
  8250.         $otp '';
  8251.         if ($encData != '')
  8252.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8253. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8254.         $userCategory '_BUDDYBEE_USER_';
  8255.         if (isset($encryptedData['userCategory']))
  8256.             $userCategory $encryptedData['userCategory'];
  8257.         else
  8258.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8259.         $em $this->getDoctrine()->getManager('company_group');
  8260.         $em_goc $this->getDoctrine()->getManager('company_group');
  8261.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8262.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8263.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8264.         $twigData = [];
  8265.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8266.         $email_address $request->request->get('email''');
  8267.         $email_twig_data = [];
  8268.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8269.         if ($request->isMethod('POST')) {
  8270.             //set an otp and its expire and send mail
  8271.             $email_address $request->request->get('email');
  8272.             $userObj null;
  8273.             $userData = [];
  8274.             if ($systemType == '_ERP_') {
  8275.                 if ($userCategory == '_APPLICANT_') {
  8276.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8277.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8278.                         array(
  8279.                             'email' => $email_address
  8280.                         )
  8281.                     );
  8282.                     if ($userObj) {
  8283.                     } else {
  8284.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8285.                             array(
  8286.                                 'oAuthEmail' => $email_address
  8287.                             )
  8288.                         );
  8289.                         if ($userObj) {
  8290.                         } else {
  8291.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8292.                                 array(
  8293.                                     'username' => $email_address
  8294.                                 )
  8295.                             );
  8296.                         }
  8297.                     }
  8298.                     if ($userObj) {
  8299.                         $email_address $userObj->getEmail();
  8300.                         if ($email_address == null || $email_address == '')
  8301.                             $email_address $userObj->getOAuthEmail();
  8302.                     }
  8303. //                    triggerResetPassword:
  8304. //                    type: integer
  8305. //                          nullable: true
  8306.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8307.                     $otp $otpData['otp'];
  8308.                     $otpExpireTs $otpData['expireTs'];
  8309.                     $userObj->setOtp($otpData['otp']);
  8310.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8311.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8312.                     $em_goc->flush();
  8313.                     $userData = array(
  8314.                         'id' => $userObj->getApplicantId(),
  8315.                         'email' => $email_address,
  8316.                         'appId' => 0,
  8317. //                        'appId'=>$userObj->getUserAppId(),
  8318.                     );
  8319.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8320.                     $email_twig_data = [
  8321.                         'page_title' => 'Find Account',
  8322.                         'encryptedData' => $encryptedData,
  8323.                         'message' => $message,
  8324.                         'userType' => $userType,
  8325.                         'errorField' => $errorField,
  8326.                         'otp' => $otpData['otp'],
  8327.                         'otpExpireSecond' => $otpExpireSecond,
  8328.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8329.                         'otpExpireTs' => $otpData['expireTs'],
  8330.                         'systemType' => $systemType,
  8331.                         'userData' => $userData
  8332.                     ];
  8333.                     if ($userObj)
  8334.                         $email_twig_data['success'] = true;
  8335.                 } else {
  8336.                     $userType UserConstants::USER_TYPE_GENERAL;
  8337.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8338.                     $email_twig_data = [
  8339.                         'page_title' => 'Find Account',
  8340.                         'encryptedData' => $encryptedData,
  8341.                         'message' => $message,
  8342.                         'userType' => $userType,
  8343.                         'errorField' => $errorField,
  8344.                     ];
  8345.                 }
  8346.             } else if ($systemType == '_CENTRAL_') {
  8347.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8348.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8349.                     array(
  8350.                         'email' => $email_address
  8351.                     )
  8352.                 );
  8353.                 if ($userObj) {
  8354.                 } else {
  8355.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8356.                         array(
  8357.                             'oAuthEmail' => $email_address
  8358.                         )
  8359.                     );
  8360.                     if ($userObj) {
  8361.                     } else {
  8362.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8363.                             array(
  8364.                                 'username' => $email_address
  8365.                             )
  8366.                         );
  8367.                     }
  8368.                 }
  8369.                 if ($userObj) {
  8370.                     $email_address $userObj->getEmail();
  8371.                     if ($email_address == null || $email_address == '')
  8372.                         $email_address $userObj->getOAuthEmail();
  8373.                     //                    triggerResetPassword:
  8374. //                    type: integer
  8375. //                          nullable: true
  8376.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8377.                     $otp $otpData['otp'];
  8378.                     $otpExpireTs $otpData['expireTs'];
  8379.                     $userObj->setOtp($otpData['otp']);
  8380.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8381.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8382.                     $em_goc->flush();
  8383.                     $userData = array(
  8384.                         'id' => $userObj->getApplicantId(),
  8385.                         'email' => $email_address,
  8386.                         'appId' => 0,
  8387.                         'image' => $userObj->getImage(),
  8388.                         'firstName' => $userObj->getFirstname(),
  8389.                         'lastName' => $userObj->getLastname(),
  8390.                         'phone' => $userObj->getPhone(),
  8391. //                        'appId'=>$userObj->getUserAppId(),
  8392.                     );
  8393.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8394.                     $email_twig_data = [
  8395.                         'page_title' => 'Find Account',
  8396.                         'encryptedData' => $encryptedData,
  8397.                         'message' => $message,
  8398.                         'userType' => $userType,
  8399.                         'errorField' => $errorField,
  8400.                         'otp' => $otpData['otp'],
  8401.                         'otpExpireSecond' => $otpExpireSecond,
  8402.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8403.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8404.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8405.                         'otpExpireTs' => $otpData['expireTs'],
  8406.                         'systemType' => $systemType,
  8407.                         'userCategory' => $userCategory,
  8408.                         'userData' => $userData
  8409.                     ];
  8410.                     $email_twig_data['success'] = true;
  8411.                 } else {
  8412.                     $message "Oops! Could not find your account";
  8413.                     $email_twig_data['success'] = false;
  8414.                 }
  8415.             } else if ($systemType == '_BUDDYBEE_') {
  8416.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8417.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8418.                     array(
  8419.                         'email' => $email_address
  8420.                     )
  8421.                 );
  8422.                 if ($userObj) {
  8423.                 } else {
  8424.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8425.                         array(
  8426.                             'oAuthEmail' => $email_address
  8427.                         )
  8428.                     );
  8429.                     if ($userObj) {
  8430.                     } else {
  8431.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8432.                             array(
  8433.                                 'username' => $email_address
  8434.                             )
  8435.                         );
  8436.                     }
  8437.                 }
  8438.                 if ($userObj) {
  8439.                     $email_address $userObj->getEmail();
  8440.                     if ($email_address == null || $email_address == '')
  8441.                         $email_address $userObj->getOAuthEmail();
  8442.                     //                    triggerResetPassword:
  8443. //                    type: integer
  8444. //                          nullable: true
  8445.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8446.                     $otp $otpData['otp'];
  8447.                     $otpExpireTs $otpData['expireTs'];
  8448.                     $userObj->setOtp($otpData['otp']);
  8449.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8450.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8451.                     $em_goc->flush();
  8452.                     $userData = array(
  8453.                         'id' => $userObj->getApplicantId(),
  8454.                         'email' => $email_address,
  8455.                         'appId' => 0,
  8456.                         'image' => $userObj->getImage(),
  8457.                         'firstName' => $userObj->getFirstname(),
  8458.                         'lastName' => $userObj->getLastname(),
  8459.                         'phone' => $userObj->getPhone(),
  8460. //                        'appId'=>$userObj->getUserAppId(),
  8461.                     );
  8462.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8463.                     $email_twig_data = [
  8464.                         'page_title' => 'Find Account',
  8465.                         'encryptedData' => $encryptedData,
  8466.                         'message' => $message,
  8467.                         'userType' => $userType,
  8468.                         'errorField' => $errorField,
  8469.                         'otp' => $otpData['otp'],
  8470.                         'otpExpireSecond' => $otpExpireSecond,
  8471.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8472.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8473.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8474.                         'otpExpireTs' => $otpData['expireTs'],
  8475.                         'systemType' => $systemType,
  8476.                         'userCategory' => $userCategory,
  8477.                         'userData' => $userData
  8478.                     ];
  8479.                     $email_twig_data['success'] = true;
  8480.                 } else {
  8481.                     $message "Oops! Could not find your account";
  8482.                     $email_twig_data['success'] = false;
  8483.                 }
  8484.             }
  8485.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8486.                 if ($systemType == '_BUDDYBEE_') {
  8487.                     $bodyHtml '';
  8488.                     $bodyTemplate $email_twig_file;
  8489.                     $bodyData $email_twig_data;
  8490.                     $attachments = [];
  8491.                     $forwardToMailAddress $email_address;
  8492. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8493.                     $new_mail $this->get('mail_module');
  8494.                     $new_mail->sendMyMail(array(
  8495.                         'senderHash' => '_CUSTOM_',
  8496.                         //                        'senderHash'=>'_CUSTOM_',
  8497.                         'forwardToMailAddress' => $forwardToMailAddress,
  8498.                         'subject' => 'Account Verification',
  8499. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8500.                         'attachments' => $attachments,
  8501.                         'toAddress' => $forwardToMailAddress,
  8502.                         'fromAddress' => 'no-reply@buddybee.eu',
  8503.                         'userName' => 'no-reply@buddybee.eu',
  8504.                         'password' => 'Honeybee@0112',
  8505.                         'smtpServer' => 'smtp.hostinger.com',
  8506.                         'smtpPort' => 465,
  8507. //                            'emailBody' => $bodyHtml,
  8508.                         'mailTemplate' => $bodyTemplate,
  8509.                         'templateData' => $bodyData,
  8510. //                        'embedCompanyImage' => 1,
  8511. //                        'companyId' => $companyId,
  8512. //                        'companyImagePath' => $company_data->getImage()
  8513.                     ));
  8514.                 } else if ($systemType == '_CENTRAL_') {
  8515.                     $bodyHtml '';
  8516.                     $bodyTemplate $email_twig_file;
  8517.                     $bodyData $email_twig_data;
  8518.                     $attachments = [];
  8519.                     $forwardToMailAddress $email_address;
  8520. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8521.                     $new_mail $this->get('mail_module');
  8522.                     $new_mail->sendMyMail(array(
  8523.                         'senderHash' => '_CUSTOM_',
  8524.                         //                        'senderHash'=>'_CUSTOM_',
  8525.                         'forwardToMailAddress' => $forwardToMailAddress,
  8526.                         'subject' => 'Account Verification',
  8527. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8528.                         'attachments' => $attachments,
  8529.                         'toAddress' => $forwardToMailAddress,
  8530.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8531.                         'userName' => 'accounts@ourhoneybee.eu',
  8532.                         'password' => 'Honeybee@0112',
  8533.                         'smtpServer' => 'smtp.hostinger.com',
  8534.                         'smtpPort' => 465,
  8535. //                            'emailBody' => $bodyHtml,
  8536.                         'mailTemplate' => $bodyTemplate,
  8537.                         'templateData' => $bodyData,
  8538. //                        'embedCompanyImage' => 1,
  8539. //                        'companyId' => $companyId,
  8540. //                        'companyImagePath' => $company_data->getImage()
  8541.                     ));
  8542.                 } else {
  8543.                     $bodyHtml '';
  8544.                     $bodyTemplate $email_twig_file;
  8545.                     $bodyData $email_twig_data;
  8546.                     $attachments = [];
  8547.                     $forwardToMailAddress $email_address;
  8548. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8549.                     $new_mail $this->get('mail_module');
  8550.                     $new_mail->sendMyMail(array(
  8551.                         'senderHash' => '_CUSTOM_',
  8552.                         //                        'senderHash'=>'_CUSTOM_',
  8553.                         'forwardToMailAddress' => $forwardToMailAddress,
  8554.                         'subject' => 'Applicant Registration on Honeybee',
  8555. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8556.                         'attachments' => $attachments,
  8557.                         'toAddress' => $forwardToMailAddress,
  8558.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8559.                         'userName' => 'accounts@ourhoneybee.eu',
  8560.                         'password' => 'Honeybee@0112',
  8561.                         'smtpServer' => 'smtp.hostinger.com',
  8562.                         'smtpPort' => 465,
  8563.                         'emailBody' => $bodyHtml,
  8564.                         'mailTemplate' => $bodyTemplate,
  8565.                         'templateData' => $bodyData,
  8566. //                        'embedCompanyImage' => 1,
  8567. //                        'companyId' => $companyId,
  8568. //                        'companyImagePath' => $company_data->getImage()
  8569.                     ));
  8570.                 }
  8571.             }
  8572.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8573.                 if ($systemType == '_BUDDYBEE_') {
  8574.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8575.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8576.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8577.                      _APPEND_CODE_';
  8578.                     $msg str_replace($searchVal$replaceVal$msg);
  8579.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8580.                     $sendType 'all';
  8581.                     $socketUserIds = [];
  8582.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8583.                 } else {
  8584.                 }
  8585.             }
  8586.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8587.                 $response = new JsonResponse(array(
  8588.                         'templateData' => $twigData,
  8589.                         'message' => $message,
  8590. //                        "otp"=>'',
  8591.                         "otp" => $otp,
  8592.                         "otpExpireTs" => $otpExpireTs,
  8593.                         'actionData' => $email_twig_data,
  8594.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8595.                     )
  8596.                 );
  8597.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8598.                 return $response;
  8599.             } else if ($email_twig_data['success'] == true) {
  8600.                 $encData = array(
  8601.                     "userType" => $userType,
  8602.                     "otp" => '',
  8603. //                "otp"=>$otp,
  8604.                     "otpExpireTs" => $otpExpireTs,
  8605.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8606.                     "userCategory" => $userCategory,
  8607.                     "userId" => $userData['id'],
  8608.                     "systemType" => $systemType,
  8609.                     "email" => $email_address,
  8610.                 );
  8611.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8612.                 $url $this->generateUrl(
  8613.                     'verify_otp'
  8614.                 );
  8615.                 return $this->redirect($url "/" $encDataStr);
  8616. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8617. ////                    'encData'
  8618. ////                'id' => $isApplicantExist->getApplicantId(),
  8619. ////                'oAuthData' => $oAuthData,
  8620. ////                'refRoute' => $refRoute,
  8621. //                ]);
  8622.             }
  8623.         }
  8624.         if ($systemType == '_ERP_') {
  8625.             if ($userCategory == '_APPLICANT_') {
  8626.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8627.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8628.                 $twigData = [
  8629.                     'page_title' => 'Find Account',
  8630.                     'encryptedData' => $encryptedData,
  8631.                     'message' => $message,
  8632.                     'systemType' => $systemType,
  8633.                     'ownServerId' => $ownServerId,
  8634.                     'userType' => $userType,
  8635.                     'errorField' => $errorField,
  8636.                 ];
  8637.             } else {
  8638.                 $userType UserConstants::USER_TYPE_GENERAL;
  8639.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8640.                 $twigData = [
  8641.                     'page_title' => 'Find Account',
  8642.                     'encryptedData' => $encryptedData,
  8643.                     'systemType' => $systemType,
  8644.                     'ownServerId' => $ownServerId,
  8645.                     'message' => $message,
  8646.                     'userType' => $userType,
  8647.                     'errorField' => $errorField,
  8648.                 ];
  8649.             }
  8650.         } else if ($systemType == '_SOPHIA_') {
  8651.             $userType UserConstants::USER_TYPE_APPLICANT;
  8652.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8653.             $twigData = [
  8654.                 'page_title' => 'Find Account',
  8655.                 'encryptedData' => $encryptedData,
  8656.                 'systemType' => $systemType,
  8657.                 'ownServerId' => $ownServerId,
  8658.                 "otp" => '',
  8659. //                "otp"=>$otp,
  8660.                 "otpExpireTs" => $otpExpireTs,
  8661.                 'message' => $message,
  8662.                 'userType' => $userType,
  8663.                 'errorField' => $errorField,
  8664.             ];
  8665.         } else if ($systemType == '_CENTRAL_') {
  8666.             $userType UserConstants::USER_TYPE_APPLICANT;
  8667.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8668.             $twigData = [
  8669.                 'page_title' => 'Find Account',
  8670.                 'encryptedData' => $encryptedData,
  8671.                 'systemType' => $systemType,
  8672.                 'ownServerId' => $ownServerId,
  8673.                 "otp" => '',
  8674. //                "otp"=>$otp,
  8675.                 "otpExpireTs" => $otpExpireTs,
  8676.                 'message' => $message,
  8677.                 'userType' => $userType,
  8678.                 'errorField' => $errorField,
  8679.             ];
  8680.         } else if ($systemType == '_BUDDYBEE_') {
  8681.             $userType UserConstants::USER_TYPE_APPLICANT;
  8682.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8683.             $twigData = [
  8684.                 'page_title' => 'Find Account',
  8685.                 'encryptedData' => $encryptedData,
  8686.                 "otp" => '',
  8687.                 'systemType' => $systemType,
  8688.                 'ownServerId' => $ownServerId,
  8689. //                "otp"=>$otp,
  8690.                 "otpExpireTs" => $otpExpireTs,
  8691.                 'message' => $message,
  8692.                 'userType' => $userType,
  8693.                 'errorField' => $errorField,
  8694.             ];
  8695.         }
  8696.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8697.             $response = new JsonResponse(array(
  8698.                     'templateData' => $twigData,
  8699.                     'message' => $message,
  8700.                     "otp" => '',
  8701. //                "otp"=>$otp,
  8702.                     "otpExpireTs" => $otpExpireTs,
  8703.                     'actionData' => $email_twig_data,
  8704.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8705.                 )
  8706.             );
  8707.             $response->headers->set('Access-Control-Allow-Origin''*');
  8708.             return $response;
  8709.         } else {
  8710.             return $this->render(
  8711.                 $twig_file,
  8712.                 $twigData
  8713.             );
  8714.         }
  8715.     }
  8716.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8717.     {
  8718. //        $userCategory=$request->request->has('userCategory');
  8719.         $encryptedData = [];
  8720.         $errorField '';
  8721.         $message '';
  8722.         $userType '';
  8723.         $otpExpireSecond 180;
  8724.         $otpExpireTs 0;
  8725.         $otp '';
  8726.         if ($encData != '')
  8727.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8728. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8729.         $userCategory '_BUDDYBEE_USER_';
  8730.         if (isset($encryptedData['userCategory']))
  8731.             $userCategory $encryptedData['userCategory'];
  8732.         else
  8733.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8734.         $em $this->getDoctrine()->getManager('company_group');
  8735.         $em_goc $this->getDoctrine()->getManager('company_group');
  8736.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8737.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8738.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8739.         $twigData = [];
  8740.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8741.         $email_address $request->request->get('email''');
  8742.         $email_twig_data = [];
  8743.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8744.         if ($request->isMethod('POST')) {
  8745.             //set an otp and its expire and send mail
  8746.             $email_address $request->request->get('email');
  8747.             $userObj null;
  8748.             $userData = [];
  8749.             if ($systemType == '_ERP_') {
  8750.                 if ($userCategory == '_APPLICANT_') {
  8751.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8752.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8753.                         array(
  8754.                             'email' => $email_address
  8755.                         )
  8756.                     );
  8757.                     if ($userObj) {
  8758.                     } else {
  8759.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8760.                             array(
  8761.                                 'oAuthEmail' => $email_address
  8762.                             )
  8763.                         );
  8764.                         if ($userObj) {
  8765.                         } else {
  8766.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8767.                                 array(
  8768.                                     'username' => $email_address
  8769.                                 )
  8770.                             );
  8771.                         }
  8772.                     }
  8773.                     if ($userObj) {
  8774.                         $email_address $userObj->getEmail();
  8775.                         if ($email_address == null || $email_address == '')
  8776.                             $email_address $userObj->getOAuthEmail();
  8777.                     }
  8778. //                    triggerResetPassword:
  8779. //                    type: integer
  8780. //                          nullable: true
  8781.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8782.                     $otp $otpData['otp'];
  8783.                     $otpExpireTs $otpData['expireTs'];
  8784.                     $userObj->setOtp($otpData['otp']);
  8785.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8786.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8787.                     $em_goc->flush();
  8788.                     $userData = array(
  8789.                         'id' => $userObj->getApplicantId(),
  8790.                         'email' => $email_address,
  8791.                         'appId' => 0,
  8792. //                        'appId'=>$userObj->getUserAppId(),
  8793.                     );
  8794.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8795.                     $email_twig_data = [
  8796.                         'page_title' => 'Find Account',
  8797.                         'encryptedData' => $encryptedData,
  8798.                         'message' => $message,
  8799.                         'userType' => $userType,
  8800.                         'errorField' => $errorField,
  8801.                         'otp' => $otpData['otp'],
  8802.                         'otpExpireSecond' => $otpExpireSecond,
  8803.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8804.                         'otpExpireTs' => $otpData['expireTs'],
  8805.                         'systemType' => $systemType,
  8806.                         'userData' => $userData
  8807.                     ];
  8808.                     if ($userObj)
  8809.                         $email_twig_data['success'] = true;
  8810.                 } else {
  8811.                     $userType UserConstants::USER_TYPE_GENERAL;
  8812.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8813.                     $email_twig_data = [
  8814.                         'page_title' => 'Find Account',
  8815.                         'encryptedData' => $encryptedData,
  8816.                         'message' => $message,
  8817.                         'userType' => $userType,
  8818.                         'errorField' => $errorField,
  8819.                     ];
  8820.                 }
  8821.             } else if ($systemType == '_CENTRAL_') {
  8822.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8823.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8824.                     array(
  8825.                         'email' => $email_address
  8826.                     )
  8827.                 );
  8828.                 if ($userObj) {
  8829.                 } else {
  8830.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8831.                         array(
  8832.                             'oAuthEmail' => $email_address
  8833.                         )
  8834.                     );
  8835.                     if ($userObj) {
  8836.                     } else {
  8837.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8838.                             array(
  8839.                                 'username' => $email_address
  8840.                             )
  8841.                         );
  8842.                     }
  8843.                 }
  8844.                 if ($userObj) {
  8845.                     $email_address $userObj->getEmail();
  8846.                     if ($email_address == null || $email_address == '')
  8847.                         $email_address $userObj->getOAuthEmail();
  8848.                     //                    triggerResetPassword:
  8849. //                    type: integer
  8850. //                          nullable: true
  8851.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8852.                     $otp $otpData['otp'];
  8853.                     $otpExpireTs $otpData['expireTs'];
  8854.                     $userObj->setOtp($otpData['otp']);
  8855.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8856.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8857.                     $em_goc->flush();
  8858.                     $userData = array(
  8859.                         'id' => $userObj->getApplicantId(),
  8860.                         'email' => $email_address,
  8861.                         'appId' => 0,
  8862.                         'image' => $userObj->getImage(),
  8863.                         'firstName' => $userObj->getFirstname(),
  8864.                         'lastName' => $userObj->getLastname(),
  8865.                         'phone' => $userObj->getPhone(),
  8866. //                        'appId'=>$userObj->getUserAppId(),
  8867.                     );
  8868.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8869.                     $email_twig_data = [
  8870.                         'page_title' => 'Find Account',
  8871.                         'encryptedData' => $encryptedData,
  8872.                         'message' => $message,
  8873.                         'userType' => $userType,
  8874.                         'errorField' => $errorField,
  8875.                         'otp' => $otpData['otp'],
  8876.                         'otpExpireSecond' => $otpExpireSecond,
  8877.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8878.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8879.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8880.                         'otpExpireTs' => $otpData['expireTs'],
  8881.                         'systemType' => $systemType,
  8882.                         'userCategory' => $userCategory,
  8883.                         'userData' => $userData
  8884.                     ];
  8885.                     $email_twig_data['success'] = true;
  8886.                 } else {
  8887.                     $message "Oops! Could not find your account";
  8888.                     $email_twig_data['success'] = false;
  8889.                 }
  8890.             }
  8891.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8892.                 if ($systemType == '_CENTRAL_') {
  8893.                     $bodyHtml '';
  8894.                     $bodyTemplate $email_twig_file;
  8895.                     $bodyData $email_twig_data;
  8896.                     $attachments = [];
  8897.                     $forwardToMailAddress $email_address;
  8898. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8899.                     $new_mail $this->get('mail_module');
  8900.                     $new_mail->sendMyMail(array(
  8901.                         'senderHash' => '_CUSTOM_',
  8902.                         //                        'senderHash'=>'_CUSTOM_',
  8903.                         'forwardToMailAddress' => $forwardToMailAddress,
  8904.                         'subject' => 'Account Verification',
  8905. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8906.                         'attachments' => $attachments,
  8907.                         'toAddress' => $forwardToMailAddress,
  8908.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8909.                         'userName' => 'accounts@ourhoneybee.eu',
  8910.                         'password' => 'Honeybee@0112',
  8911.                         'smtpServer' => 'smtp.hostinger.com',
  8912.                         'smtpPort' => 465,
  8913. //                            'emailBody' => $bodyHtml,
  8914.                         'mailTemplate' => $bodyTemplate,
  8915.                         'templateData' => $bodyData,
  8916. //                        'embedCompanyImage' => 1,
  8917. //                        'companyId' => $companyId,
  8918. //                        'companyImagePath' => $company_data->getImage()
  8919.                     ));
  8920.                 } else {
  8921.                     $bodyHtml '';
  8922.                     $bodyTemplate $email_twig_file;
  8923.                     $bodyData $email_twig_data;
  8924.                     $attachments = [];
  8925.                     $forwardToMailAddress $email_address;
  8926. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8927.                     $new_mail $this->get('mail_module');
  8928.                     $new_mail->sendMyMail(array(
  8929.                         'senderHash' => '_CUSTOM_',
  8930.                         //                        'senderHash'=>'_CUSTOM_',
  8931.                         'forwardToMailAddress' => $forwardToMailAddress,
  8932.                         'subject' => 'Applicant Registration on Honeybee',
  8933. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8934.                         'attachments' => $attachments,
  8935.                         'toAddress' => $forwardToMailAddress,
  8936.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8937.                         'userName' => 'accounts@ourhoneybee.eu',
  8938.                         'password' => 'Honeybee@0112',
  8939.                         'smtpServer' => 'smtp.hostinger.com',
  8940.                         'smtpPort' => 465,
  8941.                         'emailBody' => $bodyHtml,
  8942.                         'mailTemplate' => $bodyTemplate,
  8943.                         'templateData' => $bodyData,
  8944. //                        'embedCompanyImage' => 1,
  8945. //                        'companyId' => $companyId,
  8946. //                        'companyImagePath' => $company_data->getImage()
  8947.                     ));
  8948.                 }
  8949.             }
  8950.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8951.                 if ($systemType == '_BUDDYBEE_') {
  8952.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8953.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8954.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8955.                      _APPEND_CODE_';
  8956.                     $msg str_replace($searchVal$replaceVal$msg);
  8957.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8958.                     $sendType 'all';
  8959.                     $socketUserIds = [];
  8960.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8961.                 } else {
  8962.                 }
  8963.             }
  8964.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8965.                 $response = new JsonResponse(array(
  8966.                         'templateData' => $twigData,
  8967.                         'message' => $message,
  8968. //                        "otp"=>'',
  8969.                         "otp" => $otp,
  8970.                         "otpExpireTs" => $otpExpireTs,
  8971.                         'actionData' => $email_twig_data,
  8972.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8973.                     )
  8974.                 );
  8975.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8976.                 return $response;
  8977.             } else if ($email_twig_data['success'] == true) {
  8978.                 $encData = array(
  8979.                     "userType" => $userType,
  8980.                     "otp" => '',
  8981. //                "otp"=>$otp,
  8982.                     "otpExpireTs" => $otpExpireTs,
  8983.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8984.                     "userCategory" => $userCategory,
  8985.                     "userId" => $userData['id'],
  8986.                     "systemType" => $systemType,
  8987.                     "email" => $email_address,
  8988.                 );
  8989.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8990.                 $url $this->generateUrl(
  8991.                     'verify_otp'
  8992.                 );
  8993.                 return $this->redirect($url "/" $encDataStr);
  8994. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8995. ////                    'encData'
  8996. ////                'id' => $isApplicantExist->getApplicantId(),
  8997. ////                'oAuthData' => $oAuthData,
  8998. ////                'refRoute' => $refRoute,
  8999. //                ]);
  9000.             }
  9001.         }
  9002.         if ($systemType == '_ERP_') {
  9003.             if ($userCategory == '_APPLICANT_') {
  9004.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9005.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9006.                 $twigData = [
  9007.                     'page_title' => 'Find Account',
  9008.                     'encryptedData' => $encryptedData,
  9009.                     'message' => $message,
  9010.                     'systemType' => $systemType,
  9011.                     'ownServerId' => $ownServerId,
  9012.                     'userType' => $userType,
  9013.                     'errorField' => $errorField,
  9014.                 ];
  9015.             } else {
  9016.                 $userType UserConstants::USER_TYPE_GENERAL;
  9017.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9018.                 $twigData = [
  9019.                     'page_title' => 'Find Account',
  9020.                     'encryptedData' => $encryptedData,
  9021.                     'systemType' => $systemType,
  9022.                     'ownServerId' => $ownServerId,
  9023.                     'message' => $message,
  9024.                     'userType' => $userType,
  9025.                     'errorField' => $errorField,
  9026.                 ];
  9027.             }
  9028.         } else if ($systemType == '_CENTRAL_') {
  9029.             $userType UserConstants::USER_TYPE_APPLICANT;
  9030.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9031.             $twigData = [
  9032.                 'page_title' => 'Find Account',
  9033.                 'encryptedData' => $encryptedData,
  9034.                 'systemType' => $systemType,
  9035.                 'ownServerId' => $ownServerId,
  9036.                 "otp" => '',
  9037. //                "otp"=>$otp,
  9038.                 "otpExpireTs" => $otpExpireTs,
  9039.                 'message' => $message,
  9040.                 'userType' => $userType,
  9041.                 'errorField' => $errorField,
  9042.             ];
  9043.         } else if ($systemType == '_BUDDYBEE_') {
  9044.             $userType UserConstants::USER_TYPE_APPLICANT;
  9045.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9046.             $twigData = [
  9047.                 'page_title' => 'Find Account',
  9048.                 'encryptedData' => $encryptedData,
  9049.                 "otp" => '',
  9050.                 'systemType' => $systemType,
  9051.                 'ownServerId' => $ownServerId,
  9052. //                "otp"=>$otp,
  9053.                 "otpExpireTs" => $otpExpireTs,
  9054.                 'message' => $message,
  9055.                 'userType' => $userType,
  9056.                 'errorField' => $errorField,
  9057.             ];
  9058.         }
  9059.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9060.             $response = new JsonResponse(array(
  9061.                     'templateData' => $twigData,
  9062.                     'message' => $message,
  9063.                     "otp" => '',
  9064. //                "otp"=>$otp,
  9065.                     "otpExpireTs" => $otpExpireTs,
  9066.                     'actionData' => $email_twig_data,
  9067.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9068.                 )
  9069.             );
  9070.             $response->headers->set('Access-Control-Allow-Origin''*');
  9071.             return $response;
  9072.         } else {
  9073.             return $this->render(
  9074.                 $twig_file,
  9075.                 $twigData
  9076.             );
  9077.         }
  9078.     }
  9079.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9080.     {
  9081. //        $userCategory=$request->request->has('userCategory');
  9082.         $encryptedData = [];
  9083.         $errorField '';
  9084.         $message '';
  9085.         $userType '';
  9086.         $otpExpireSecond 180;
  9087.         $otpExpireTs 0;
  9088.         if ($encData != '')
  9089.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9090. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9091.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9092.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9093.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9094.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9095.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9096.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9097.         $em $this->getDoctrine()->getManager('company_group');
  9098.         $em_goc $this->getDoctrine()->getManager('company_group');
  9099.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9100.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9101.         $twigData = [];
  9102.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  9103.         $email_twig_data = [];
  9104.         $userData = [];
  9105.         if ($request->isMethod('POST') || $otp != '') {
  9106.             $otp $request->request->get('otp'$otp);
  9107.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9108.             $userId $request->request->get('userId'$userId);
  9109.             $userCategory $request->request->get('userCategory'$userCategory);
  9110.             $email_address $request->request->get('email'$email);
  9111.             if ($systemType == '_ERP_') {
  9112.                 if ($userCategory == '_APPLICANT_') {
  9113.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9114.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9115.                         array(
  9116.                             'email' => $email_address
  9117.                         )
  9118.                     );
  9119.                     if ($userObj) {
  9120.                     } else {
  9121.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9122.                             array(
  9123.                                 'oAuthEmail' => $email_address
  9124.                             )
  9125.                         );
  9126.                         if ($userObj) {
  9127.                         } else {
  9128.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9129.                                 array(
  9130.                                     'userName' => $email_address
  9131.                                 )
  9132.                             );
  9133.                         }
  9134.                     }
  9135.                     if ($userObj) {
  9136.                         $email_address $userObj->getEmail();
  9137.                         if ($email_address == null || $email_address == '')
  9138.                             $email_address $userObj->getOAuthEmail();
  9139.                     }
  9140. //                    triggerResetPassword:
  9141. //                    type: integer
  9142. //                          nullable: true
  9143.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9144.                     $userObj->setOtp($otpData['otp']);
  9145.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9146.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9147.                     $em_goc->flush();
  9148.                     $userData = array(
  9149.                         'id' => $userObj->getApplicantId(),
  9150.                         'email' => $email_address,
  9151.                         'appId' => 0,
  9152. //                        'appId'=>$userObj->getUserAppId(),
  9153.                     );
  9154.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9155.                     $email_twig_data = [
  9156.                         'page_title' => 'Find Account',
  9157.                         'encryptedData' => $encryptedData,
  9158.                         'message' => $message,
  9159.                         'userType' => $userType,
  9160.                         'errorField' => $errorField,
  9161.                         'otp' => $otpData['otp'],
  9162.                         'otpExpireSecond' => $otpExpireSecond,
  9163.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9164.                         'otpExpireTs' => $otpData['expireTs'],
  9165.                         'systemType' => $systemType,
  9166.                         'userData' => $userData
  9167.                     ];
  9168.                     if ($userObj)
  9169.                         $email_twig_data['success'] = true;
  9170.                 } else {
  9171.                     $userType UserConstants::USER_TYPE_GENERAL;
  9172.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9173.                     $email_twig_data = [
  9174.                         'page_title' => 'Find Account',
  9175.                         'encryptedData' => $encryptedData,
  9176.                         'message' => $message,
  9177.                         'userType' => $userType,
  9178.                         'errorField' => $errorField,
  9179.                     ];
  9180.                 }
  9181.             } else if ($systemType == '_BUDDYBEE_') {
  9182.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9183.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9184.                     array(
  9185.                         'applicantId' => $userId
  9186.                     )
  9187.                 );
  9188.                 if ($userObj) {
  9189.                     $userOtp $userObj->getOtp();
  9190.                     $userOtpActionId $userObj->getOtpActionId();
  9191.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9192.                     $otpExpireTs $userObj->getOtpExpireTs();
  9193.                     $currentTime = new \DateTime();
  9194.                     $currentTimeTs $currentTime->format('U');
  9195.                     if ($userOtp != $otp) {
  9196.                         $message "Invalid OTP!";
  9197.                         $email_twig_data['success'] = false;
  9198.                     } else if ($userOtpActionId != $otpActionId) {
  9199.                         $message "Invalid OTP Action!";
  9200.                         $email_twig_data['success'] = false;
  9201.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9202.                         $message "OTP Expired!";
  9203.                         $email_twig_data['success'] = false;
  9204.                     } else {
  9205.                         $userObj->setOtp(0);
  9206.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9207.                         $userObj->setOtpExpireTs(0);
  9208.                         $userObj->setTriggerResetPassword(1);
  9209.                         $em_goc->flush();
  9210.                         $email_twig_data['success'] = true;
  9211.                         $message "";
  9212.                     }
  9213.                     $userData = array(
  9214.                         'id' => $userObj->getApplicantId(),
  9215.                         'email' => $email_address,
  9216.                         'appId' => 0,
  9217.                         'image' => $userObj->getImage(),
  9218.                         'firstName' => $userObj->getFirstname(),
  9219.                         'lastName' => $userObj->getLastname(),
  9220. //                        'appId'=>$userObj->getUserAppId(),
  9221.                     );
  9222.                     $email_twig_data['userData'] = $userData;
  9223.                 } else {
  9224.                     $message "Account not found!";
  9225.                     $email_twig_data['success'] = false;
  9226.                 }
  9227.             }
  9228.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9229.                 $response = new JsonResponse(array(
  9230.                         'templateData' => $twigData,
  9231.                         'message' => $message,
  9232.                         'actionData' => $email_twig_data,
  9233.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9234.                     )
  9235.                 );
  9236.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9237.                 return $response;
  9238.             } else if ($email_twig_data['success'] == true) {
  9239.                 $encData = array(
  9240.                     "userType" => $userType,
  9241.                     "otp" => '',
  9242.                     "otpExpireTs" => $otpExpireTs,
  9243.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9244.                     "userCategory" => $userCategory,
  9245.                     "userId" => $userData['id'],
  9246.                     "systemType" => $systemType,
  9247.                 );
  9248.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9249.                 $url $this->generateUrl(
  9250.                     'reset_password_new_password'
  9251.                 );
  9252.                 return $this->redirect($url "/" $encDataStr);
  9253. //                return $this->redirectToRoute("reset_password_new_password", [
  9254. ////                'id' => $isApplicantExist->getApplicantId(),
  9255. ////                'oAuthData' => $oAuthData,
  9256. ////                'refRoute' => $refRoute,
  9257. //                ]);
  9258.             }
  9259.         }
  9260.         if ($systemType == '_ERP_') {
  9261.             if ($userCategory == '_APPLICANT_') {
  9262.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9263.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9264.                 $twigData = [
  9265.                     'page_title' => 'Find Account',
  9266.                     'encryptedData' => $encryptedData,
  9267.                     'message' => $message,
  9268.                     'userType' => $userType,
  9269.                     'errorField' => $errorField,
  9270.                 ];
  9271.             } else {
  9272.                 $userType UserConstants::USER_TYPE_GENERAL;
  9273.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9274.                 $twigData = [
  9275.                     'page_title' => 'Find Account',
  9276.                     'encryptedData' => $encryptedData,
  9277.                     'message' => $message,
  9278.                     'userType' => $userType,
  9279.                     'errorField' => $errorField,
  9280.                 ];
  9281.             }
  9282.         } else if ($systemType == '_BUDDYBEE_') {
  9283.             $userType UserConstants::USER_TYPE_APPLICANT;
  9284.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9285.             $twigData = [
  9286.                 'page_title' => 'Verify Otp',
  9287.                 'encryptedData' => $encryptedData,
  9288.                 'message' => $message,
  9289.                 'email' => $email,
  9290.                 "otp" => '',
  9291. //                "otp"=>$otp,
  9292.                 "otpExpireTs" => $otpExpireTs,
  9293.                 'userType' => $userType,
  9294.                 'userCategory' => $userCategory,
  9295.                 'errorField' => $errorField,
  9296.             ];
  9297.         }
  9298.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9299.             $response = new JsonResponse(array(
  9300.                     'templateData' => $twigData,
  9301.                     'message' => $message,
  9302.                     'actionData' => $email_twig_data,
  9303.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9304.                 )
  9305.             );
  9306.             $response->headers->set('Access-Control-Allow-Origin''*');
  9307.             return $response;
  9308.         } else {
  9309.             return $this->render(
  9310.                 $twig_file,
  9311.                 $twigData
  9312.             );
  9313.         }
  9314.     }
  9315. //    public function getCompanyByUser(Request $request){
  9316. //        $em = $this->getDoctrine()->getManager();
  9317. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9318. //        $session = $request->getSession();
  9319. //        $userId = $session->get(UserConstants::USER_ID);
  9320. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9321. //            ->select('U.userAppIdList')
  9322. //            ->where('U.userId = :userId')
  9323. //            ->setParameter('userId', $userId)
  9324. //            ->getQuery()
  9325. //            ->getResult();
  9326. //
  9327. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9328. //            ->select('C.name','C.appId')
  9329. //            ->getQuery()
  9330. //            ->getResult();
  9331. //
  9332. //        return new JsonResponse(
  9333. //            [
  9334. //                'applicantCompnayId' => $applicantDetails,
  9335. //                'copanyData' => $compnayDetails
  9336. //            ]
  9337. //        );
  9338.     public function getCompanyByUser(Request $request)
  9339.     {
  9340.         $em_goc $this->getDoctrine()->getManager('company_group');
  9341.         $em_goc->getConnection()->connect();
  9342.         $session $request->getSession();
  9343.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9344.         $userAppIdList json_decode($appIdstrue);
  9345.         if (!is_array($userAppIdList)) {
  9346.             return new JsonResponse([]);
  9347.         }
  9348.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9349.             ->createQueryBuilder('C')
  9350.             ->select('C.name, C.appId')
  9351.             ->where('C.appId IN (:appIds)')
  9352.             ->setParameter('appIds'$userAppIdList)
  9353.             ->getQuery()
  9354.             ->getResult();
  9355.         return new JsonResponse($companyData);
  9356.     }
  9357.     public function applicantList(Request $request)
  9358.     {
  9359.         $em_goc $this->getDoctrine()->getManager('company_group');
  9360.         $em_goc->getConnection()->connect();
  9361.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9362.             ->createQueryBuilder('C')
  9363.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9364.             ->getQuery()
  9365.             ->getResult();
  9366.         return new JsonResponse($applicantList);
  9367.     }
  9368.     public function getUserType()
  9369.     {
  9370.         $userType HumanResourceConstant::$userTypeForApp;
  9371.         return new JsonResponse($userType);
  9372.     }
  9373.     public function updatepasswordAction(Request $request)
  9374.     {
  9375.         $em_goc $this->getDoctrine()->getManager('company_group');
  9376.         $session $request->getSession();
  9377.         $userId $session->get(UserConstants::USER_ID);
  9378.         if ($request->isMethod('POST')) {
  9379.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9380.             $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($request->request->get('password'), $user->getSalt());
  9381.             $user->setPassword($encodedPassword);
  9382.             $em_goc->persist($user);
  9383.             $em_goc->flush();
  9384.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9385.         }
  9386.     }
  9387. }