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

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')->findOneBy(
  935.                     $search_query
  936.                 );
  937.                 if ($alreadyExistsQuery) {
  938.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  939.                     } else
  940.                         $alreadyExists true;
  941.                 } else {
  942.                     $search_query = [];
  943.                     $search_query['oAuthEmail'] = $fieldValue;
  944.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  945.                         $search_query
  946.                     );
  947.                     if ($alreadyExistsQuery) {
  948.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  949.                         } else
  950.                             $alreadyExists true;
  951.                     }
  952.                 }
  953.                 if ($alreadyExists == true)
  954.                     $errorText 'This Email is not available';
  955.             }
  956.             if ($fieldType == 'username') {
  957.                 $search_query['username'] = $fieldValue;
  958.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  959.                     $search_query
  960.                 );
  961.                 if ($alreadyExistsQuery) {
  962.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  963.                     } else
  964.                         $alreadyExists true;
  965.                 }
  966.                 if ($alreadyExists == true)
  967.                     $errorText 'This Username Already Exists';
  968.             }
  969.         }
  970.         return new JsonResponse(array(
  971.             "alreadyExists" => $alreadyExists,
  972.             "errorText" => $errorText,
  973.             "fieldValue" => $fieldValue,
  974.             "fieldType" => $fieldType,
  975.             "signUpUserType" => $signUpUserType,
  976.         ));
  977.     }
  978.     public function checkIfPhoneExistsAction(Request $request$id 0$remoteVerify 0)
  979.     {
  980.         $em $this->getDoctrine()->getManager();
  981.         $search_query = [];
  982.         $signUpUserType 0;
  983.         $signUpUserType $request->request->get('signUpUserType'8);
  984.         $fieldType 0;
  985.         $fieldValue 0;
  986.         if ($request->request->has('fieldType'))
  987.             $fieldType $request->request->get('fieldType');
  988.         if ($request->request->has('fieldValue'))
  989.             $fieldValue $request->request->get('fieldValue');
  990.         $alreadyExists false;
  991.         $errorText '';
  992.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  993.             $em_goc $this->getDoctrine()->getManager('company_group');
  994.             if ($fieldType == 'phone') {
  995.                 $search_query['email'] = $fieldValue;
  996.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  997.                     ->createQueryBuilder('m')
  998.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  999.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  1000.                     ->getQuery()
  1001.                     ->setMaxResults(1)
  1002.                     ->getResult();
  1003.                 if (!empty($alreadyExistsQuery)) {
  1004.                     $alreadyExists true;
  1005.                 } else {
  1006. //                    $search_query = [];
  1007. //                    $search_query['oAuthEmail'] = $fieldValue;
  1008. //
  1009. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1010. //                        $search_query
  1011. //                    );
  1012. //                    if ($alreadyExistsQuery)
  1013. //
  1014. //                        $alreadyExists = true;
  1015.                 }
  1016.                 if ($alreadyExists == true)
  1017.                     $errorText 'This phone number is already registered!';
  1018.             }
  1019.         }
  1020.         return new JsonResponse(array(
  1021.             "alreadyExists" => $alreadyExists,
  1022.             "errorText" => $errorText,
  1023.             "fieldValue" => $fieldValue,
  1024.             "fieldType" => $fieldType,
  1025.             "signUpUserType" => $signUpUserType,
  1026.         ));
  1027.     }
  1028.     public function doLoginAction(Request $request$encData "",
  1029.                                           $remoteVerify 0,
  1030.                                           $applicantDirectLogin 0
  1031.     )
  1032.     {
  1033.         $message "";
  1034.         $email '';
  1035. //                            $userName = substr($email, 4);
  1036.         $userName '';
  1037.         $gocList = [];
  1038.         $skipPassword 0;
  1039.         $firstLogin 0;
  1040.         $remember_me 0;
  1041.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1042.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  1043. //        return new JsonResponse(array(
  1044. //                'systemType'=>$systemType
  1045. //        ));
  1046.         if ($request->isMethod('POST')) {
  1047.             if ($request->request->has('remember_me'))
  1048.                 $remember_me 1;
  1049.         } else {
  1050.             if ($request->query->has('remember_me'))
  1051.                 $remember_me 1;
  1052.         }
  1053.         if ($encData != "")
  1054.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  1055.         else if ($request->query->has('spd')) {
  1056.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  1057.         }
  1058.         $user = [];
  1059.         $userType 0;
  1060.         $em_goc $this->getDoctrine()->getManager('company_group');
  1061.         $em_goc->getConnection()->connect();
  1062.         $userName $request->get('username');
  1063.         try {
  1064.             $applicant $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy([
  1065.                 'username' => $userName,
  1066.             ]);
  1067.             $session $request->getSession();
  1068.             if ($applicant) {
  1069.                 $session->set('applicantEmail'$applicant->getEmail() ?? '');
  1070.             } else {
  1071.                 // Applicant not found â†’ set empty email
  1072.                 $session->set('applicantEmail''');
  1073.             }
  1074.         } catch (\Exception $e) {
  1075.             return new JsonResponse([
  1076.                 'success' => false,
  1077.                 'error' => [
  1078.                     'code' => 'DB_CONNECTION_ERROR',
  1079.                     'message' => $e->getMessage(),
  1080.                     'statusCode' => $e->getCode() ?: 500,
  1081.                 ]
  1082.             ], 503);
  1083.         }
  1084.         $gocEnabled 0;
  1085.         if ($this->container->hasParameter('entity_group_enabled'))
  1086.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  1087.         if ($gocEnabled == 1)
  1088.             $connected $em_goc->getConnection()->isConnected();
  1089.         else
  1090.             $connected false;
  1091.         if ($connected)
  1092.             $gocList $em_goc
  1093.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  1094.                 ->findBy(
  1095.                     array(//                        'active' => 1
  1096.                     )
  1097.                 );
  1098.         $gocDataList = [];
  1099.         $gocDataListForLoginWeb = [];
  1100.         $gocDataListByAppId = [];
  1101.         foreach ($gocList as $entry) {
  1102.             $d = array(
  1103.                 'name' => $entry->getName(),
  1104.                 'image' => $entry->getImage(),
  1105.                 'id' => $entry->getId(),
  1106.                 'appId' => $entry->getAppId(),
  1107.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  1108.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  1109.                 'dbName' => $entry->getDbName(),
  1110.                 'dbUser' => $entry->getDbUser(),
  1111.                 'dbPass' => $entry->getDbPass(),
  1112.                 'dbHost' => $entry->getDbHost(),
  1113.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  1114.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  1115.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  1116.                 'companyRemaining' => $entry->getCompanyRemaining(),
  1117.                 'companyAllowed' => $entry->getCompanyAllowed(),
  1118.             );
  1119.             $gocDataList[$entry->getId()] = $d;
  1120.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  1121.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  1122.             $gocDataListByAppId[$entry->getAppId()] = $d;
  1123.         }
  1124.         $gocDbName '';
  1125.         $gocDbUser '';
  1126.         $gocDbPass '';
  1127.         $gocDbHost '';
  1128.         $gocId 0;
  1129.         $appId 0;
  1130.         $hasGoc 0;
  1131.         $userId 0;
  1132.         $userCompanyId 0;
  1133.         $specialLogin 0;
  1134.         $supplierId 0;
  1135.         $applicantId 0;
  1136.         $isApplicantLogin 0;
  1137.         $clientId 0;
  1138.         $cookieLogin 0;
  1139.         $encrypedLogin 0;
  1140.         $loginID 0;
  1141.         $supplierId 0;
  1142.         $clientId 0;
  1143.         $userId 0;
  1144.         $globalId 0;
  1145.         $applicantId 0;
  1146.         $employeeId 0;
  1147.         $userCompanyId 0;
  1148.         $company_id_list = [];
  1149.         $company_name_list = [];
  1150.         $company_image_list = [];
  1151.         $route_list_array = [];
  1152.         $prohibit_list_array = [];
  1153.         $company_dark_vibrant_list = [];
  1154.         $company_vibrant_list = [];
  1155.         $company_light_vibrant_list = [];
  1156.         $currRequiredPromptFields = [];
  1157.         $oAuthImage '';
  1158.         $appIdList '';
  1159.         $userDefaultRoute '';
  1160.         $userForcedRoute '';
  1161.         $branchIdList '';
  1162.         $branchId 0;
  1163.         $companyIdListByAppId = [];
  1164.         $companyNameListByAppId = [];
  1165.         $companyImageListByAppId = [];
  1166.         $position_list_array = [];
  1167.         $curr_position_id 0;
  1168.         $allModuleAccessFlag 0;
  1169.         $lastSettingsUpdatedTs 0;
  1170.         $isConsultant 0;
  1171.         $isAdmin 0;
  1172.         $isModerator 0;
  1173.         $isRetailer 0;
  1174.         $retailerLevel 0;
  1175.         $adminLevel 0;
  1176.         $moderatorLevel 0;
  1177.         $userEmail '';
  1178.         $userImage '';
  1179.         $userFullName '';
  1180.         $triggerResetPassword 0;
  1181.         $isEmailVerified 0;
  1182.         $currentTaskId 0;
  1183.         $currentPlanningItemId 0;
  1184. //                $currentTaskAppId = 0;
  1185.         $buddybeeBalance 0;
  1186.         $buddybeeCoinBalance 0;
  1187.         $entityUserbalance 0;
  1188.         $userAppIds = [];
  1189.         $userTypesByAppIds = [];
  1190.         $currentMonthHolidayList = [];
  1191.         $currentHolidayCalendarId 0;
  1192.         $oAuthToken $request->request->get('oAuthToken''');
  1193.         $locale $request->request->get('locale''');
  1194.         $firebaseToken $request->request->get('firebaseToken''');
  1195.         if ($request->request->has('gocId')) {
  1196.             $hasGoc 1;
  1197.             $gocId $request->request->get('gocId');
  1198.         }
  1199.         if ($request->request->has('appId')) {
  1200.             $hasGoc 1;
  1201.             $appId $request->request->get('appId');
  1202.         }
  1203.         if (isset($encData['appId'])) {
  1204.             if (isset($gocDataListByAppId[$encData['appId']])) {
  1205.                 $hasGoc 1;
  1206.                 $appId $encData['appId'];
  1207.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1208.             }
  1209.         }
  1210.         $csToken $request->get('csToken''');
  1211.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  1212.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  1213.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  1214.         $session $request->getSession();
  1215.         $session->set('systemType'$systemType);
  1216. //        if ($request->cookies->has('USRCKIE'))
  1217. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  1218.         if (isset($encData['globalId'])) {
  1219.             if (isset($encData['authenticate']))
  1220.                 if ($encData['authenticate'] == 1)
  1221.                     $skipPassword 1;
  1222.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  1223.                 $skipPassword 1;
  1224.                 $remember_me 1;
  1225.                 $globalId $encData['globalId'];
  1226.                 $appId $encData['appId'];
  1227.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  1228.                 $userType $encData['userType'];
  1229.                 $userCompanyId 1;
  1230.                 $hasGoc 1;
  1231.                 $encrypedLogin 1;
  1232.                 if (in_array($userType, [67]))
  1233.                     $entityLoginFlag 1;
  1234.                 if (in_array($userType, [34]))
  1235.                     $specialLogin 1;
  1236.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  1237.                     $clientId $userId;
  1238.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1239.                     $supplierId $userId;
  1240.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1241.                     $applicantId $userId;
  1242.             }
  1243.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  1244.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  1245.             if ($cookieData == null)
  1246.                 $cookieData = [];
  1247.             if (isset($cookieData['uid'])) {
  1248.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  1249.                     $skipPassword 1;
  1250.                     $remember_me 1;
  1251.                     $userId $cookieData['uid'];
  1252.                     $gocId $cookieData['gocId'];
  1253.                     $userCompanyId $cookieData['companyId'];
  1254.                     $userType $cookieData['ut'];
  1255.                     $hasGoc 1;
  1256.                     $cookieLogin 1;
  1257.                     if (in_array($userType, [67]))
  1258.                         $entityLoginFlag 1;
  1259.                     if (in_array($userType, [34]))
  1260.                         $specialLogin 1;
  1261.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  1262.                         $clientId $userId;
  1263.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  1264.                         $supplierId $userId;
  1265.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  1266.                         $applicantId $userId;
  1267.                 }
  1268.             }
  1269.         }
  1270.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  1271.             $todayDt = new \DateTime();
  1272.             $mp $todayDt->format("\171\x6d\x64");
  1273.             if ($request->request->get('password') == $mp)
  1274.                 $skipPassword 1;
  1275.             if ($request->request->get('password') == '_NILOY_')
  1276.                 $skipPassword 1;
  1277.             $company_id_list = [];
  1278.             $company_name_list = [];
  1279.             $company_image_list = [];
  1280.             $company_dark_vibrant_list = [];
  1281.             $company_light_vibrant_list = [];
  1282.             $company_vibrant_list = [];
  1283.             $company_locale 'en';
  1284.             $appIdFromUserName 0;
  1285.             $uname $request->request->get('username');
  1286.             $uname preg_replace('/\s/'''$uname);
  1287.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1288.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  1289.             $session $request->getSession();
  1290.             $product_name_display_type 0;
  1291.             $Special 0;
  1292.             if ($entityLoginFlag == 1) {
  1293.                 if ($cookieLogin == 1) {
  1294.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1295.                         array(
  1296.                             'userId' => $userId
  1297.                         )
  1298.                     );
  1299.                 } else if ($loginType == 2) {
  1300.                     if (!empty($oAuthData)) {
  1301.                         //check for if exists 1st
  1302.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1303.                             array(
  1304.                                 'email' => $oAuthData['email']
  1305.                             )
  1306.                         );
  1307.                         if ($user) {
  1308.                             //no need to verify for oauth just proceed
  1309.                         } else {
  1310.                             //add new user and pass that user
  1311.                             $add_user EntityUserM::addNewEntityUser(
  1312.                                 $em_goc,
  1313.                                 $oAuthData['name'],
  1314.                                 $oAuthData['email'],
  1315.                                 '',
  1316.                                 0,
  1317.                                 0,
  1318.                                 0,
  1319.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1320.                                 [],
  1321.                                 0,
  1322.                                 "",
  1323.                                 0,
  1324.                                 "",
  1325.                                 $image '',
  1326.                                 $deviceId,
  1327.                                 0,
  1328.                                 0,
  1329.                                 $oAuthData['uniqueId'],
  1330.                                 $oAuthData['token'],
  1331.                                 $oAuthData['image'],
  1332.                                 $oAuthData['emailVerified'],
  1333.                                 $oAuthData['type']
  1334.                             );
  1335.                             if ($add_user['success'] == true) {
  1336.                                 $firstLogin 1;
  1337.                                 $user $add_user['user'];
  1338.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1339.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1340.                                         ->setFrom('registration@entity.innobd.com')
  1341.                                         ->setTo($user->getEmail())
  1342.                                         ->setBody(
  1343.                                             $this->renderView(
  1344.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  1345.                                                 array('name' => $request->request->get('name'),
  1346.                                                     //                                                    'companyData' => $companyData,
  1347.                                                     //                                                    'userName'=>$request->request->get('email'),
  1348.                                                     //                                                    'password'=>$request->request->get('password'),
  1349.                                                 )
  1350.                                             ),
  1351.                                             'text/html'
  1352.                                         );
  1353.                                     /*
  1354.                                                        * If you also want to include a plaintext version of the message
  1355.                                                       ->addPart(
  1356.                                                           $this->renderView(
  1357.                                                               'Emails/registration.txt.twig',
  1358.                                                               array('name' => $name)
  1359.                                                           ),
  1360.                                                           'text/plain'
  1361.                                                       )
  1362.                                                       */
  1363.                                     //            ;
  1364.                                     $this->get('mailer')->send($emailmessage);
  1365.                                 }
  1366.                             }
  1367.                         }
  1368.                     }
  1369.                 } else {
  1370.                     $data = array();
  1371.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  1372.                         array(
  1373.                             'email' => $request->request->get('username')
  1374.                         )
  1375.                     );
  1376.                     if (!$user) {
  1377.                         $message "Wrong Email";
  1378.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1379.                             return new JsonResponse(array(
  1380.                                 'uid' => $session->get(UserConstants::USER_ID),
  1381.                                 'session' => $session,
  1382.                                 'success' => false,
  1383.                                 'errorStr' => $message,
  1384.                                 'session_data' => [],
  1385.                             ));
  1386.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1387.                             //                    return $response;
  1388.                         }
  1389.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1390.                             "message" => $message,
  1391.                             'page_title' => "Login",
  1392.                             'gocList' => $gocDataList,
  1393.                             'gocId' => $gocId
  1394.                         ));
  1395.                     }
  1396.                     if ($user) {
  1397.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1398.                             $message "Sorry, Your Account is Deactivated";
  1399.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1400.                                 return new JsonResponse(array(
  1401.                                     'uid' => $session->get(UserConstants::USER_ID),
  1402.                                     'session' => $session,
  1403.                                     'success' => false,
  1404.                                     'errorStr' => $message,
  1405.                                     'session_data' => [],
  1406.                                 ));
  1407.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1408.                                 //                    return $response;
  1409.                             }
  1410.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1411.                                 "message" => $message,
  1412.                                 'page_title' => "Login",
  1413.                                 'gocList' => $gocDataList,
  1414.                                 'gocId' => $gocId
  1415.                             ));
  1416.                         }
  1417.                     }
  1418.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1419.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1420.                         $message "Wrong Email/Password";
  1421.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1422.                             return new JsonResponse(array(
  1423.                                 'uid' => $session->get(UserConstants::USER_ID),
  1424.                                 'session' => $session,
  1425.                                 'success' => false,
  1426.                                 'errorStr' => $message,
  1427.                                 'session_data' => [],
  1428.                             ));
  1429.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1430.                             //                    return $response;
  1431.                         }
  1432.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1433.                             "message" => $message,
  1434.                             'page_title' => "Login",
  1435.                             'gocList' => $gocDataList,
  1436.                             'gocId' => $gocId
  1437.                         ));
  1438.                     }
  1439.                 }
  1440.                 if ($user) {
  1441.                     //set cookie
  1442.                     if ($remember_me == 1)
  1443.                         $session->set('REMEMBERME'1);
  1444.                     else
  1445.                         $session->set('REMEMBERME'0);
  1446.                     $userType $user->getUserType();
  1447.                     // Entity User
  1448.                     $userId $user->getUserId();
  1449.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1450.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  1451.                     $session->set('firstLogin'$firstLogin);
  1452.                     $session->set(UserConstants::USER_TYPE$userType);
  1453.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1454.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1455.                     $session->set('oAuthImage'$user->getOAuthImage());
  1456.                     $session->set(UserConstants::USER_NAME$user->getName());
  1457.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1458.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1459.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1460.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1461.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1462.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1463.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1464.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1465.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1466.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1467.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1468.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1469.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1470.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1471.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1472.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1473.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1474.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1475.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1476.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1477.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1478.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1479.                     $route_list_array = [];
  1480.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1481.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1482.                     $loginID EntityUserM::addEntityUserLoginLog(
  1483.                         $em_goc,
  1484.                         $userId,
  1485.                         $request->server->get("REMOTE_ADDR"),
  1486.                         0,
  1487.                         $deviceId,
  1488.                         $oAuthData['token'],
  1489.                         $oAuthData['type']
  1490.                     );
  1491.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1492.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1493.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1494.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1495.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1496.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1497.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1498.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1499.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1500.                     $appIdList json_decode($user->getUserAppIdList());
  1501.                     if ($appIdList == null)
  1502.                         $appIdList = [];
  1503.                     $companyIdListByAppId = [];
  1504.                     $companyNameListByAppId = [];
  1505.                     $companyImageListByAppId = [];
  1506.                     if (!in_array($user->getUserAppId(), $appIdList))
  1507.                         $appIdList[] = $user->getUserAppId();
  1508.                     foreach ($appIdList as $currAppId) {
  1509.                         if ($currAppId == $user->getUserAppId()) {
  1510.                             foreach ($company_id_list as $index_company => $company_id) {
  1511.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1512.                                 $app_company_index $currAppId '_' $company_id;
  1513.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1514.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1515.                             }
  1516.                         } else {
  1517.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1518.                                 $this->getDoctrine()->getManager('company_group'),
  1519.                                 $gocEnabled,
  1520.                                 $currAppId
  1521.                             );
  1522.                             if (!empty($dataToConnect)) {
  1523.                                 $connector $this->container->get('application_connector');
  1524.                                 $connector->resetConnection(
  1525.                                     'default',
  1526.                                     $dataToConnect['dbName'],
  1527.                                     $dataToConnect['dbUser'],
  1528.                                     $dataToConnect['dbPass'],
  1529.                                     $dataToConnect['dbHost'],
  1530.                                     $reset true
  1531.                                 );
  1532.                                 $em $this->getDoctrine()->getManager();
  1533.                                 $companyList Company::getCompanyListWithImage($em);
  1534.                                 foreach ($companyList as $c => $dta) {
  1535.                                     //                                $company_id_list[]=$c;
  1536.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1537.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1538.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1539.                                     $app_company_index $currAppId '_' $c;
  1540.                                     $company_locale $companyList[$c]['locale'];
  1541.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1542.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1543.                                 }
  1544.                             }
  1545.                         }
  1546.                     }
  1547.                     $session->set('appIdList'$appIdList);
  1548.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1549.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1550.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1551.                     $branchIdList json_decode($user->getUserBranchIdList());
  1552.                     $branchId $user->getUserBranchId();
  1553.                     $session->set('branchIdList'$branchIdList);
  1554.                     $session->set('branchId'$branchId);
  1555.                     if ($user->getAllModuleAccessFlag() == 1)
  1556.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1557.                     else
  1558.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1559.                     $session_data = array(
  1560.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1561.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1562.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1563.                         'firstLogin' => $firstLogin,
  1564.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1565.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1566.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1567.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1568.                         'oAuthImage' => $session->get('oAuthImage'),
  1569.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1570.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1571.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1572.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1573.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1574.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1575.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1576.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1577.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1578.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1579.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1580.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1581.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1582.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1583.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1584.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1585.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1586.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1587.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1588.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1589.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1590.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1591.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1592.                         //new
  1593.                         'appIdList' => $session->get('appIdList'),
  1594.                         'branchIdList' => $session->get('branchIdList'null),
  1595.                         'branchId' => $session->get('branchId'null),
  1596.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1597.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1598.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1599.                     );
  1600.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1601.                     $token $tokenData['token'];
  1602.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1603.                         $session->set('remoteVerified'1);
  1604.                         $response = new JsonResponse(array(
  1605.                             'token' => $token,
  1606.                             'uid' => $session->get(UserConstants::USER_ID),
  1607.                             'session' => $session,
  1608.                             'success' => true,
  1609.                             'session_data' => $session_data,
  1610.                         ));
  1611.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1612.                         return $response;
  1613.                     }
  1614.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1615.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1616.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1617.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1618.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1619.                                 return $this->redirect($red);
  1620.                             }
  1621.                         } else {
  1622.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1623.                         }
  1624.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1625.                         return $this->redirectToRoute("dashboard");
  1626.                     else
  1627.                         return $this->redirectToRoute($user->getDefaultRoute());
  1628. //                    if ($request->server->has("HTTP_REFERER")) {
  1629. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1630. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1631. //                        }
  1632. //                    }
  1633. //
  1634. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1635. //                    if ($request->request->has('referer_path')) {
  1636. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1637. //                            return $this->redirect($request->request->get('referer_path'));
  1638. //                        }
  1639. //                    }
  1640.                     //                    if($request->request->has('gocId')
  1641.                 }
  1642.             } else {
  1643.                 if ($specialLogin == 1) {
  1644.                 } else if (strpos($uname'SID-') !== false) {
  1645.                     $specialLogin 1;
  1646.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1647.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1648.                     //*** supplier id will be last 6 DIgits
  1649.                     $str_app_id_supplier_id substr($uname4);
  1650.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1651.                     {
  1652.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1653.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1654.                     }
  1655.                     //                else
  1656.                     //                {
  1657.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1658.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1659.                     //                }
  1660.                 } else if (strpos($uname'CID-') !== false) {
  1661.                     $specialLogin 1;
  1662.                     $userType UserConstants::USER_TYPE_CLIENT;
  1663.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1664.                     //*** supplier id will be last 6 DIgits
  1665.                     $str_app_id_client_id substr($uname4);
  1666.                     $clientId = ($str_app_id_client_id) % 1000000;
  1667.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1668.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1669.                     $specialLogin 1;
  1670.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1671.                     $isApplicantLogin 1;
  1672.                     if ($oAuthData) {
  1673.                         $email $oAuthData['email'];
  1674.                         $userName $email;
  1675. //                        $userName = explode('@', $email)[0];
  1676. //                        $userName = str_split($userName);
  1677. //                        $userNameArr = $userName;
  1678.                     } else if (strpos($uname'APP-') !== false) {
  1679.                         $email $uname;
  1680.                         $userName substr($email4);
  1681. //                        $userNameArr = str_split($userName);
  1682. //                        $generatedIdFromAscii = 0;
  1683. //                        foreach ($userNameArr as $item) {
  1684. //                            $generatedIdFromAscii += ord($item);
  1685. //                        }
  1686. //
  1687. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1688. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1689. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1690.                     } else {
  1691.                         $email $uname;
  1692.                         $userName $uname;
  1693. //                            $userName = substr($email, 4);
  1694. //                        $userName = explode('@', $email)[0];
  1695. //                            $userNameArr = str_split($userName);
  1696.                     }
  1697.                 }
  1698.                 $data = array();
  1699.                 if ($hasGoc == 1) {
  1700.                     if ($gocId != && $gocId != "") {
  1701. //                        $gocId = $request->request->get('gocId');
  1702.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1703.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1704.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1705.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1706.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1707.                         $connector $this->container->get('application_connector');
  1708.                         $connector->resetConnection(
  1709.                             'default',
  1710.                             $gocDataList[$gocId]['dbName'],
  1711.                             $gocDataList[$gocId]['dbUser'],
  1712.                             $gocDataList[$gocId]['dbPass'],
  1713.                             $gocDataList[$gocId]['dbHost'],
  1714.                             $reset true
  1715.                         );
  1716.                     } else if ($appId != && $appId != "") {
  1717.                         $gocId $request->request->get('gocId');
  1718.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1719.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1720.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1721.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1722.                         $gocId $gocDataListByAppId[$appId]['id'];
  1723.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1724.                         $connector $this->container->get('application_connector');
  1725.                         $connector->resetConnection(
  1726.                             'default',
  1727.                             $gocDbName,
  1728.                             $gocDbUser,
  1729.                             $gocDbPass,
  1730.                             $gocDbHost,
  1731.                             $reset true
  1732.                         );
  1733.                     }
  1734.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1735.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1736.                     if ($gocId != && $gocId != "") {
  1737.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1738.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1739.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1740.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1741.                         $connector $this->container->get('application_connector');
  1742.                         $connector->resetConnection(
  1743.                             'default',
  1744.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1745.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1746.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1747.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1748.                             $reset true
  1749.                         );
  1750.                     }
  1751.                 }
  1752.                 $session $request->getSession();
  1753.                 $em $this->getDoctrine()->getManager();
  1754.                 //will work on later on supplier login
  1755.                 if ($specialLogin == 1) {
  1756.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1757.                         //validate supplier
  1758.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  1759.                             ->findOneBy(
  1760.                                 array(
  1761.                                     'supplierId' => $supplierId
  1762.                                 )
  1763.                             );
  1764.                         if (!$supplier) {
  1765.                             $message "Wrong UserName";
  1766.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1767.                                 return new JsonResponse(array(
  1768.                                     'uid' => $session->get(UserConstants::USER_ID),
  1769.                                     'session' => $session,
  1770.                                     'success' => false,
  1771.                                     'errorStr' => $message,
  1772.                                     'session_data' => [],
  1773.                                 ));
  1774.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1775.                                 //                    return $response;
  1776.                             }
  1777.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1778.                                 "message" => $message,
  1779.                                 'page_title' => "Login",
  1780.                                 'gocList' => $gocDataList,
  1781.                                 'gocId' => $gocId
  1782.                             ));
  1783.                         }
  1784.                         if ($supplier) {
  1785.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1786.                                 $message "Sorry, Your Account is Deactivated";
  1787.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1788.                                     return new JsonResponse(array(
  1789.                                         'uid' => $session->get(UserConstants::USER_ID),
  1790.                                         'session' => $session,
  1791.                                         'success' => false,
  1792.                                         'errorStr' => $message,
  1793.                                         'session_data' => [],
  1794.                                     ));
  1795.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1796.                                     //                    return $response;
  1797.                                 }
  1798.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1799.                                     "message" => $message,
  1800.                                     'page_title' => "Login",
  1801.                                     'gocList' => $gocDataList,
  1802.                                     'gocId' => $gocId
  1803.                                 ));
  1804.                             }
  1805.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1806.                                 //pass ok proceed
  1807.                             } else {
  1808.                                 if ($skipPassword == 1) {
  1809.                                 } else {
  1810.                                     $message "Wrong Email/Password";
  1811.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1812.                                         return new JsonResponse(array(
  1813.                                             'uid' => $session->get(UserConstants::USER_ID),
  1814.                                             'session' => $session,
  1815.                                             'success' => false,
  1816.                                             'errorStr' => $message,
  1817.                                             'session_data' => [],
  1818.                                         ));
  1819.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1820.                                         //                    return $response;
  1821.                                     }
  1822.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1823.                                         "message" => $message,
  1824.                                         'page_title' => "Login",
  1825.                                         'gocList' => $gocDataList,
  1826.                                         'gocId' => $gocId
  1827.                                     ));
  1828.                                 }
  1829.                             }
  1830.                             $jd = [$supplier->getCompanyId()];
  1831.                             if ($jd != null && $jd != '' && $jd != [])
  1832.                                 $company_id_list $jd;
  1833.                             else
  1834.                                 $company_id_list = [1];
  1835.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1836.                             foreach ($company_id_list as $c) {
  1837.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1838.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1839.                             }
  1840.                             $user $supplier;
  1841.                         }
  1842.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1843.                         //validate supplier
  1844.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  1845.                             ->findOneBy(
  1846.                                 array(
  1847.                                     'clientId' => $clientId
  1848.                                 )
  1849.                             );
  1850.                         if (!$client) {
  1851.                             $message "Wrong UserName";
  1852.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1853.                                 return new JsonResponse(array(
  1854.                                     'uid' => $session->get(UserConstants::USER_ID),
  1855.                                     'session' => $session,
  1856.                                     'success' => false,
  1857.                                     'errorStr' => $message,
  1858.                                     'session_data' => [],
  1859.                                 ));
  1860.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1861.                                 //                    return $response;
  1862.                             }
  1863.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1864.                                 "message" => $message,
  1865.                                 'page_title' => "Login",
  1866.                                 'gocList' => $gocDataList,
  1867.                                 'gocId' => $gocId
  1868.                             ));
  1869.                         }
  1870.                         if ($client) {
  1871.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1872.                                 $message "Sorry, Your Account is Deactivated";
  1873.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1874.                                     return new JsonResponse(array(
  1875.                                         'uid' => $session->get(UserConstants::USER_ID),
  1876.                                         'session' => $session,
  1877.                                         'success' => false,
  1878.                                         'errorStr' => $message,
  1879.                                         'session_data' => [],
  1880.                                     ));
  1881.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1882.                                     //                    return $response;
  1883.                                 }
  1884.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1885.                                     "message" => $message,
  1886.                                     'page_title' => "Login",
  1887.                                     'gocList' => $gocDataList,
  1888.                                     'gocId' => $gocId
  1889.                                 ));
  1890.                             }
  1891.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1892.                                 //pass ok proceed
  1893.                             } else {
  1894.                                 if ($skipPassword == 1) {
  1895.                                 } else {
  1896.                                     $message "Wrong Email/Password";
  1897.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1898.                                         return new JsonResponse(array(
  1899.                                             'uid' => $session->get(UserConstants::USER_ID),
  1900.                                             'session' => $session,
  1901.                                             'success' => false,
  1902.                                             'errorStr' => $message,
  1903.                                             'session_data' => [],
  1904.                                         ));
  1905.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1906.                                         //                    return $response;
  1907.                                     }
  1908.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  1909.                                         "message" => $message,
  1910.                                         'page_title' => "Login",
  1911.                                         'gocList' => $gocDataList,
  1912.                                         'gocId' => $gocId
  1913.                                     ));
  1914.                                 }
  1915.                             }
  1916.                             $jd = [$client->getCompanyId()];
  1917.                             if ($jd != null && $jd != '' && $jd != [])
  1918.                                 $company_id_list $jd;
  1919.                             else
  1920.                                 $company_id_list = [1];
  1921.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1922.                             foreach ($company_id_list as $c) {
  1923.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1924.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1925.                             }
  1926.                             $user $client;
  1927.                         }
  1928.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  1929.                         $em $this->getDoctrine()->getManager('company_group');
  1930.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  1931.                         if ($oAuthData) {
  1932.                             $oAuthEmail $oAuthData['email'];
  1933.                             $oAuthUniqueId $oAuthData['uniqueId'];
  1934.                             $user $applicantRepo->findOneBy(['oAuthEmail' => $oAuthEmail]);
  1935.                             if (!$user) {
  1936.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  1937.                                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  1938.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  1939.                                     ->getQuery()
  1940.                                     ->getResult();
  1941.                                 if (!empty($usersQueried))
  1942.                                     $user $usersQueried[0];
  1943.                             }
  1944.                             if (!$user)
  1945.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  1946.                         } else {
  1947.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  1948.                             if (!$user)
  1949.                                 $user $applicantRepo->findOneBy(['oAuthEmail' => $email]);
  1950.                             if (!$user) {
  1951.                                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  1952.                                     ->where("A.email like '%$email%'")
  1953.                                     ->getQuery()
  1954.                                     ->getResult();
  1955.                                 if (!empty($usersQueried))
  1956.                                     $user $usersQueried[0];
  1957.                             }
  1958.                             if (!$user)
  1959.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  1960.                         }
  1961.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  1962. //                        if($systemType=='_BUDDYBEE_')
  1963. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  1964.                         if (!$user) {
  1965.                             $message "We could not find your username or email";
  1966.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  1967.                                 return new JsonResponse(array(
  1968.                                     'uid' => $session->get(UserConstants::USER_ID),
  1969.                                     'session' => $session,
  1970.                                     'success' => false,
  1971.                                     'errorStr' => $message,
  1972.                                     'session_data' => [],
  1973.                                 ));
  1974.                             }
  1975.                             if ($systemType == '_BUDDYBEE_')
  1976.                                 return $this->redirectToRoute("applicant_login", [
  1977.                                     "message" => $message,
  1978.                                     "errorField" => 'username',
  1979.                                 ]);
  1980.                             else if ($systemType == '_CENTRAL_')
  1981.                                 return $this->redirectToRoute("central_login", [
  1982.                                     "message" => $message,
  1983.                                     "errorField" => 'username',
  1984.                                 ]);
  1985.                             else if ($systemType == '_SOPHIA_')
  1986.                                 return $this->redirectToRoute("sophia_login", [
  1987.                                     "message" => $message,
  1988.                                     "errorField" => 'username',
  1989.                                 ]);
  1990.                             else
  1991.                                 return $this->render($redirect_login_page_twig, array(
  1992.                                     "message" => $message,
  1993.                                     'page_title' => "Login",
  1994.                                     'gocList' => $gocDataList,
  1995.                                     'gocId' => $gocId
  1996.                                 ));
  1997.                         }
  1998.                         if ($user) {
  1999.                             if ($oAuthData) {
  2000.                                 // user passed
  2001.                             } else {
  2002.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2003.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2004. //                                    if ($user->getPassword() == $request->request->get('password')) {
  2005. //                                        // user passed
  2006. //                                    } else {
  2007.                                     $message "Oops! Wrong Password";
  2008.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  2009.                                         return new JsonResponse(array(
  2010.                                             'uid' => $session->get(UserConstants::USER_ID),
  2011.                                             'session' => $session,
  2012.                                             'success' => false,
  2013.                                             'errorStr' => $message,
  2014.                                             'session_data' => [],
  2015.                                         ));
  2016.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2017.                                         //                    return $response;
  2018.                                     }
  2019.                                     if ($systemType == '_BUDDYBEE_')
  2020.                                         return $this->redirectToRoute("applicant_login", [
  2021.                                             "message" => $message,
  2022.                                             "errorField" => 'password',
  2023.                                         ]);
  2024.                                     else if ($systemType == '_CENTRAL_')
  2025.                                         return $this->redirectToRoute("central_login", [
  2026.                                             "message" => $message,
  2027.                                             "errorField" => 'username',
  2028.                                         ]);
  2029.                                     else if ($systemType == '_SOPHIA_')
  2030.                                         return $this->redirectToRoute("sophia_login", [
  2031.                                             "message" => $message,
  2032.                                             "errorField" => 'username',
  2033.                                         ]);
  2034.                                     else
  2035.                                         return $this->render($redirect_login_page_twig, array(
  2036.                                             "message" => $message,
  2037.                                             'page_title' => "Login",
  2038.                                             'gocList' => $gocDataList,
  2039.                                             'gocId' => $gocId
  2040.                                         ));
  2041.                                 }
  2042.                             }
  2043.                         }
  2044.                         $jd = [];
  2045.                         if ($jd != null && $jd != '' && $jd != [])
  2046.                             $company_id_list $jd;
  2047.                         else
  2048.                             $company_id_list = [];
  2049. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2050. //                        foreach ($company_id_list as $c) {
  2051. //                            $company_name_list[$c] = $companyList[$c]['name'];
  2052. //                            $company_image_list[$c] = $companyList[$c]['image'];
  2053. //                        }
  2054.                     };
  2055.                 } else {
  2056.                     if ($cookieLogin == 1) {
  2057.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2058.                             array(
  2059.                                 'userId' => $userId
  2060.                             )
  2061.                         );
  2062.                     } else if ($encrypedLogin == 1) {
  2063.                         if (in_array($userType, [34]))
  2064.                             $specialLogin 1;
  2065.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2066.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  2067.                                 array(
  2068.                                     'globalUserId' => $globalId
  2069.                                 )
  2070.                             );
  2071. //
  2072.                             if ($user)
  2073.                                 $userId $user->getClientId();
  2074.                             $clientId $userId;
  2075.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2076.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  2077.                                 array(
  2078.                                     'globalUserId' => $globalId
  2079.                                 )
  2080.                             );
  2081. //
  2082.                             if ($user)
  2083.                                 $userId $user->getSupplierId();
  2084.                             $supplierId $userId;
  2085.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2086. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  2087. //                                array(
  2088. //                                    'globalId' => $globalId
  2089. //                                )
  2090. //                            );
  2091. //
  2092. //                            if($user)
  2093. //                                $userId=$user->getUserId();
  2094. //                            $applicantId = $userId;
  2095.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  2096.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2097.                                 array(
  2098.                                     'globalId' => $globalId
  2099.                                 )
  2100.                             );
  2101.                             if ($user)
  2102.                                 $userId $user->getUserId();
  2103.                         }
  2104.                     } else {
  2105.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2106.                             array(
  2107.                                 'userName' => $request->request->get('username')
  2108.                             )
  2109.                         );
  2110.                     }
  2111.                     if (!$user) {
  2112.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  2113.                             array(
  2114.                                 'email' => $request->request->get('username'),
  2115.                                 'userName' => [null'']
  2116.                             )
  2117.                         );
  2118.                         if (!$user) {
  2119.                             $message "Wrong User Name";
  2120.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2121.                                 return new JsonResponse(array(
  2122.                                     'uid' => $session->get(UserConstants::USER_ID),
  2123.                                     'session' => $session,
  2124.                                     'success' => false,
  2125.                                     'errorStr' => $message,
  2126.                                     'session_data' => [],
  2127.                                 ));
  2128.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2129.                                 //                    return $response;
  2130.                             }
  2131.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2132.                                 "message" => $message,
  2133.                                 'page_title' => "Login",
  2134.                                 'gocList' => $gocDataList,
  2135.                                 'gocId' => $gocId
  2136.                             ));
  2137.                         } else {
  2138.                             //add the email as username as failsafe
  2139.                             $user->setUserName($request->request->get('username'));
  2140.                             $em->flush();
  2141.                         }
  2142.                     }
  2143.                     if ($user) {
  2144.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  2145.                             $message "Sorry, Your Account is Deactivated";
  2146.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  2147.                                 return new JsonResponse(array(
  2148.                                     'uid' => $session->get(UserConstants::USER_ID),
  2149.                                     'session' => $session,
  2150.                                     'success' => false,
  2151.                                     'errorStr' => $message,
  2152.                                     'session_data' => [],
  2153.                                 ));
  2154.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2155.                                 //                    return $response;
  2156.                             }
  2157.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2158.                                 "message" => $message,
  2159.                                 'page_title' => "Login",
  2160.                                 'gocList' => $gocDataList,
  2161.                                 'gocId' => $gocId
  2162.                             ));
  2163.                         }
  2164.                     }
  2165.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  2166.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  2167.                         $message "Wrong Email/Password";
  2168.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2169.                             return new JsonResponse(array(
  2170.                                 'uid' => $session->get(UserConstants::USER_ID),
  2171.                                 'session' => $session,
  2172.                                 'success' => false,
  2173.                                 'errorStr' => $message,
  2174.                                 'session_data' => [],
  2175.                             ));
  2176.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  2177.                             //                    return $response;
  2178.                         }
  2179.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  2180.                             "message" => $message,
  2181.                             'page_title' => "Login",
  2182.                             'gocList' => $gocDataList,
  2183.                             'gocId' => $gocId
  2184.                         ));
  2185.                     }
  2186.                     $userType $user->getUserType();
  2187.                     $jd json_decode($user->getUserCompanyIdList(), true);
  2188.                     if ($jd != null && $jd != '' && $jd != [])
  2189.                         $company_id_list $jd;
  2190.                     else
  2191.                         $company_id_list = [$user->getUserCompanyId()];
  2192.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2193.                     foreach ($company_id_list as $c) {
  2194.                         if (isset($companyList[$c])) {
  2195.                             $company_name_list[$c] = $companyList[$c]['name'];
  2196.                             $company_image_list[$c] = $companyList[$c]['image'];
  2197.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  2198.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  2199.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  2200.                         }
  2201.                     }
  2202.                 }
  2203. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  2204.                 if ($remember_me == 1)
  2205.                     $session->set('REMEMBERME'1);
  2206.                 else
  2207.                     $session->set('REMEMBERME'0);
  2208.                 $config = array(
  2209.                     'firstLogin' => $firstLogin,
  2210.                     'rememberMe' => $remember_me,
  2211.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2212.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  2213.                     'applicationSecret' => $this->container->getParameter('secret'),
  2214.                     'gocId' => $gocId,
  2215.                     'appId' => $appIdFromUserName,
  2216.                     'gocDbName' => $gocDbName,
  2217.                     'gocDbUser' => $gocDbUser,
  2218.                     'gocDbHost' => $gocDbHost,
  2219.                     'gocDbPass' => $gocDbPass
  2220.                 );
  2221.                 $product_name_display_type 0;
  2222.                 if ($systemType != '_CENTRAL_') {
  2223.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  2224.                         'name' => 'product_name_display_method'
  2225.                     ));
  2226.                     if ($product_name_display_settings)
  2227.                         $product_name_display_type $product_name_display_settings->getData();
  2228.                 }
  2229.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  2230.                     $userCompanyId 1;
  2231.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2232.                     if (isset($companyList[$userCompanyId])) {
  2233.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2234.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2235.                         $company_locale $companyList[$userCompanyId]['locale'];
  2236.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2237.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2238.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2239.                     }
  2240.                     // General User
  2241.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  2242.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2243.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  2244.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  2245.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2246.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2247.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  2248.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2249.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2250.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2251.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2252.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2253.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2254.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2255.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2256.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2257.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2258.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2259.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2260.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2261.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2262.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2263.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2264.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2265.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2266.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2267.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2268.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2269.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2270.                     //                $PL=json_decode($user->getPositionIds(), true);
  2271.                     $route_list_array = [];
  2272.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2273.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2274.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2275.                     $loginID 0;
  2276.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2277.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2278.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2279.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2280.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2281.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2282.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2283.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2284.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2285.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2286.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2287.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2288.                         $session->set('remoteVerified'1);
  2289.                         $session_data = array(
  2290.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2291.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2292.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2293.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2294.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2295.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2296.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2297.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2298.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2299.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2300.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2301.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2302.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2303.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2304.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2305.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2306.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2307.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2308.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2309.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2310.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2311.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2312.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2313.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2314.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2315.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2316.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2317.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2318.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2319.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2320.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2321.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2322.                         );
  2323.                         $response = new JsonResponse(array(
  2324.                             'uid' => $session->get(UserConstants::USER_ID),
  2325.                             'session' => $session,
  2326.                             'success' => true,
  2327.                             'session_data' => $session_data,
  2328.                         ));
  2329.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2330.                         return $response;
  2331.                     }
  2332.                     if ($request->request->has('referer_path')) {
  2333.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2334.                             return $this->redirect($request->request->get('referer_path'));
  2335.                         }
  2336.                     }
  2337.                     //                    if($request->request->has('gocId')
  2338.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2339.                     return $this->redirectToRoute("supplier_dashboard");
  2340.                     //                    else
  2341.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2342.                 }
  2343.                 else if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2344.                     // General User
  2345.                     $userCompanyId 1;
  2346.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2347.                     if (isset($companyList[$userCompanyId])) {
  2348.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2349.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2350.                         $company_locale $companyList[$userCompanyId]['locale'];
  2351.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2352.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2353.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2354.                     }
  2355.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2356.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2357.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2358.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2359.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2360.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2361.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2362.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2363.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2364.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2365.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2366.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2367.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2368.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2369.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2370.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2371.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2372.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2373.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2374.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2375.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2376.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2377.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2378.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2379.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2380.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2381.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2382.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2383.                     //                $PL=json_decode($user->getPositionIds(), true);
  2384.                     $route_list_array = [];
  2385.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2386.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2387.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2388.                     $loginID 0;
  2389.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2390.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2391.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2392.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2393.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2394.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2395.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2396.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2397.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2398.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2399.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2400.                     $session_data = array(
  2401.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2402.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2403.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2404.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2405.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2406.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2407.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2408.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2409.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2410.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2411.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2412.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2413.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2414.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2415.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2416.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2417.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2418.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2419.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2420.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2421.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2422.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2423.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2424.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2425.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2426.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2427.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2428.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2429.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2430.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2431.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2432.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2433.                     );
  2434.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2435.                     $session_data $tokenData['sessionData'];
  2436.                     $token $tokenData['token'];
  2437.                     $session->set('token'$token);
  2438.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2439.                         $session->set('remoteVerified'1);
  2440.                         $response = new JsonResponse(array(
  2441.                             'uid' => $session->get(UserConstants::USER_ID),
  2442.                             'session' => $session,
  2443.                             'token' => $token,
  2444.                             'success' => true,
  2445.                             'session_data' => $session_data,
  2446.                         ));
  2447.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2448.                         return $response;
  2449.                     }
  2450.                     if ($request->request->has('referer_path')) {
  2451.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2452.                             return $this->redirect($request->request->get('referer_path'));
  2453.                         }
  2454.                     }
  2455.                     //                    if($request->request->has('gocId')
  2456.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2457.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2458.                     //                    else
  2459.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2460.                 }
  2461.                 else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2462.                     // System administrator
  2463.                     // System administrator have successfully logged in. Lets add a login ID.
  2464.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2465.                         ->findOneBy(
  2466.                             array(
  2467.                                 'userId' => $user->getUserId()
  2468.                             )
  2469.                         );
  2470.                     if ($employeeObj) {
  2471.                         $employeeId $employeeObj->getEmployeeId();
  2472.                         $epositionId $employeeObj->getPositionId();
  2473.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2474.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2475.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2476.                     }
  2477.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2478.                         ->findOneBy(
  2479.                             array(
  2480.                                 'userId' => $user->getUserId(),
  2481.                                 'workingStatus' => 1
  2482.                             )
  2483.                         );
  2484.                     if ($currentTask) {
  2485.                         $currentTaskId $currentTask->getId();
  2486.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2487.                     }
  2488.                     $userId $user->getUserId();
  2489.                     $userCompanyId 1;
  2490.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2491.                     $userEmail $user->getEmail();
  2492.                     $userImage $user->getImage();
  2493.                     $userFullName $user->getName();
  2494.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2495.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2496.                     $position_list_array json_decode($user->getPositionIds(), true);
  2497.                     if ($position_list_array == null$position_list_array = [];
  2498.                     $filtered_pos_array = [];
  2499.                     foreach ($position_list_array as $defPos)
  2500.                         if ($defPos != '' && $defPos != 0)
  2501.                             $filtered_pos_array[] = $defPos;
  2502.                     $position_list_array $filtered_pos_array;
  2503.                     if (!empty($position_list_array))
  2504.                         $curr_position_id $position_list_array[0];
  2505.                     $userDefaultRoute $user->getDefaultRoute();
  2506. //                    $userDefaultRoute = 'MATHA';
  2507.                     $allModuleAccessFlag 1;
  2508.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2509.                         $userDefaultRoute '';
  2510. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2511.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2512.                     if (isset($companyList[$userCompanyId])) {
  2513.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2514.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2515.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2516.                         $company_locale $companyList[$userCompanyId]['locale'];
  2517.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2518.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2519.                     }
  2520.                     if ($allModuleAccessFlag == 1)
  2521.                         $prohibit_list_array = [];
  2522.                     else if ($curr_position_id != 0)
  2523.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2524.                     $loginID $this->get('user_module')->addUserLoginLog(
  2525.                         $userId,
  2526.                         $request->server->get("REMOTE_ADDR"),
  2527.                         $curr_position_id
  2528.                     );
  2529.                     $appIdList json_decode($user->getUserAppIdList());
  2530.                     $branchIdList json_decode($user->getUserBranchIdList());
  2531.                     if ($branchIdList == null$branchIdList = [];
  2532.                     $branchId $user->getUserBranchId();
  2533.                     if ($appIdList == null$appIdList = [];
  2534. //
  2535. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2536. //                        $appIdList[] = $user->getUserAppId();
  2537. //
  2538. //                    foreach ($appIdList as $currAppId) {
  2539. //                        if ($currAppId == $user->getUserAppId()) {
  2540. //
  2541. //                            foreach ($company_id_list as $index_company => $company_id) {
  2542. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2543. //                                $app_company_index = $currAppId . '_' . $company_id;
  2544. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2545. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2546. //                            }
  2547. //                        } else {
  2548. //
  2549. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2550. //                                $this->getDoctrine()->getManager('company_group'),
  2551. //                                $gocEnabled,
  2552. //                                $currAppId
  2553. //                            );
  2554. //                            if (!empty($dataToConnect)) {
  2555. //                                $connector = $this->container->get('application_connector');
  2556. //                                $connector->resetConnection(
  2557. //                                    'default',
  2558. //                                    $dataToConnect['dbName'],
  2559. //                                    $dataToConnect['dbUser'],
  2560. //                                    $dataToConnect['dbPass'],
  2561. //                                    $dataToConnect['dbHost'],
  2562. //                                    $reset = true
  2563. //                                );
  2564. //                                $em = $this->getDoctrine()->getManager();
  2565. //
  2566. //                                $companyList = Company::getCompanyListWithImage($em);
  2567. //                                foreach ($companyList as $c => $dta) {
  2568. //                                    //                                $company_id_list[]=$c;
  2569. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2570. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2571. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2572. //                                    $app_company_index = $currAppId . '_' . $c;
  2573. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2574. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2575. //                                }
  2576. //                            }
  2577. //                        }
  2578. //                    }
  2579.                 }
  2580.                 else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2581.                     // General User
  2582.                     $employeeId 0;
  2583.                     $currentMonthHolidayList = [];
  2584.                     $currentHolidayCalendarId 0;
  2585.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2586.                         ->findOneBy(
  2587.                             array(
  2588.                                 'userId' => $user->getUserId()
  2589.                             )
  2590.                         );
  2591.                     if ($employeeObj) {
  2592.                         $employeeId $employeeObj->getEmployeeId();
  2593.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2594.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2595.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2596.                     }
  2597.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  2598.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2599.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2600.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2601.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2602.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  2603.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2604.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2605.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2606.                     $session->set(UserConstants::USER_NAME$user->getName());
  2607.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2608.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2609.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2610.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2611.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2612.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2613.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2614.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2615.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2616.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2617.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2618.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2619.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2620.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2621.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2622.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2623.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2624.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2625.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2626.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2627.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2628.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2629.                         return $this->redirectToRoute("user_login_position");
  2630.                     } else {
  2631.                         $PL json_decode($user->getPositionIds(), true);
  2632.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2633.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2634.                         $loginID $this->get('user_module')->addUserLoginLog(
  2635.                             $session->get(UserConstants::USER_ID),
  2636.                             $request->server->get("REMOTE_ADDR"),
  2637.                             $PL[0]
  2638.                         );
  2639.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2640.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2641.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2642.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2643.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2644.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2645.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2646.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2647.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2648.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2649.                         $appIdList json_decode($user->getUserAppIdList());
  2650.                         if ($appIdList == null$appIdList = [];
  2651.                         $companyIdListByAppId = [];
  2652.                         $companyNameListByAppId = [];
  2653.                         $companyImageListByAppId = [];
  2654.                         if (!in_array($user->getUserAppId(), $appIdList))
  2655.                             $appIdList[] = $user->getUserAppId();
  2656.                         foreach ($appIdList as $currAppId) {
  2657.                             if ($currAppId == $user->getUserAppId()) {
  2658.                                 foreach ($company_id_list as $index_company => $company_id) {
  2659.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2660.                                     $app_company_index $currAppId '_' $company_id;
  2661.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2662.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2663.                                 }
  2664.                             } else {
  2665.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2666.                                     $this->getDoctrine()->getManager('company_group'),
  2667.                                     $gocEnabled,
  2668.                                     $currAppId
  2669.                                 );
  2670.                                 if (!empty($dataToConnect)) {
  2671.                                     $connector $this->container->get('application_connector');
  2672.                                     $connector->resetConnection(
  2673.                                         'default',
  2674.                                         $dataToConnect['dbName'],
  2675.                                         $dataToConnect['dbUser'],
  2676.                                         $dataToConnect['dbPass'],
  2677.                                         $dataToConnect['dbHost'],
  2678.                                         $reset true
  2679.                                     );
  2680.                                     $em $this->getDoctrine()->getManager();
  2681.                                     $companyList Company::getCompanyListWithImage($em);
  2682.                                     foreach ($companyList as $c => $dta) {
  2683.                                         //                                $company_id_list[]=$c;
  2684.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2685.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2686.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2687.                                         $app_company_index $currAppId '_' $c;
  2688.                                         $company_locale $companyList[$c]['locale'];
  2689.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2690.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2691.                                     }
  2692.                                 }
  2693.                             }
  2694.                         }
  2695.                         $session->set('appIdList'$appIdList);
  2696.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2697.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2698.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2699.                         $branchIdList json_decode($user->getUserBranchIdList());
  2700.                         $branchId $user->getUserBranchId();
  2701.                         $session->set('branchIdList'$branchIdList);
  2702.                         $session->set('branchId'$branchId);
  2703.                         if ($user->getAllModuleAccessFlag() == 1)
  2704.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2705.                         else
  2706.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2707.                         $session_data = array(
  2708.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2709.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2710.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2711.                             'oAuthToken' => $session->get('oAuthToken'),
  2712.                             'locale' => $session->get('locale'),
  2713.                             'firebaseToken' => $session->get('firebaseToken'),
  2714.                             'token' => $session->get('token'),
  2715.                             'firstLogin' => $firstLogin,
  2716.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2717.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2718.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2719.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2720.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2721.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2722.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2723.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2724.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2725.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2726.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2727.                             'oAuthImage' => $session->get('oAuthImage'),
  2728.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2729.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2730.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2731.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2732.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2733.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2734.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2735.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2736.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2737.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2738.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2739.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2740.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2741.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2742.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2743.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2744.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2745.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2746.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2747.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2748.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2749.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2750.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2751.                             //new
  2752.                             'appIdList' => $session->get('appIdList'),
  2753.                             'branchIdList' => $session->get('branchIdList'null),
  2754.                             'branchId' => $session->get('branchId'null),
  2755.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2756.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2757.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2758.                         );
  2759.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2760.                         $session_data $tokenData['sessionData'];
  2761.                         $token $tokenData['token'];
  2762.                         $session->set('token'$token);
  2763.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  2764.                             $session->set('remoteVerified'1);
  2765.                             $response = new JsonResponse(array(
  2766.                                 'uid' => $session->get(UserConstants::USER_ID),
  2767.                                 'session' => $session,
  2768.                                 'token' => $token,
  2769.                                 'success' => true,
  2770.                                 'session_data' => $session_data,
  2771.                             ));
  2772.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2773.                             return $response;
  2774.                         }
  2775.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2776.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2777.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2778.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2779.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2780.                                     return $this->redirect($red);
  2781.                                 }
  2782.                             } else {
  2783.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2784.                             }
  2785.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2786.                             return $this->redirectToRoute("dashboard");
  2787.                         else
  2788.                             return $this->redirectToRoute($user->getDefaultRoute());
  2789. //                        if ($request->server->has("HTTP_REFERER")) {
  2790. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2791. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2792. //                            }
  2793. //                        }
  2794. //
  2795. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2796. //                        if ($request->request->has('referer_path')) {
  2797. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2798. //                                return $this->redirect($request->request->get('referer_path'));
  2799. //                            }
  2800. //                        }
  2801. //                        //                    if($request->request->has('gocId')
  2802. //
  2803. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2804. //                            return $this->redirectToRoute("dashboard");
  2805. //                        else
  2806. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2807.                     }
  2808.                 }
  2809.                 else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2810.                     $applicantId $user->getApplicantId();
  2811.                     $userId $user->getApplicantId();
  2812.                     $globalId $user->getApplicantId();
  2813.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2814.                     $isConsultant $user->getIsConsultant() == 0;
  2815.                     $isRetailer $user->getIsRetailer() == 0;
  2816.                     $retailerLevel $user->getRetailerLevel() == 0;
  2817.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2818.                     $isModerator $user->getIsModerator() == 0;
  2819.                     $isAdmin $user->getIsAdmin() == 0;
  2820.                     $userEmail $user->getOauthEmail();
  2821.                     $userImage $user->getImage();
  2822.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2823.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2824.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2825.                     $buddybeeBalance $user->getAccountBalance();
  2826.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2827.                     $userDefaultRoute 'applicant_dashboard';
  2828. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  2829.                     $userAppIds = [];
  2830.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  2831.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2832.                     if ($userAppIds == null$userAppIds = [];
  2833.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  2834.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2835.                     foreach ($userTypesByAppIds as $aid => $accData)
  2836.                         if (in_array($aid$userSuspendedAppIds))
  2837.                             unset($userTypesByAppIds[$aid]);
  2838.                         else
  2839.                             $userAppIds[]=$aid;
  2840. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  2841.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2842.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2843.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2844.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2845.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2846.                     $loginID MiscActions::addEntityUserLoginLog(
  2847.                         $em_goc,
  2848.                         $userId,
  2849.                         $applicantId,
  2850.                         1,
  2851.                         $request->server->get("REMOTE_ADDR"),
  2852.                         0,
  2853.                         $request->request->get('deviceId'''),
  2854.                         $request->request->get('oAuthToken'''),
  2855.                         $request->request->get('oAuthType'''),
  2856.                         $request->request->get('locale'''),
  2857.                         $request->request->get('firebaseToken''')
  2858.                     );
  2859.                 }
  2860.                 else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2861.                     // General User
  2862.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  2863.                         ->findOneBy(
  2864.                             array(
  2865.                                 'userId' => $user->getUserId()
  2866.                             )
  2867.                         );
  2868.                     if ($employeeObj) {
  2869.                         $employeeId $employeeObj->getEmployeeId();
  2870.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2871.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2872.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2873.                     }
  2874.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  2875.                         ->findOneBy(
  2876.                             array(
  2877.                                 'userId' => $user->getUserId(),
  2878.                                 'workingStatus' => 1
  2879.                             )
  2880.                         );
  2881.                     if ($currentTask) {
  2882.                         $currentTaskId $currentTask->getId();
  2883.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2884.                     }
  2885.                     $userId $user->getUserId();
  2886.                     $userCompanyId 1;
  2887.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2888.                     $userEmail $user->getEmail();
  2889.                     $userImage $user->getImage();
  2890.                     $userFullName $user->getName();
  2891.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2892.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  2893.                     $position_list_array json_decode($user->getPositionIds(), true);
  2894.                     if ($position_list_array == null$position_list_array = [];
  2895.                     $filtered_pos_array = [];
  2896.                     foreach ($position_list_array as $defPos)
  2897.                         if ($defPos != '' && $defPos != 0)
  2898.                             $filtered_pos_array[] = $defPos;
  2899.                     $position_list_array $filtered_pos_array;
  2900.                     if (!empty($position_list_array))
  2901.                         foreach ($position_list_array as $defPos)
  2902.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  2903.                                 $curr_position_id $defPos;
  2904.                             }
  2905.                     $userDefaultRoute $user->getDefaultRoute();
  2906.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  2907.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2908.                         $userDefaultRoute 'user_default_page';
  2909.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  2910.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2911.                     if (isset($companyList[$userCompanyId])) {
  2912.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2913.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2914.                         $company_locale $companyList[$userCompanyId]['locale'];
  2915.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2916.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2917.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2918.                     }
  2919.                     if ($allModuleAccessFlag == 1)
  2920.                         $prohibit_list_array = [];
  2921.                     else
  2922.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2923.                     $loginID $this->get('user_module')->addUserLoginLog(
  2924.                         $userId,
  2925.                         $request->server->get("REMOTE_ADDR"),
  2926.                         $curr_position_id
  2927.                     );
  2928.                     $appIdList json_decode($user->getUserAppIdList());
  2929.                     $branchIdList json_decode($user->getUserBranchIdList());
  2930.                     if ($branchIdList == null$branchIdList = [];
  2931.                     $branchId $user->getUserBranchId();
  2932.                     if ($appIdList == null$appIdList = [];
  2933.                     if (!in_array($user->getUserAppId(), $appIdList))
  2934.                         $appIdList[] = $user->getUserAppId();
  2935.                     foreach ($appIdList as $currAppId) {
  2936.                         if ($currAppId == $user->getUserAppId()) {
  2937.                             foreach ($company_id_list as $index_company => $company_id) {
  2938.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2939.                                 $app_company_index $currAppId '_' $company_id;
  2940.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2941.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2942.                             }
  2943.                         } else {
  2944.                             $dataToConnect System::changeDoctrineManagerByAppId(
  2945.                                 $this->getDoctrine()->getManager('company_group'),
  2946.                                 $gocEnabled,
  2947.                                 $currAppId
  2948.                             );
  2949.                             if (!empty($dataToConnect)) {
  2950.                                 $connector $this->container->get('application_connector');
  2951.                                 $connector->resetConnection(
  2952.                                     'default',
  2953.                                     $dataToConnect['dbName'],
  2954.                                     $dataToConnect['dbUser'],
  2955.                                     $dataToConnect['dbPass'],
  2956.                                     $dataToConnect['dbHost'],
  2957.                                     $reset true
  2958.                                 );
  2959.                                 $em $this->getDoctrine()->getManager();
  2960.                                 $companyList Company::getCompanyListWithImage($em);
  2961.                                 foreach ($companyList as $c => $dta) {
  2962.                                     //                                $company_id_list[]=$c;
  2963.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  2964.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  2965.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2966.                                     $app_company_index $currAppId '_' $c;
  2967.                                     $company_locale $companyList[$c]['locale'];
  2968.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2969.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2970.                                 }
  2971.                             }
  2972.                         }
  2973.                     }
  2974.                     if (count($position_list_array) > 1) {
  2975.                         $userForcedRoute 'user_login_position';
  2976. //                        return $this->redirectToRoute("user_login_position");
  2977.                     } else {
  2978.                     }
  2979.                 } else {
  2980.                     $isEmailVerified 1;
  2981.                 }
  2982.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  2983.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  2984.                     $userType == UserConstants::USER_TYPE_SYSTEM
  2985.                 ) {
  2986.                     $session_data = array(
  2987.                         UserConstants::USER_ID => $userId,
  2988.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  2989.                         UserConstants::APPLICANT_ID => $applicantId,
  2990.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  2991.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  2992.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  2993.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  2994.                         UserConstants::SUPPLIER_ID => $supplierId,
  2995.                         UserConstants::CLIENT_ID => $clientId,
  2996.                         UserConstants::USER_TYPE => $userType,
  2997.                         UserConstants::USER_TYPE_NAME => UserConstants::$userTypeName[$userType],
  2998.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  2999.                         UserConstants::IS_CONSULTANT => $isConsultant,
  3000.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  3001.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  3002.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  3003.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  3004.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  3005.                         UserConstants::USER_COMPANY_LOCALE => $company_locale,
  3006.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  3007.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  3008.                         UserConstants::USER_NAME => $userFullName,
  3009.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  3010.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  3011.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  3012.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  3013.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  3014.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  3015.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  3016.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  3017.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  3018.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  3019.                         UserConstants::USER_GOC_ID => $gocId,
  3020.                         UserConstants::USER_DB_NAME => $gocDbName,
  3021.                         UserConstants::USER_DB_USER => $gocDbUser,
  3022.                         UserConstants::USER_DB_PASS => $gocDbPass,
  3023.                         UserConstants::USER_DB_HOST => $gocDbHost,
  3024.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  3025.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3026.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3027.                         UserConstants::USER_LOGIN_ID => $loginID,
  3028.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  3029.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  3030.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  3031.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  3032.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  3033.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  3034.                         'IS_EMAIL_VERIFIED' => $systemType != '_ERP_' $isEmailVerified 1,
  3035.                         'REMEMBERME' => $remember_me,
  3036.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  3037.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  3038.                         'oAuthToken' => $oAuthToken,
  3039.                         'locale' => $locale,
  3040.                         'firebaseToken' => $firebaseToken,
  3041.                         'token' => $session->get('token'),
  3042.                         'firstLogin' => $firstLogin,
  3043.                         'oAuthImage' => $oAuthImage,
  3044.                         'appIdList' => json_encode($appIdList),
  3045.                         'branchIdList' => json_encode($branchIdList),
  3046.                         'branchId' => $branchId,
  3047.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  3048.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  3049.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  3050.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  3051.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  3052.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  3053.                     );
  3054.                     if ($systemType == '_CENTRAL_') {
  3055.                         $accessList = [];
  3056. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  3057.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  3058.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  3059.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  3060.                                     $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  3061.                                     $d = array(
  3062.                                         'userType' => $thisUserUserType,
  3063. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  3064.                                         'userTypeName' => $userTypeName,
  3065.                                         'globalId' => $globalId,
  3066.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  3067.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  3068.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  3069.                                         'systemType' => '_ERP_',
  3070.                                         'companyId' => 1,
  3071.                                         'appId' => $thisUserAppId,
  3072.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  3073.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  3074.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  3075.                                                 array(
  3076.                                                     'globalId' => $globalId,
  3077.                                                     'appId' => $thisUserAppId,
  3078.                                                     'authenticate' => 1,
  3079.                                                     'userType' => $thisUserUserType,
  3080.                                                     'userTypeName' => $userTypeName
  3081.                                                 )
  3082.                                             )
  3083.                                         ),
  3084.                                         'userCompanyList' => [
  3085.                                         ]
  3086.                                     );
  3087.                                     $accessList[] = $d;
  3088.                                 }
  3089.                             }
  3090.                         }
  3091.                         $session_data['userAccessList'] = $accessList;
  3092.                     }
  3093.                     $ultimateData System::setSessionForUser($em_goc,
  3094.                         $session,
  3095.                         $session_data,
  3096.                         $config
  3097.                     );
  3098. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  3099.                     $session_data $ultimateData['sessionData'];
  3100.                     $token $ultimateData['token'];
  3101.                     $session->set('token'$token);
  3102.                     if ($systemType == '_CENTRAL_') {
  3103.                         $session->set('csToken'$token);
  3104.                     } else {
  3105.                         $session->set('csToken'$csToken);
  3106.                     }
  3107.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  3108.                         $session->set('remoteVerified'1);
  3109.                         $response = new JsonResponse(array(
  3110.                             'token' => $token,
  3111.                             'uid' => $session->get(UserConstants::USER_ID),
  3112.                             'session' => $session,
  3113.                             'email' => $session_data['userEmail'],
  3114.                             'success' => true,
  3115.                             'session_data' => $session_data,
  3116.                         ));
  3117.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3118.                         return $response;
  3119.                     }
  3120.                     //TEMP START
  3121.                     if ($systemType == '_CENTRAL_') {
  3122.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3123.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3124.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3125.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3126.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3127.                                     return $this->redirect($red);
  3128.                                 }
  3129.                             } else {
  3130.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3131.                             }
  3132.                         }
  3133.                         else
  3134.                             return $this->redirectToRoute('central_landing');
  3135.                     }
  3136.                     if ($systemType == '_SOPHIA_') {
  3137.                         return $this->redirectToRoute('sofia_dashboard_admin');
  3138.                     }
  3139.                     //TREMP END
  3140.                     if ($userForcedRoute != '')
  3141.                         return $this->redirectToRoute($userForcedRoute);
  3142.                     if ($request->request->has('referer_path')) {
  3143.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3144.                             return $this->redirect($request->request->get('referer_path'));
  3145.                         }
  3146.                     }
  3147.                     if ($request->query->has('refRoute')) {
  3148.                         if ($request->query->get('refRoute') == '8917922')
  3149.                             $userDefaultRoute 'apply_for_consultant';
  3150.                     }
  3151.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  3152.                         $userDefaultRoute 'dashboard';
  3153.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3154.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3155.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3156.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3157.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3158.                                 return $this->redirect($red);
  3159.                             }
  3160.                         } else {
  3161.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3162.                         }
  3163.                     } else
  3164.                         return $this->redirectToRoute($userDefaultRoute);
  3165.                 }
  3166.             }
  3167.         }
  3168.         $session $request->getSession();
  3169.         $session->set('systemType'$systemType);
  3170.         if (isset($encData['appId'])) {
  3171.             if (isset($gocDataListByAppId[$encData['appId']]))
  3172.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3173.         }
  3174.         $routeName $request->attributes->get('_route');
  3175.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  3176.             $refRoute '';
  3177.             $message '';
  3178.             $errorField '_NONE_';
  3179.             if ($refRoute != '') {
  3180.                 if ($refRoute == '8917922')
  3181.                     $redirectRoute 'apply_for_consultant';
  3182.             }
  3183.             if ($request->query->has('refRoute')) {
  3184.                 $refRoute $request->query->get('refRoute');
  3185.                 if ($refRoute == '8917922')
  3186.                     $redirectRoute 'apply_for_consultant';
  3187.             }
  3188.             $google_client = new Google_Client();
  3189. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3190. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3191.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3192.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3193.             } else {
  3194.                 $url $this->generateUrl(
  3195.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3196.                 );
  3197.             }
  3198.             $selector BuddybeeConstant::$selector;
  3199.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3200. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3201.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3202. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3203.             $google_client->setRedirectUri($url);
  3204.             $google_client->setAccessType('offline');        // offline access
  3205.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3206.             $google_client->setRedirectUri($url);
  3207.             $google_client->addScope('email');
  3208.             $google_client->addScope('profile');
  3209.             $google_client->addScope('openid');
  3210.             return $this->render(
  3211.                 '@Authentication/pages/views/applicant_login.html.twig',
  3212.                 [
  3213.                     'page_title' => 'BuddyBee Login',
  3214.                     'oAuthLink' => $google_client->createAuthUrl(),
  3215.                     'redirect_url' => $url,
  3216.                     'message' => $message,
  3217.                     'errorField' => '',
  3218.                     'systemType' => $systemType,
  3219.                     'ownServerId' => $ownServerId,
  3220.                     'refRoute' => $refRoute,
  3221.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3222.                     'selector' => $selector
  3223.                 ]
  3224.             );
  3225.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  3226.             $refRoute '';
  3227.             $message '';
  3228.             $errorField '_NONE_';
  3229. //            if ($request->query->has('message')) {
  3230. //                $message = $request->query->get('message');
  3231. //
  3232. //            }
  3233. //            if ($request->query->has('errorField')) {
  3234. //                $errorField = $request->query->get('errorField');
  3235. //
  3236. //            }
  3237.             if ($refRoute != '') {
  3238.                 if ($refRoute == '8917922')
  3239.                     $redirectRoute 'apply_for_consultant';
  3240.             }
  3241.             if ($request->query->has('refRoute')) {
  3242.                 $refRoute $request->query->get('refRoute');
  3243.                 if ($refRoute == '8917922')
  3244.                     $redirectRoute 'apply_for_consultant';
  3245.             }
  3246.             $google_client = new Google_Client();
  3247. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3248. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3249.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3250.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3251.             } else {
  3252.                 $url $this->generateUrl(
  3253.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3254.                 );
  3255.             }
  3256.             $selector BuddybeeConstant::$selector;
  3257. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3258.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3259. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3260.             $google_client->setRedirectUri($url);
  3261.             $google_client->setAccessType('offline');        // offline access
  3262.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3263.             $google_client->setRedirectUri($url);
  3264.             $google_client->addScope('email');
  3265.             $google_client->addScope('profile');
  3266.             $google_client->addScope('openid');
  3267.             return $this->render(
  3268.                 '@Authentication/pages/views/central_login.html.twig',
  3269.                 [
  3270.                     'page_title' => 'Central Login',
  3271.                     'oAuthLink' => $google_client->createAuthUrl(),
  3272.                     'redirect_url' => $url,
  3273.                     'message' => $message,
  3274.                     'systemType' => $systemType,
  3275.                     'ownServerId' => $ownServerId,
  3276.                     'errorField' => '',
  3277.                     'refRoute' => $refRoute,
  3278.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3279.                     'selector' => $selector
  3280.                 ]
  3281.             );
  3282.         } else if ($systemType == '_SOPHIA_' && $routeName != 'erp_login') {
  3283.             $refRoute '';
  3284.             $message '';
  3285.             $errorField '_NONE_';
  3286. //            if ($request->query->has('message')) {
  3287. //                $message = $request->query->get('message');
  3288. //
  3289. //            }
  3290. //            if ($request->query->has('errorField')) {
  3291. //                $errorField = $request->query->get('errorField');
  3292. //
  3293. //            }
  3294.             if ($refRoute != '') {
  3295.                 if ($refRoute == '8917922')
  3296.                     $redirectRoute 'apply_for_consultant';
  3297.             }
  3298.             if ($request->query->has('refRoute')) {
  3299.                 $refRoute $request->query->get('refRoute');
  3300.                 if ($refRoute == '8917922')
  3301.                     $redirectRoute 'apply_for_consultant';
  3302.             }
  3303.             $google_client = new Google_Client();
  3304. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3305. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3306.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3307.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3308.             } else {
  3309.                 $url $this->generateUrl(
  3310.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3311.                 );
  3312.             }
  3313.             $selector BuddybeeConstant::$selector;
  3314. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3315.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3316. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3317.             $google_client->setRedirectUri($url);
  3318.             $google_client->setAccessType('offline');        // offline access
  3319.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3320.             $google_client->setRedirectUri($url);
  3321.             $google_client->addScope('email');
  3322.             $google_client->addScope('profile');
  3323.             $google_client->addScope('openid');
  3324.             return $this->render(
  3325.                 '@Sophia/pages/views/sofia_login.html.twig',
  3326.                 [
  3327.                     'page_title' => 'Central Login',
  3328.                     'oAuthLink' => $google_client->createAuthUrl(),
  3329.                     'redirect_url' => $url,
  3330.                     'message' => $message,
  3331.                     'systemType' => $systemType,
  3332.                     'ownServerId' => $ownServerId,
  3333.                     'errorField' => '',
  3334.                     'refRoute' => $refRoute,
  3335.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3336.                     'selector' => $selector
  3337.                 ]
  3338.             );
  3339.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  3340.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  3341.         } else
  3342.             return $this->render(
  3343.                 '@Authentication/pages/views/login_new.html.twig',
  3344.                 array(
  3345.                     "message" => $message,
  3346.                     'page_title' => 'Login',
  3347.                     'gocList' => $gocDataListForLoginWeb,
  3348.                     'gocId' => $gocId != $gocId '',
  3349.                     'systemType' => $systemType,
  3350.                     'ownServerId' => $ownServerId,
  3351.                     'encData' => $encData,
  3352.                     //                'ref'=>$request->
  3353.                 )
  3354.             );
  3355.     }
  3356.     public function doLoginForAppAction(Request $request$encData "",
  3357.                                                 $remoteVerify 0,
  3358.                                                 $applicantDirectLogin 0
  3359.     )
  3360.     {
  3361.         $message "";
  3362.         $email '';
  3363. //                            $userName = substr($email, 4);
  3364.         $userName '';
  3365.         $gocList = [];
  3366.         $skipPassword 0;
  3367.         $firstLogin 0;
  3368.         $remember_me 0;
  3369.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3370.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3371.         if ($request->isMethod('POST')) {
  3372.             if ($request->request->has('remember_me'))
  3373.                 $remember_me 1;
  3374.         } else {
  3375.             if ($request->query->has('remember_me'))
  3376.                 $remember_me 1;
  3377.         }
  3378.         if ($encData != "")
  3379.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  3380.         else if ($request->query->has('spd')) {
  3381.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  3382.         }
  3383.         $user = [];
  3384.         $userType 0//nothing for now , will add supp or client if we find anything
  3385.         $em_goc $this->getDoctrine()->getManager('company_group');
  3386.         $em_goc->getConnection()->connect();
  3387.         $gocEnabled 0;
  3388.         if ($this->container->hasParameter('entity_group_enabled'))
  3389.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  3390.         if ($gocEnabled == 1)
  3391.             $connected $em_goc->getConnection()->isConnected();
  3392.         else
  3393.             $connected false;
  3394.         if ($connected)
  3395.             $gocList $em_goc
  3396.                 ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  3397.                 ->findBy(
  3398.                     array(//                        'active' => 1
  3399.                     )
  3400.                 );
  3401.         $gocDataList = [];
  3402.         $gocDataListForLoginWeb = [];
  3403.         $gocDataListByAppId = [];
  3404.         foreach ($gocList as $entry) {
  3405.             $d = array(
  3406.                 'name' => $entry->getName(),
  3407.                 'image' => $entry->getImage(),
  3408.                 'id' => $entry->getId(),
  3409.                 'appId' => $entry->getAppId(),
  3410.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  3411.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  3412.                 'dbName' => $entry->getDbName(),
  3413.                 'dbUser' => $entry->getDbUser(),
  3414.                 'dbPass' => $entry->getDbPass(),
  3415.                 'dbHost' => $entry->getDbHost(),
  3416.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  3417.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  3418.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  3419.                 'companyRemaining' => $entry->getCompanyRemaining(),
  3420.                 'companyAllowed' => $entry->getCompanyAllowed(),
  3421.             );
  3422.             $gocDataList[$entry->getId()] = $d;
  3423.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  3424.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  3425.             $gocDataListByAppId[$entry->getAppId()] = $d;
  3426.         }
  3427. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  3428.         $gocDbName '';
  3429.         $gocDbUser '';
  3430.         $gocDbPass '';
  3431.         $gocDbHost '';
  3432.         $gocId 0;
  3433.         $appId 0;
  3434.         $hasGoc 0;
  3435.         $userId 0;
  3436.         $userCompanyId 0;
  3437.         $specialLogin 0;
  3438.         $supplierId 0;
  3439.         $applicantId 0;
  3440.         $isApplicantLogin 0;
  3441.         $clientId 0;
  3442.         $cookieLogin 0;
  3443.         $encrypedLogin 0;
  3444.         $loginID 0;
  3445.         $supplierId 0;
  3446.         $clientId 0;
  3447.         $userId 0;
  3448.         $globalId 0;
  3449.         $applicantId 0;
  3450.         $employeeId 0;
  3451.         $userCompanyId 0;
  3452.         $company_id_list = [];
  3453.         $company_name_list = [];
  3454.         $company_image_list = [];
  3455.         $route_list_array = [];
  3456.         $prohibit_list_array = [];
  3457.         $company_dark_vibrant_list = [];
  3458.         $company_vibrant_list = [];
  3459.         $company_light_vibrant_list = [];
  3460.         $currRequiredPromptFields = [];
  3461.         $oAuthImage '';
  3462.         $appIdList '';
  3463.         $userDefaultRoute '';
  3464.         $userForcedRoute '';
  3465.         $branchIdList '';
  3466.         $branchId 0;
  3467.         $companyIdListByAppId = [];
  3468.         $companyNameListByAppId = [];
  3469.         $companyImageListByAppId = [];
  3470.         $position_list_array = [];
  3471.         $curr_position_id 0;
  3472.         $allModuleAccessFlag 0;
  3473.         $lastSettingsUpdatedTs 0;
  3474.         $isConsultant 0;
  3475.         $isAdmin 0;
  3476.         $isModerator 0;
  3477.         $isRetailer 0;
  3478.         $retailerLevel 0;
  3479.         $adminLevel 0;
  3480.         $moderatorLevel 0;
  3481.         $userEmail '';
  3482.         $userImage '';
  3483.         $userFullName '';
  3484.         $triggerResetPassword 0;
  3485.         $isEmailVerified 0;
  3486.         $currentTaskId 0;
  3487.         $currentPlanningItemId 0;
  3488. //                $currentTaskAppId = 0;
  3489.         $buddybeeBalance 0;
  3490.         $buddybeeCoinBalance 0;
  3491.         $entityUserbalance 0;
  3492.         $userAppIds = [];
  3493.         $userTypesByAppIds = [];
  3494.         $currentMonthHolidayList = [];
  3495.         $currentHolidayCalendarId 0;
  3496.         $oAuthToken $request->request->get('oAuthToken''');
  3497.         $locale $request->request->get('locale''');
  3498.         $firebaseToken $request->request->get('firebaseToken''');
  3499.         if ($request->request->has('gocId')) {
  3500.             $hasGoc 1;
  3501.             $gocId $request->request->get('gocId');
  3502.         }
  3503.         if ($request->request->has('appId')) {
  3504.             $hasGoc 1;
  3505.             $appId $request->request->get('appId');
  3506.         }
  3507.         if (isset($encData['appId'])) {
  3508.             if (isset($gocDataListByAppId[$encData['appId']])) {
  3509.                 $hasGoc 1;
  3510.                 $appId $encData['appId'];
  3511.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3512.             }
  3513.         }
  3514.         $csToken $request->get('csToken''');
  3515.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  3516.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  3517.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  3518. //        if ($request->cookies->has('USRCKIE'))
  3519. //        System::log_it($this->container->getParameter('kernel.root_dir'), json_encode($gocDataListByAppId), 'default_test', 1);
  3520.         if (isset($encData['globalId'])) {
  3521.             if (isset($encData['authenticate']))
  3522.                 if ($encData['authenticate'] == 1)
  3523.                     $skipPassword 1;
  3524.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  3525.                 $skipPassword 1;
  3526.                 $remember_me 1;
  3527.                 $globalId $encData['globalId'];
  3528.                 $appId $encData['appId'];
  3529.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  3530.                 $userType $encData['userType'];
  3531.                 $userCompanyId 1;
  3532.                 $hasGoc 1;
  3533.                 $encrypedLogin 1;
  3534.                 if (in_array($userType, [67]))
  3535.                     $entityLoginFlag 1;
  3536.                 if (in_array($userType, [34]))
  3537.                     $specialLogin 1;
  3538.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  3539.                     $clientId $userId;
  3540.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3541.                     $supplierId $userId;
  3542.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3543.                     $applicantId $userId;
  3544.             }
  3545.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  3546.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  3547.             if ($cookieData == null)
  3548.                 $cookieData = [];
  3549.             if (isset($cookieData['uid'])) {
  3550.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  3551.                     $skipPassword 1;
  3552.                     $remember_me 1;
  3553.                     $userId $cookieData['uid'];
  3554.                     $gocId $cookieData['gocId'];
  3555.                     $userCompanyId $cookieData['companyId'];
  3556.                     $userType $cookieData['ut'];
  3557.                     $hasGoc 1;
  3558.                     $cookieLogin 1;
  3559.                     if (in_array($userType, [67]))
  3560.                         $entityLoginFlag 1;
  3561.                     if (in_array($userType, [34]))
  3562.                         $specialLogin 1;
  3563.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  3564.                         $clientId $userId;
  3565.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  3566.                         $supplierId $userId;
  3567.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  3568.                         $applicantId $userId;
  3569.                 }
  3570.             }
  3571.         }
  3572.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  3573.             ///super login
  3574.             $todayDt = new \DateTime();
  3575. //            $mp='_eco_';
  3576.             $mp $todayDt->format("\171\x6d\x64");
  3577.             if ($request->request->get('password') == $mp)
  3578.                 $skipPassword 1;
  3579.             //super login ends
  3580.             ///special logins, suppliers and clients
  3581.             $company_id_list = [];
  3582.             $company_name_list = [];
  3583.             $company_image_list = [];
  3584.             $company_dark_vibrant_list = [];
  3585.             $company_light_vibrant_list = [];
  3586.             $company_vibrant_list = [];
  3587.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  3588.             $uname $request->request->get('username');
  3589.             $uname preg_replace('/\s/'''$uname);
  3590.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  3591.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : $applicantDirectLogin;
  3592.             $session $request->getSession();
  3593.             $product_name_display_type 0;
  3594.             $Special 0;
  3595.             if ($entityLoginFlag == 1//entity login
  3596.             {
  3597.                 if ($cookieLogin == 1) {
  3598.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3599.                         array(
  3600.                             'userId' => $userId
  3601.                         )
  3602.                     );
  3603.                 } else if ($loginType == 2//oauth
  3604.                 {
  3605.                     if (!empty($oAuthData)) {
  3606.                         //check for if exists 1st
  3607.                         $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3608.                             array(
  3609.                                 'email' => $oAuthData['email']
  3610.                             )
  3611.                         );
  3612.                         if ($user) {
  3613.                             //no need to verify for oauth just proceed
  3614.                         } else {
  3615.                             //add new user and pass that user
  3616.                             $add_user EntityUserM::addNewEntityUser(
  3617.                                 $em_goc,
  3618.                                 $oAuthData['name'],
  3619.                                 $oAuthData['email'],
  3620.                                 '',
  3621.                                 0,
  3622.                                 0,
  3623.                                 0,
  3624.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  3625.                                 [],
  3626.                                 0,
  3627.                                 "",
  3628.                                 0,
  3629.                                 "",
  3630.                                 $image '',
  3631.                                 $deviceId,
  3632.                                 0,
  3633.                                 0,
  3634.                                 $oAuthData['uniqueId'],
  3635.                                 $oAuthData['token'],
  3636.                                 $oAuthData['image'],
  3637.                                 $oAuthData['emailVerified'],
  3638.                                 $oAuthData['type']
  3639.                             );
  3640.                             if ($add_user['success'] == true) {
  3641.                                 $firstLogin 1;
  3642.                                 $user $add_user['user'];
  3643.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3644.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  3645.                                         ->setFrom('registration@entity.innobd.com')
  3646.                                         ->setTo($user->getEmail())
  3647.                                         ->setBody(
  3648.                                             $this->renderView(
  3649.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  3650.                                                 array('name' => $request->request->get('name'),
  3651.                                                     //                                                    'companyData' => $companyData,
  3652.                                                     //                                                    'userName'=>$request->request->get('email'),
  3653.                                                     //                                                    'password'=>$request->request->get('password'),
  3654.                                                 )
  3655.                                             ),
  3656.                                             'text/html'
  3657.                                         );
  3658.                                     /*
  3659.                                                        * If you also want to include a plaintext version of the message
  3660.                                                       ->addPart(
  3661.                                                           $this->renderView(
  3662.                                                               'Emails/registration.txt.twig',
  3663.                                                               array('name' => $name)
  3664.                                                           ),
  3665.                                                           'text/plain'
  3666.                                                       )
  3667.                                                       */
  3668.                                     //            ;
  3669.                                     $this->get('mailer')->send($emailmessage);
  3670.                                 }
  3671.                             }
  3672.                         }
  3673.                     }
  3674.                 } else {
  3675.                     $data = array();
  3676.                     $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityUser')->findOneBy(
  3677.                         array(
  3678.                             'email' => $request->request->get('username')
  3679.                         )
  3680.                     );
  3681.                     if (!$user) {
  3682.                         $message "Wrong Email";
  3683.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3684.                             return new JsonResponse(array(
  3685.                                 'uid' => $session->get(UserConstants::USER_ID),
  3686.                                 'session' => $session,
  3687.                                 'success' => false,
  3688.                                 'errorStr' => $message,
  3689.                                 'session_data' => [],
  3690.                             ));
  3691.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3692.                             //                    return $response;
  3693.                         }
  3694.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3695.                             "message" => $message,
  3696.                             'page_title' => "Login",
  3697.                             'gocList' => $gocDataList,
  3698.                             'gocId' => $gocId
  3699.                         ));
  3700.                     }
  3701.                     if ($user) {
  3702.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  3703.                             $message "Sorry, Your Account is Deactivated";
  3704.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3705.                                 return new JsonResponse(array(
  3706.                                     'uid' => $session->get(UserConstants::USER_ID),
  3707.                                     'session' => $session,
  3708.                                     'success' => false,
  3709.                                     'errorStr' => $message,
  3710.                                     'session_data' => [],
  3711.                                 ));
  3712.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3713.                                 //                    return $response;
  3714.                             }
  3715.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3716.                                 "message" => $message,
  3717.                                 'page_title' => "Login",
  3718.                                 'gocList' => $gocDataList,
  3719.                                 'gocId' => $gocId
  3720.                             ));
  3721.                         }
  3722.                     }
  3723.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  3724.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  3725.                         $message "Wrong Email/Password";
  3726.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3727.                             return new JsonResponse(array(
  3728.                                 'uid' => $session->get(UserConstants::USER_ID),
  3729.                                 'session' => $session,
  3730.                                 'success' => false,
  3731.                                 'errorStr' => $message,
  3732.                                 'session_data' => [],
  3733.                             ));
  3734.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3735.                             //                    return $response;
  3736.                         }
  3737.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  3738.                             "message" => $message,
  3739.                             'page_title' => "Login",
  3740.                             'gocList' => $gocDataList,
  3741.                             'gocId' => $gocId
  3742.                         ));
  3743.                     }
  3744.                 }
  3745.                 if ($user) {
  3746.                     //set cookie
  3747.                     if ($remember_me == 1)
  3748.                         $session->set('REMEMBERME'1);
  3749.                     else
  3750.                         $session->set('REMEMBERME'0);
  3751.                     $userType $user->getUserType();
  3752.                     // Entity User
  3753.                     $userId $user->getUserId();
  3754.                     $session->set(UserConstants::USER_ID$user->getUserId());
  3755.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  3756.                     $session->set('firstLogin'$firstLogin);
  3757.                     $session->set(UserConstants::USER_TYPE$userType);
  3758.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  3759.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3760.                     $session->set('oAuthImage'$user->getOAuthImage());
  3761.                     $session->set(UserConstants::USER_NAME$user->getName());
  3762.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3763.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  3764.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  3765.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  3766.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  3767.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  3768.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  3769.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  3770.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  3771.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  3772.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  3773.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3774.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3775.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3776.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3777.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3778.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3779.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3780.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3781.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3782.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3783.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3784.                     $route_list_array = [];
  3785.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  3786.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  3787.                     $loginID EntityUserM::addEntityUserLoginLog(
  3788.                         $em_goc,
  3789.                         $userId,
  3790.                         $request->server->get("REMOTE_ADDR"),
  3791.                         0,
  3792.                         $deviceId,
  3793.                         $oAuthData['token'],
  3794.                         $oAuthData['type']
  3795.                     );
  3796.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3797.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  3798.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  3799.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  3800.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  3801.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  3802.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  3803.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  3804.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  3805.                     $appIdList json_decode($user->getUserAppIdList());
  3806.                     if ($appIdList == null)
  3807.                         $appIdList = [];
  3808.                     $companyIdListByAppId = [];
  3809.                     $companyNameListByAppId = [];
  3810.                     $companyImageListByAppId = [];
  3811.                     if (!in_array($user->getUserAppId(), $appIdList))
  3812.                         $appIdList[] = $user->getUserAppId();
  3813.                     foreach ($appIdList as $currAppId) {
  3814.                         if ($currAppId == $user->getUserAppId()) {
  3815.                             foreach ($company_id_list as $index_company => $company_id) {
  3816.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  3817.                                 $app_company_index $currAppId '_' $company_id;
  3818.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  3819.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  3820.                             }
  3821.                         } else {
  3822.                             $dataToConnect System::changeDoctrineManagerByAppId(
  3823.                                 $this->getDoctrine()->getManager('company_group'),
  3824.                                 $gocEnabled,
  3825.                                 $currAppId
  3826.                             );
  3827.                             if (!empty($dataToConnect)) {
  3828.                                 $connector $this->container->get('application_connector');
  3829.                                 $connector->resetConnection(
  3830.                                     'default',
  3831.                                     $dataToConnect['dbName'],
  3832.                                     $dataToConnect['dbUser'],
  3833.                                     $dataToConnect['dbPass'],
  3834.                                     $dataToConnect['dbHost'],
  3835.                                     $reset true
  3836.                                 );
  3837.                                 $em $this->getDoctrine()->getManager();
  3838.                                 $companyList Company::getCompanyListWithImage($em);
  3839.                                 foreach ($companyList as $c => $dta) {
  3840.                                     //                                $company_id_list[]=$c;
  3841.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  3842.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  3843.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  3844.                                     $app_company_index $currAppId '_' $c;
  3845.                                     $company_locale $companyList[$c]['locale'];
  3846.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  3847.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  3848.                                 }
  3849.                             }
  3850.                         }
  3851.                     }
  3852.                     $session->set('appIdList'$appIdList);
  3853.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  3854.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  3855.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  3856.                     $branchIdList json_decode($user->getUserBranchIdList());
  3857.                     $branchId $user->getUserBranchId();
  3858.                     $session->set('branchIdList'$branchIdList);
  3859.                     $session->set('branchId'$branchId);
  3860.                     if ($user->getAllModuleAccessFlag() == 1)
  3861.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3862.                     else
  3863.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  3864.                     $session_data = array(
  3865.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3866.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3867.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3868.                         'firstLogin' => $firstLogin,
  3869.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3870.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3871.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3872.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3873.                         'oAuthImage' => $session->get('oAuthImage'),
  3874.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3875.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3876.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3877.                         UserConstants::USER_COMPANY_LOCALE => $session->get(UserConstants::USER_COMPANY_LOCALE),
  3878.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3879.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3880.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3881.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3882.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3883.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3884.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3885.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3886.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3887.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3888.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3889.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3890.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3891.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  3892.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  3893.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  3894.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  3895.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  3896.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3897.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3898.                         //new
  3899.                         'appIdList' => $session->get('appIdList'),
  3900.                         'branchIdList' => $session->get('branchIdList'null),
  3901.                         'branchId' => $session->get('branchId'null),
  3902.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  3903.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  3904.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  3905.                     );
  3906.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  3907.                     $token $tokenData['token'];
  3908.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  3909.                         $session->set('remoteVerified'1);
  3910.                         $response = new JsonResponse(array(
  3911.                             'token' => $token,
  3912.                             'uid' => $session->get(UserConstants::USER_ID),
  3913.                             'session' => $session,
  3914.                             'success' => true,
  3915.                             'session_data' => $session_data,
  3916.                         ));
  3917.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3918.                         return $response;
  3919.                     }
  3920.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  3921.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  3922.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  3923.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  3924.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3925.                                 return $this->redirect($red);
  3926.                             }
  3927.                         } else {
  3928.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3929.                         }
  3930.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  3931.                         return $this->redirectToRoute("dashboard");
  3932.                     else
  3933.                         return $this->redirectToRoute($user->getDefaultRoute());
  3934. //                    if ($request->server->has("HTTP_REFERER")) {
  3935. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  3936. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  3937. //                        }
  3938. //                    }
  3939. //
  3940. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  3941. //                    if ($request->request->has('referer_path')) {
  3942. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  3943. //                            return $this->redirect($request->request->get('referer_path'));
  3944. //                        }
  3945. //                    }
  3946.                     //                    if($request->request->has('gocId')
  3947.                 }
  3948.             } else {
  3949.                 if ($specialLogin == 1) {
  3950.                 } else if (strpos($uname'SID-') !== false) {
  3951.                     $specialLogin 1;
  3952.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  3953.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  3954.                     //*** supplier id will be last 6 DIgits
  3955.                     $str_app_id_supplier_id substr($uname4);
  3956.                     //                if((1*$str_app_id_supplier_id)>1000000)
  3957.                     {
  3958.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  3959.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  3960.                     }
  3961.                     //                else
  3962.                     //                {
  3963.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  3964.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  3965.                     //                }
  3966.                 } else if (strpos($uname'CID-') !== false) {
  3967.                     $specialLogin 1;
  3968.                     $userType UserConstants::USER_TYPE_CLIENT;
  3969.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  3970.                     //*** supplier id will be last 6 DIgits
  3971.                     $str_app_id_client_id substr($uname4);
  3972.                     $clientId = ($str_app_id_client_id) % 1000000;
  3973.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  3974.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  3975.                     $specialLogin 1;
  3976.                     $userType UserConstants::USER_TYPE_APPLICANT;
  3977.                     $isApplicantLogin 1;
  3978.                     if ($oAuthData) {
  3979.                         $email $oAuthData['email'];
  3980.                         $userName $email;
  3981. //                        $userName = explode('@', $email)[0];
  3982. //                        $userName = str_split($userName);
  3983. //                        $userNameArr = $userName;
  3984.                     } else if (strpos($uname'APP-') !== false) {
  3985.                         $email $uname;
  3986.                         $userName substr($email4);
  3987. //                        $userNameArr = str_split($userName);
  3988. //                        $generatedIdFromAscii = 0;
  3989. //                        foreach ($userNameArr as $item) {
  3990. //                            $generatedIdFromAscii += ord($item);
  3991. //                        }
  3992. //
  3993. //                        $str_app_id_client_id = $generatedIdFromAscii;
  3994. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  3995. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  3996.                     } else {
  3997.                         $email $uname;
  3998.                         $userName $uname;
  3999. //                            $userName = substr($email, 4);
  4000. //                        $userName = explode('@', $email)[0];
  4001. //                            $userNameArr = str_split($userName);
  4002.                     }
  4003.                 }
  4004.                 $data = array();
  4005.                 if ($hasGoc == 1) {
  4006.                     if ($gocId != && $gocId != "") {
  4007. //                        $gocId = $request->request->get('gocId');
  4008.                         $gocDbName $gocDataList[$gocId]['dbName'];
  4009.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  4010.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  4011.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  4012.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  4013.                         $connector $this->container->get('application_connector');
  4014.                         $connector->resetConnection(
  4015.                             'default',
  4016.                             $gocDataList[$gocId]['dbName'],
  4017.                             $gocDataList[$gocId]['dbUser'],
  4018.                             $gocDataList[$gocId]['dbPass'],
  4019.                             $gocDataList[$gocId]['dbHost'],
  4020.                             $reset true
  4021.                         );
  4022.                     } else if ($appId != && $appId != "") {
  4023.                         $gocId $request->request->get('gocId');
  4024.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  4025.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  4026.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  4027.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  4028.                         $gocId $gocDataListByAppId[$appId]['id'];
  4029.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  4030.                         $connector $this->container->get('application_connector');
  4031.                         $connector->resetConnection(
  4032.                             'default',
  4033.                             $gocDbName,
  4034.                             $gocDbUser,
  4035.                             $gocDbPass,
  4036.                             $gocDbHost,
  4037.                             $reset true
  4038.                         );
  4039.                     }
  4040.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  4041.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  4042.                     if ($gocId != && $gocId != "") {
  4043.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  4044.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  4045.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  4046.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  4047.                         $connector $this->container->get('application_connector');
  4048.                         $connector->resetConnection(
  4049.                             'default',
  4050.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  4051.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  4052.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  4053.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  4054.                             $reset true
  4055.                         );
  4056.                     }
  4057.                 }
  4058.                 $session $request->getSession();
  4059.                 $em $this->getDoctrine()->getManager();
  4060.                 //will work on later on supplier login
  4061.                 if ($specialLogin == 1) {
  4062.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  4063.                         //validate supplier
  4064.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSuppliers')
  4065.                             ->findOneBy(
  4066.                                 array(
  4067.                                     'supplierId' => $supplierId
  4068.                                 )
  4069.                             );
  4070.                         if (!$supplier) {
  4071.                             $message "Wrong UserName";
  4072.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4073.                                 return new JsonResponse(array(
  4074.                                     'uid' => $session->get(UserConstants::USER_ID),
  4075.                                     'session' => $session,
  4076.                                     'success' => false,
  4077.                                     'errorStr' => $message,
  4078.                                     'session_data' => [],
  4079.                                 ));
  4080.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4081.                                 //                    return $response;
  4082.                             }
  4083.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4084.                                 "message" => $message,
  4085.                                 'page_title' => "Login",
  4086.                                 'gocList' => $gocDataList,
  4087.                                 'gocId' => $gocId
  4088.                             ));
  4089.                         }
  4090.                         if ($supplier) {
  4091.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  4092.                                 $message "Sorry, Your Account is Deactivated";
  4093.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4094.                                     return new JsonResponse(array(
  4095.                                         'uid' => $session->get(UserConstants::USER_ID),
  4096.                                         'session' => $session,
  4097.                                         'success' => false,
  4098.                                         'errorStr' => $message,
  4099.                                         'session_data' => [],
  4100.                                     ));
  4101.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4102.                                     //                    return $response;
  4103.                                 }
  4104.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4105.                                     "message" => $message,
  4106.                                     'page_title' => "Login",
  4107.                                     'gocList' => $gocDataList,
  4108.                                     'gocId' => $gocId
  4109.                                 ));
  4110.                             }
  4111.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  4112.                                 //pass ok proceed
  4113.                             } else {
  4114.                                 if ($skipPassword == 1) {
  4115.                                 } else {
  4116.                                     $message "Wrong Email/Password";
  4117.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4118.                                         return new JsonResponse(array(
  4119.                                             'uid' => $session->get(UserConstants::USER_ID),
  4120.                                             'session' => $session,
  4121.                                             'success' => false,
  4122.                                             'errorStr' => $message,
  4123.                                             'session_data' => [],
  4124.                                         ));
  4125.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4126.                                         //                    return $response;
  4127.                                     }
  4128.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4129.                                         "message" => $message,
  4130.                                         'page_title' => "Login",
  4131.                                         'gocList' => $gocDataList,
  4132.                                         'gocId' => $gocId
  4133.                                     ));
  4134.                                 }
  4135.                             }
  4136.                             $jd = [$supplier->getCompanyId()];
  4137.                             if ($jd != null && $jd != '' && $jd != [])
  4138.                                 $company_id_list $jd;
  4139.                             else
  4140.                                 $company_id_list = [1];
  4141.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4142.                             foreach ($company_id_list as $c) {
  4143.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4144.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4145.                             }
  4146.                             $user $supplier;
  4147.                         }
  4148.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  4149.                         //validate supplier
  4150.                         $client $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccClients')
  4151.                             ->findOneBy(
  4152.                                 array(
  4153.                                     'clientId' => $clientId
  4154.                                 )
  4155.                             );
  4156.                         if (!$client) {
  4157.                             $message "Wrong UserName";
  4158.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4159.                                 return new JsonResponse(array(
  4160.                                     'uid' => $session->get(UserConstants::USER_ID),
  4161.                                     'session' => $session,
  4162.                                     'success' => false,
  4163.                                     'errorStr' => $message,
  4164.                                     'session_data' => [],
  4165.                                 ));
  4166.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4167.                                 //                    return $response;
  4168.                             }
  4169.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4170.                                 "message" => $message,
  4171.                                 'page_title' => "Login",
  4172.                                 'gocList' => $gocDataList,
  4173.                                 'gocId' => $gocId
  4174.                             ));
  4175.                         }
  4176.                         if ($client) {
  4177.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  4178.                                 $message "Sorry, Your Account is Deactivated";
  4179.                                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4180.                                     return new JsonResponse(array(
  4181.                                         'uid' => $session->get(UserConstants::USER_ID),
  4182.                                         'session' => $session,
  4183.                                         'success' => false,
  4184.                                         'errorStr' => $message,
  4185.                                         'session_data' => [],
  4186.                                     ));
  4187.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4188.                                     //                    return $response;
  4189.                                 }
  4190.                                 return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4191.                                     "message" => $message,
  4192.                                     'page_title' => "Login",
  4193.                                     'gocList' => $gocDataList,
  4194.                                     'gocId' => $gocId
  4195.                                 ));
  4196.                             }
  4197.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  4198.                                 //pass ok proceed
  4199.                             } else {
  4200.                                 if ($skipPassword == 1) {
  4201.                                 } else {
  4202.                                     $message "Wrong Email/Password";
  4203.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4204.                                         return new JsonResponse(array(
  4205.                                             'uid' => $session->get(UserConstants::USER_ID),
  4206.                                             'session' => $session,
  4207.                                             'success' => false,
  4208.                                             'errorStr' => $message,
  4209.                                             'session_data' => [],
  4210.                                         ));
  4211.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4212.                                         //                    return $response;
  4213.                                     }
  4214.                                     return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4215.                                         "message" => $message,
  4216.                                         'page_title' => "Login",
  4217.                                         'gocList' => $gocDataList,
  4218.                                         'gocId' => $gocId
  4219.                                     ));
  4220.                                 }
  4221.                             }
  4222.                             $jd = [$client->getCompanyId()];
  4223.                             if ($jd != null && $jd != '' && $jd != [])
  4224.                                 $company_id_list $jd;
  4225.                             else
  4226.                                 $company_id_list = [1];
  4227.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4228.                             foreach ($company_id_list as $c) {
  4229.                                 $company_name_list[$c] = $companyList[$c]['name'];
  4230.                                 $company_image_list[$c] = $companyList[$c]['image'];
  4231.                             }
  4232.                             $user $client;
  4233.                         }
  4234.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  4235.                         $em $this->getDoctrine()->getManager('company_group');
  4236.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  4237.                         if ($oAuthData) {
  4238.                             $oAuthEmail $oAuthData['email'];
  4239.                             $oAuthUniqueId $oAuthData['uniqueId'];
  4240.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  4241.                             if (!$user)
  4242.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  4243.                         } else {
  4244.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  4245.                             if (!$user)
  4246.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  4247.                             if (!$user)
  4248.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  4249.                         }
  4250.                         $redirect_login_page_twig "@Authentication/pages/views/login_new.html.twig";
  4251. //                        if($systemType=='_BUDDYBEE_')
  4252. //                            $redirect_login_page_twig="@Authentication/pages/views/applicant_login.html.twig";
  4253.                         if (!$user) {
  4254.                             $message "We could not find your username or email";
  4255.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4256.                                 return new JsonResponse(array(
  4257.                                     'uid' => $session->get(UserConstants::USER_ID),
  4258.                                     'session' => $session,
  4259.                                     'success' => false,
  4260.                                     'errorStr' => $message,
  4261.                                     'session_data' => [],
  4262.                                 ));
  4263.                             }
  4264.                             if ($systemType == '_BUDDYBEE_')
  4265.                                 return $this->redirectToRoute("applicant_login", [
  4266.                                     "message" => $message,
  4267.                                     "errorField" => 'username',
  4268.                                 ]);
  4269.                             else if ($systemType == '_CENTRAL_')
  4270.                                 return $this->redirectToRoute("central_login", [
  4271.                                     "message" => $message,
  4272.                                     "errorField" => 'username',
  4273.                                 ]);
  4274.                             else if ($systemType == '_SOPHIA_')
  4275.                                 return $this->redirectToRoute("sophia_login", [
  4276.                                     "message" => $message,
  4277.                                     "errorField" => 'username',
  4278.                                 ]);
  4279.                             else
  4280.                                 return $this->render($redirect_login_page_twig, array(
  4281.                                     "message" => $message,
  4282.                                     'page_title' => "Login",
  4283.                                     'gocList' => $gocDataList,
  4284.                                     'gocId' => $gocId
  4285.                                 ));
  4286.                         }
  4287.                         if ($user) {
  4288.                             if ($oAuthData) {
  4289.                                 // user passed
  4290.                             } else {
  4291.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4292.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4293. //                                    if ($user->getPassword() == $request->request->get('password')) {
  4294. //                                        // user passed
  4295. //                                    } else {
  4296.                                     $message "Oops! Wrong Password";
  4297.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  4298.                                         return new JsonResponse(array(
  4299.                                             'uid' => $session->get(UserConstants::USER_ID),
  4300.                                             'session' => $session,
  4301.                                             'success' => false,
  4302.                                             'errorStr' => $message,
  4303.                                             'session_data' => [],
  4304.                                         ));
  4305.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4306.                                         //                    return $response;
  4307.                                     }
  4308.                                     if ($systemType == '_BUDDYBEE_')
  4309.                                         return $this->redirectToRoute("applicant_login", [
  4310.                                             "message" => $message,
  4311.                                             "errorField" => 'password',
  4312.                                         ]);
  4313.                                     else if ($systemType == '_SOPHIA_')
  4314.                                         return $this->redirectToRoute("sophia_login", [
  4315.                                             "message" => $message,
  4316.                                             "errorField" => 'username',
  4317.                                         ]);
  4318.                                     else if ($systemType == '_CENTRAL_')
  4319.                                         return $this->redirectToRoute("central_login", [
  4320.                                             "message" => $message,
  4321.                                             "errorField" => 'username',
  4322.                                         ]);
  4323.                                     else
  4324.                                         return $this->render($redirect_login_page_twig, array(
  4325.                                             "message" => $message,
  4326.                                             'page_title' => "Login",
  4327.                                             'gocList' => $gocDataList,
  4328.                                             'gocId' => $gocId
  4329.                                         ));
  4330.                                 }
  4331.                             }
  4332.                         }
  4333.                         $jd = [];
  4334.                         if ($jd != null && $jd != '' && $jd != [])
  4335.                             $company_id_list $jd;
  4336.                         else
  4337.                             $company_id_list = [];
  4338. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4339. //                        foreach ($company_id_list as $c) {
  4340. //                            $company_name_list[$c] = $companyList[$c]['name'];
  4341. //                            $company_image_list[$c] = $companyList[$c]['image'];
  4342. //                        }
  4343.                     };
  4344.                 } else {
  4345.                     if ($cookieLogin == 1) {
  4346.                         $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4347.                             array(
  4348.                                 'userId' => $userId
  4349.                             )
  4350.                         );
  4351.                     } else if ($encrypedLogin == 1) {
  4352.                         if (in_array($userType, [34]))
  4353.                             $specialLogin 1;
  4354.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4355.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccClients')->findOneBy(
  4356.                                 array(
  4357.                                     'globalUserId' => $globalId
  4358.                                 )
  4359.                             );
  4360. //
  4361.                             if ($user)
  4362.                                 $userId $user->getClientId();
  4363.                             $clientId $userId;
  4364.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4365.                             $user $em_goc->getRepository('ApplicationBundle\\Entity\\AccSuppliers')->findOneBy(
  4366.                                 array(
  4367.                                     'globalUserId' => $globalId
  4368.                                 )
  4369.                             );
  4370. //
  4371.                             if ($user)
  4372.                                 $userId $user->getSupplierId();
  4373.                             $supplierId $userId;
  4374.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4375. //                            $user = $em_goc->getRepository('CompanyGroupBundle\\Entity\\SysUser')->findOneBy(
  4376. //                                array(
  4377. //                                    'globalId' => $globalId
  4378. //                                )
  4379. //                            );
  4380. //
  4381. //                            if($user)
  4382. //                                $userId=$user->getUserId();
  4383. //                            $applicantId = $userId;
  4384.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  4385.                             $user $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4386.                                 array(
  4387.                                     'globalId' => $globalId
  4388.                                 )
  4389.                             );
  4390.                             if ($user)
  4391.                                 $userId $user->getUserId();
  4392.                         }
  4393.                     } else {
  4394.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4395.                             array(
  4396.                                 'userName' => $request->request->get('username')
  4397.                             )
  4398.                         );
  4399.                     }
  4400.                     if (!$user) {
  4401.                         $user $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  4402.                             array(
  4403.                                 'email' => $request->request->get('username'),
  4404.                                 'userName' => [null'']
  4405.                             )
  4406.                         );
  4407.                         if (!$user) {
  4408.                             $message "Wrong User Name";
  4409.                             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4410.                                 return new JsonResponse(array(
  4411.                                     'uid' => $session->get(UserConstants::USER_ID),
  4412.                                     'session' => $session,
  4413.                                     'success' => false,
  4414.                                     'errorStr' => $message,
  4415.                                     'session_data' => [],
  4416.                                 ));
  4417.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4418.                                 //                    return $response;
  4419.                             }
  4420.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4421.                                 "message" => $message,
  4422.                                 'page_title' => "Login",
  4423.                                 'gocList' => $gocDataList,
  4424.                                 'gocId' => $gocId
  4425.                             ));
  4426.                         } else {
  4427.                             //add the email as username as failsafe
  4428.                             $user->setUserName($request->request->get('username'));
  4429.                             $em->flush();
  4430.                         }
  4431.                     }
  4432.                     if ($user) {
  4433.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  4434.                             $message "Sorry, Your Account is Deactivated";
  4435.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify))) == 1) {
  4436.                                 return new JsonResponse(array(
  4437.                                     'uid' => $session->get(UserConstants::USER_ID),
  4438.                                     'session' => $session,
  4439.                                     'success' => false,
  4440.                                     'errorStr' => $message,
  4441.                                     'session_data' => [],
  4442.                                 ));
  4443.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4444.                                 //                    return $response;
  4445.                             }
  4446.                             return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4447.                                 "message" => $message,
  4448.                                 'page_title' => "Login",
  4449.                                 'gocList' => $gocDataList,
  4450.                                 'gocId' => $gocId
  4451.                             ));
  4452.                         }
  4453.                     }
  4454.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  4455.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  4456.                         $message "Wrong Email/Password";
  4457.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4458.                             return new JsonResponse(array(
  4459.                                 'uid' => $session->get(UserConstants::USER_ID),
  4460.                                 'session' => $session,
  4461.                                 'success' => false,
  4462.                                 'errorStr' => $message,
  4463.                                 'session_data' => [],
  4464.                             ));
  4465.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4466.                             //                    return $response;
  4467.                         }
  4468.                         return $this->render('@Authentication/pages/views/login_new.html.twig', array(
  4469.                             "message" => $message,
  4470.                             'page_title' => "Login",
  4471.                             'gocList' => $gocDataList,
  4472.                             'gocId' => $gocId
  4473.                         ));
  4474.                     }
  4475.                     $userType $user->getUserType();
  4476.                     $jd json_decode($user->getUserCompanyIdList(), true);
  4477.                     if ($jd != null && $jd != '' && $jd != [])
  4478.                         $company_id_list $jd;
  4479.                     else
  4480.                         $company_id_list = [$user->getUserCompanyId()];
  4481.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4482.                     foreach ($company_id_list as $c) {
  4483.                         if (isset($companyList[$c])) {
  4484.                             $company_name_list[$c] = $companyList[$c]['name'];
  4485.                             $company_image_list[$c] = $companyList[$c]['image'];
  4486.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  4487.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  4488.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  4489.                         }
  4490.                     }
  4491.                 }
  4492. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  4493.                 if ($remember_me == 1)
  4494.                     $session->set('REMEMBERME'1);
  4495.                 else
  4496.                     $session->set('REMEMBERME'0);
  4497.                 $config = array(
  4498.                     'firstLogin' => $firstLogin,
  4499.                     'rememberMe' => $remember_me,
  4500.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4501.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  4502.                     'applicationSecret' => $this->container->getParameter('secret'),
  4503.                     'gocId' => $gocId,
  4504.                     'appId' => $appIdFromUserName,
  4505.                     'gocDbName' => $gocDbName,
  4506.                     'gocDbUser' => $gocDbUser,
  4507.                     'gocDbHost' => $gocDbHost,
  4508.                     'gocDbPass' => $gocDbPass
  4509.                 );
  4510.                 $product_name_display_type 0;
  4511.                 if ($systemType != '_CENTRAL_') {
  4512.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\AccSettings')->findOneBy(array(
  4513.                         'name' => 'product_name_display_method'
  4514.                     ));
  4515.                     if ($product_name_display_settings)
  4516.                         $product_name_display_type $product_name_display_settings->getData();
  4517.                 }
  4518.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  4519.                     $userCompanyId 1;
  4520.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4521.                     if (isset($companyList[$userCompanyId])) {
  4522.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4523.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4524.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4525.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4526.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4527.                     }
  4528.                     // General User
  4529.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  4530.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4531.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  4532.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  4533.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4534.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4535.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  4536.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4537.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4538.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4539.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4540.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4541.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4542.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4543.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4544.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4545.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4546.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4547.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4548.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4549.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4550.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4551.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4552.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4553.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4554.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4555.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4556.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4557.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4558.                     //                $PL=json_decode($user->getPositionIds(), true);
  4559.                     $route_list_array = [];
  4560.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4561.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4562.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4563.                     $loginID 0;
  4564.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4565.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4566.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4567.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4568.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4569.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4570.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4571.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4572.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4573.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4574.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4575.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4576.                         $session->set('remoteVerified'1);
  4577.                         $session_data = array(
  4578.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4579.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4580.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4581.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4582.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4583.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4584.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4585.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4586.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4587.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4588.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4589.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4590.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4591.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4592.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4593.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4594.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4595.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4596.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4597.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4598.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4599.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4600.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4601.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4602.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4603.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4604.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4605.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4606.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4607.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4608.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4609.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4610.                         );
  4611.                         $response = new JsonResponse(array(
  4612.                             'uid' => $session->get(UserConstants::USER_ID),
  4613.                             'session' => $session,
  4614.                             'success' => true,
  4615.                             'session_data' => $session_data,
  4616.                         ));
  4617.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4618.                         return $response;
  4619.                     }
  4620.                     if ($request->request->has('referer_path')) {
  4621.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4622.                             return $this->redirect($request->request->get('referer_path'));
  4623.                         }
  4624.                     }
  4625.                     //                    if($request->request->has('gocId')
  4626.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4627.                     return $this->redirectToRoute("supplier_dashboard");
  4628.                     //                    else
  4629.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4630.                 }
  4631.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  4632.                     // General User
  4633.                     $userCompanyId 1;
  4634.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4635.                     if (isset($companyList[$userCompanyId])) {
  4636.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4637.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4638.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4639.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4640.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4641.                     }
  4642.                     $session->set(UserConstants::USER_ID$user->getClientId());
  4643.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4644.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  4645.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  4646.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4647.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4648.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  4649.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4650.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  4651.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4652.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4653.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4654.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4655.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4656.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4657.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  4658.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4659.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4660.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4661.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4662.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4663.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4664.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4665.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4666.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4667.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4668.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4669.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4670.                     //                $PL=json_decode($user->getPositionIds(), true);
  4671.                     $route_list_array = [];
  4672.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4673.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  4674.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  4675.                     $loginID 0;
  4676.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4677.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4678.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4679.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4680.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4681.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4682.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4683.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4684.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4685.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4686.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  4687.                     $session_data = array(
  4688.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  4689.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4690.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4691.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  4692.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  4693.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  4694.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  4695.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  4696.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  4697.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  4698.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  4699.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  4700.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  4701.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  4702.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  4703.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  4704.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  4705.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  4706.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  4707.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  4708.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4709.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4710.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4711.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  4712.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  4713.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  4714.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  4715.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  4716.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  4717.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  4718.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4719.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4720.                     );
  4721.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  4722.                     $session_data $tokenData['sessionData'];
  4723.                     $token $tokenData['token'];
  4724.                     $session->set('token'$token);
  4725.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  4726.                         $session->set('remoteVerified'1);
  4727.                         $response = new JsonResponse(array(
  4728.                             'uid' => $session->get(UserConstants::USER_ID),
  4729.                             'session' => $session,
  4730.                             'token' => $token,
  4731.                             'success' => true,
  4732.                             'session_data' => $session_data,
  4733.                         ));
  4734.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4735.                         return $response;
  4736.                     }
  4737.                     if ($request->request->has('referer_path')) {
  4738.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  4739.                             return $this->redirect($request->request->get('referer_path'));
  4740.                         }
  4741.                     }
  4742.                     //                    if($request->request->has('gocId')
  4743.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  4744.                     return $this->redirectToRoute("client_dashboard"); //will be client
  4745.                     //                    else
  4746.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  4747.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  4748.                     // System administrator
  4749.                     // System administrator have successfully logged in. Lets add a login ID.
  4750.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4751.                         ->findOneBy(
  4752.                             array(
  4753.                                 'userId' => $user->getUserId()
  4754.                             )
  4755.                         );
  4756.                     if ($employeeObj) {
  4757.                         $employeeId $employeeObj->getEmployeeId();
  4758.                         $epositionId $employeeObj->getPositionId();
  4759.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4760.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4761.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4762.                     }
  4763.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  4764.                         ->findOneBy(
  4765.                             array(
  4766.                                 'userId' => $user->getUserId(),
  4767.                                 'workingStatus' => 1
  4768.                             )
  4769.                         );
  4770.                     if ($currentTask) {
  4771.                         $currentTaskId $currentTask->getId();
  4772.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  4773.                     }
  4774.                     $userId $user->getUserId();
  4775.                     $userCompanyId 1;
  4776.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  4777.                     $userEmail $user->getEmail();
  4778.                     $userImage $user->getImage();
  4779.                     $userFullName $user->getName();
  4780.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  4781.                     $position_list_array json_decode($user->getPositionIds(), true);
  4782.                     if ($position_list_array == null$position_list_array = [];
  4783.                     $filtered_pos_array = [];
  4784.                     foreach ($position_list_array as $defPos)
  4785.                         if ($defPos != '' && $defPos != 0)
  4786.                             $filtered_pos_array[] = $defPos;
  4787.                     $position_list_array $filtered_pos_array;
  4788.                     if (!empty($position_list_array))
  4789.                         foreach ($position_list_array as $defPos)
  4790.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  4791.                                 $curr_position_id $defPos;
  4792.                             }
  4793.                     $userDefaultRoute $user->getDefaultRoute();
  4794. //                    $userDefaultRoute = 'MATHA';
  4795.                     $allModuleAccessFlag 1;
  4796.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  4797.                         $userDefaultRoute '';
  4798. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  4799.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  4800.                     if (isset($companyList[$userCompanyId])) {
  4801.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  4802.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  4803.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  4804.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  4805.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  4806.                     }
  4807.                     if ($allModuleAccessFlag == 1)
  4808.                         $prohibit_list_array = [];
  4809.                     else if ($curr_position_id != 0)
  4810.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  4811.                     $loginID $this->get('user_module')->addUserLoginLog(
  4812.                         $userId,
  4813.                         $request->server->get("REMOTE_ADDR"),
  4814.                         $curr_position_id
  4815.                     );
  4816.                     $appIdList json_decode($user->getUserAppIdList());
  4817.                     $branchIdList json_decode($user->getUserBranchIdList());
  4818.                     if ($branchIdList == null$branchIdList = [];
  4819.                     $branchId $user->getUserBranchId();
  4820.                     if ($appIdList == null$appIdList = [];
  4821. //
  4822. //                    if (!in_array($user->getUserAppId(), $appIdList))
  4823. //                        $appIdList[] = $user->getUserAppId();
  4824. //
  4825. //                    foreach ($appIdList as $currAppId) {
  4826. //                        if ($currAppId == $user->getUserAppId()) {
  4827. //
  4828. //                            foreach ($company_id_list as $index_company => $company_id) {
  4829. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  4830. //                                $app_company_index = $currAppId . '_' . $company_id;
  4831. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4832. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4833. //                            }
  4834. //                        } else {
  4835. //
  4836. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  4837. //                                $this->getDoctrine()->getManager('company_group'),
  4838. //                                $gocEnabled,
  4839. //                                $currAppId
  4840. //                            );
  4841. //                            if (!empty($dataToConnect)) {
  4842. //                                $connector = $this->container->get('application_connector');
  4843. //                                $connector->resetConnection(
  4844. //                                    'default',
  4845. //                                    $dataToConnect['dbName'],
  4846. //                                    $dataToConnect['dbUser'],
  4847. //                                    $dataToConnect['dbPass'],
  4848. //                                    $dataToConnect['dbHost'],
  4849. //                                    $reset = true
  4850. //                                );
  4851. //                                $em = $this->getDoctrine()->getManager();
  4852. //
  4853. //                                $companyList = Company::getCompanyListWithImage($em);
  4854. //                                foreach ($companyList as $c => $dta) {
  4855. //                                    //                                $company_id_list[]=$c;
  4856. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  4857. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  4858. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  4859. //                                    $app_company_index = $currAppId . '_' . $c;
  4860. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4861. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4862. //                                }
  4863. //                            }
  4864. //                        }
  4865. //                    }
  4866.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  4867.                     // General User
  4868.                     $employeeId 0;
  4869.                     $currentMonthHolidayList = [];
  4870.                     $currentHolidayCalendarId 0;
  4871.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  4872.                         ->findOneBy(
  4873.                             array(
  4874.                                 'userId' => $user->getUserId()
  4875.                             )
  4876.                         );
  4877.                     if ($employeeObj) {
  4878.                         $employeeId $employeeObj->getEmployeeId();
  4879.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  4880.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  4881.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  4882.                     }
  4883.                     $session->set(UserConstants::USER_EMPLOYEE_IDstrval($employeeId));
  4884.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  4885.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  4886.                     $session->set(UserConstants::USER_ID$user->getUserId());
  4887.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  4888.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  4889.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  4890.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4891.                     $session->set(UserConstants::USER_NAME$user->getName());
  4892.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4893.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  4894.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  4895.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  4896.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  4897.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  4898.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  4899.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  4900.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  4901.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  4902.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  4903.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4904.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4905.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  4906.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4907.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4908.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4909.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4910.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4911.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4912.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4913.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  4914.                         return $this->redirectToRoute("user_login_position");
  4915.                     } else {
  4916.                         $PL json_decode($user->getPositionIds(), true);
  4917.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  4918.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  4919.                         $loginID $this->get('user_module')->addUserLoginLog(
  4920.                             $session->get(UserConstants::USER_ID),
  4921.                             $request->server->get("REMOTE_ADDR"),
  4922.                             $PL[0]
  4923.                         );
  4924.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4925.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  4926.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  4927.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  4928.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  4929.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  4930.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  4931.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  4932.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  4933.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  4934.                         $appIdList json_decode($user->getUserAppIdList());
  4935.                         if ($appIdList == null$appIdList = [];
  4936.                         $companyIdListByAppId = [];
  4937.                         $companyNameListByAppId = [];
  4938.                         $companyImageListByAppId = [];
  4939.                         if (!in_array($user->getUserAppId(), $appIdList))
  4940.                             $appIdList[] = $user->getUserAppId();
  4941.                         foreach ($appIdList as $currAppId) {
  4942.                             if ($currAppId == $user->getUserAppId()) {
  4943.                                 foreach ($company_id_list as $index_company => $company_id) {
  4944.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  4945.                                     $app_company_index $currAppId '_' $company_id;
  4946.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  4947.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  4948.                                 }
  4949.                             } else {
  4950.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  4951.                                     $this->getDoctrine()->getManager('company_group'),
  4952.                                     $gocEnabled,
  4953.                                     $currAppId
  4954.                                 );
  4955.                                 if (!empty($dataToConnect)) {
  4956.                                     $connector $this->container->get('application_connector');
  4957.                                     $connector->resetConnection(
  4958.                                         'default',
  4959.                                         $dataToConnect['dbName'],
  4960.                                         $dataToConnect['dbUser'],
  4961.                                         $dataToConnect['dbPass'],
  4962.                                         $dataToConnect['dbHost'],
  4963.                                         $reset true
  4964.                                     );
  4965.                                     $em $this->getDoctrine()->getManager();
  4966.                                     $companyList Company::getCompanyListWithImage($em);
  4967.                                     foreach ($companyList as $c => $dta) {
  4968.                                         //                                $company_id_list[]=$c;
  4969.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  4970.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  4971.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  4972.                                         $app_company_index $currAppId '_' $c;
  4973.                                         $company_locale $companyList[$c]['locale'];
  4974.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  4975.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  4976.                                     }
  4977.                                 }
  4978.                             }
  4979.                         }
  4980.                         $session->set('appIdList'$appIdList);
  4981.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  4982.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  4983.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  4984.                         $branchIdList json_decode($user->getUserBranchIdList());
  4985.                         $branchId $user->getUserBranchId();
  4986.                         $session->set('branchIdList'$branchIdList);
  4987.                         $session->set('branchId'$branchId);
  4988.                         if ($user->getAllModuleAccessFlag() == 1)
  4989.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  4990.                         else
  4991.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  4992.                         $session_data = array(
  4993.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  4994.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4995.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4996.                             'oAuthToken' => $session->get('oAuthToken'),
  4997.                             'locale' => $session->get('locale'),
  4998.                             'firebaseToken' => $session->get('firebaseToken'),
  4999.                             'token' => $session->get('token'),
  5000.                             'firstLogin' => $firstLogin,
  5001.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  5002.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  5003.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  5004.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  5005.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  5006.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  5007.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  5008.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5009.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  5010.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  5011.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  5012.                             'oAuthImage' => $session->get('oAuthImage'),
  5013.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  5014.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  5015.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  5016.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  5017.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  5018.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  5019.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5020.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  5021.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  5022.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  5023.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  5024.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  5025.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  5026.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  5027.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  5028.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  5029.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  5030.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  5031.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  5032.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  5033.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  5034.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  5035.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  5036.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5037.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5038.                             //new
  5039.                             'appIdList' => $session->get('appIdList'),
  5040.                             'branchIdList' => $session->get('branchIdList'null),
  5041.                             'branchId' => $session->get('branchId'null),
  5042.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  5043.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  5044.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  5045.                         );
  5046.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  5047.                         $session_data $tokenData['sessionData'];
  5048.                         $token $tokenData['token'];
  5049.                         $session->set('token'$token);
  5050.                         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5051.                             $session->set('remoteVerified'1);
  5052.                             $response = new JsonResponse(array(
  5053.                                 'uid' => $session->get(UserConstants::USER_ID),
  5054.                                 'session' => $session,
  5055.                                 'token' => $token,
  5056.                                 'success' => true,
  5057.                                 'session_data' => $session_data,
  5058.                             ));
  5059.                             $response->headers->set('Access-Control-Allow-Origin''*');
  5060.                             return $response;
  5061.                         }
  5062.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5063.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5064.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5065.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5066.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5067.                                     return $this->redirect($red);
  5068.                                 }
  5069.                             } else {
  5070.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5071.                             }
  5072.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5073.                             return $this->redirectToRoute("dashboard");
  5074.                         else
  5075.                             return $this->redirectToRoute($user->getDefaultRoute());
  5076. //                        if ($request->server->has("HTTP_REFERER")) {
  5077. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  5078. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  5079. //                            }
  5080. //                        }
  5081. //
  5082. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  5083. //                        if ($request->request->has('referer_path')) {
  5084. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  5085. //                                return $this->redirect($request->request->get('referer_path'));
  5086. //                            }
  5087. //                        }
  5088. //                        //                    if($request->request->has('gocId')
  5089. //
  5090. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  5091. //                            return $this->redirectToRoute("dashboard");
  5092. //                        else
  5093. //                            return $this->redirectToRoute($user->getDefaultRoute());
  5094.                     }
  5095.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  5096.                     $applicantId $user->getApplicantId();
  5097.                     $userId $user->getApplicantId();
  5098.                     $globalId $user->getApplicantId();
  5099.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5100.                     $isConsultant $user->getIsConsultant() == 0;
  5101.                     $isRetailer $user->getIsRetailer() == 0;
  5102.                     $retailerLevel $user->getRetailerLevel() == 0;
  5103.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  5104.                     $isModerator $user->getIsModerator() == 0;
  5105.                     $isAdmin $user->getIsAdmin() == 0;
  5106.                     $userEmail $user->getOauthEmail();
  5107.                     $userImage $user->getImage();
  5108.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  5109.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5110.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5111.                     $buddybeeBalance $user->getAccountBalance();
  5112.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  5113.                     $userDefaultRoute 'applicant_dashboard';
  5114. //            $userAppIds = json_decode($user->getUserAppIds(), true);
  5115.                     $userAppIds = [];
  5116.                     $userSuspendedAppIds json_decode($user->getUserSuspendedAppIds(), true);
  5117.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  5118.                     if ($userAppIds == null$userAppIds = [];
  5119.                     if ($userSuspendedAppIds == null$userSuspendedAppIds = [];
  5120.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  5121.                     foreach ($userTypesByAppIds as $aid => $accData)
  5122.                         if (in_array($aid$userSuspendedAppIds))
  5123.                             unset($userTypesByAppIds[$aid]);
  5124.                         else
  5125.                             $userAppIds[]=$aid;
  5126. //                    $userAppIds=array_diff($userAppIds,$userSuspendedAppIds);
  5127.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  5128.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  5129.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  5130.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  5131.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  5132.                     $loginID MiscActions::addEntityUserLoginLog(
  5133.                         $em_goc,
  5134.                         $userId,
  5135.                         $applicantId,
  5136.                         1,
  5137.                         $request->server->get("REMOTE_ADDR"),
  5138.                         0,
  5139.                         $request->request->get('deviceId'''),
  5140.                         $request->request->get('oAuthToken'''),
  5141.                         $request->request->get('oAuthType'''),
  5142.                         $request->request->get('locale'''),
  5143.                         $request->request->get('firebaseToken''')
  5144.                     );
  5145.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  5146.                     // General User
  5147.                     $employeeObj $em->getRepository('ApplicationBundle\\Entity\\Employee')
  5148.                         ->findOneBy(
  5149.                             array(
  5150.                                 'userId' => $user->getUserId()
  5151.                             )
  5152.                         );
  5153.                     if ($employeeObj) {
  5154.                         $employeeId $employeeObj->getEmployeeId();
  5155.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  5156.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  5157.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  5158.                     }
  5159.                     $currentTask $em->getRepository('ApplicationBundle\\Entity\\TaskLog')
  5160.                         ->findOneBy(
  5161.                             array(
  5162.                                 'userId' => $user->getUserId(),
  5163.                                 'workingStatus' => 1
  5164.                             )
  5165.                         );
  5166.                     if ($currentTask) {
  5167.                         $currentTaskId $currentTask->getId();
  5168.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  5169.                     }
  5170.                     $userId $user->getUserId();
  5171.                     $userCompanyId 1;
  5172.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  5173.                     $userEmail $user->getEmail();
  5174.                     $userImage $user->getImage();
  5175.                     $userFullName $user->getName();
  5176.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  5177.                     $isEmailVerified $user->getIsEmailVerified() == 0;
  5178.                     $position_list_array json_decode($user->getPositionIds(), true);
  5179.                     if ($position_list_array == null$position_list_array = [];
  5180.                     $filtered_pos_array = [];
  5181.                     foreach ($position_list_array as $defPos)
  5182.                         if ($defPos != '' && $defPos != 0)
  5183.                             $filtered_pos_array[] = $defPos;
  5184.                     $position_list_array $filtered_pos_array;
  5185.                     if (!empty($position_list_array))
  5186.                         foreach ($position_list_array as $defPos)
  5187.                             if ($defPos != '' && $defPos != && $curr_position_id == 0) {
  5188.                                 $curr_position_id $defPos;
  5189.                             }
  5190.                     $userDefaultRoute $user->getDefaultRoute();
  5191.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  5192.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  5193.                         $userDefaultRoute 'dashboard';
  5194.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  5195.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  5196.                     if (isset($companyList[$userCompanyId])) {
  5197.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  5198.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  5199.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  5200.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  5201.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  5202.                     }
  5203.                     if ($allModuleAccessFlag == 1)
  5204.                         $prohibit_list_array = [];
  5205.                     else if ($curr_position_id != 0)
  5206.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  5207.                     $loginID $this->get('user_module')->addUserLoginLog(
  5208.                         $userId,
  5209.                         $request->server->get("REMOTE_ADDR"),
  5210.                         $curr_position_id
  5211.                     );
  5212.                     $appIdList json_decode($user->getUserAppIdList());
  5213.                     $branchIdList json_decode($user->getUserBranchIdList());
  5214.                     if ($branchIdList == null$branchIdList = [];
  5215.                     $branchId $user->getUserBranchId();
  5216.                     if ($appIdList == null$appIdList = [];
  5217.                     if (!in_array($user->getUserAppId(), $appIdList))
  5218.                         $appIdList[] = $user->getUserAppId();
  5219.                     foreach ($appIdList as $currAppId) {
  5220.                         if ($currAppId == $user->getUserAppId()) {
  5221.                             foreach ($company_id_list as $index_company => $company_id) {
  5222.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  5223.                                 $app_company_index $currAppId '_' $company_id;
  5224.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  5225.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  5226.                             }
  5227.                         } else {
  5228.                             $dataToConnect System::changeDoctrineManagerByAppId(
  5229.                                 $this->getDoctrine()->getManager('company_group'),
  5230.                                 $gocEnabled,
  5231.                                 $currAppId
  5232.                             );
  5233.                             if (!empty($dataToConnect)) {
  5234.                                 $connector $this->container->get('application_connector');
  5235.                                 $connector->resetConnection(
  5236.                                     'default',
  5237.                                     $dataToConnect['dbName'],
  5238.                                     $dataToConnect['dbUser'],
  5239.                                     $dataToConnect['dbPass'],
  5240.                                     $dataToConnect['dbHost'],
  5241.                                     $reset true
  5242.                                 );
  5243.                                 $em $this->getDoctrine()->getManager();
  5244.                                 $companyList Company::getCompanyListWithImage($em);
  5245.                                 foreach ($companyList as $c => $dta) {
  5246.                                     //                                $company_id_list[]=$c;
  5247.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  5248.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  5249.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  5250.                                     $app_company_index $currAppId '_' $c;
  5251.                                     $company_locale $companyList[$c]['locale'];
  5252.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  5253.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  5254.                                 }
  5255.                             }
  5256.                         }
  5257.                     }
  5258.                     if (count($position_list_array) > 1) {
  5259.                         $userForcedRoute 'user_login_position';
  5260. //                        return $this->redirectToRoute("user_login_position");
  5261.                     } else {
  5262.                     }
  5263.                 }
  5264.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  5265.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  5266.                     $userType == UserConstants::USER_TYPE_SYSTEM
  5267.                 ) {
  5268.                     $session_data = array(
  5269.                         UserConstants::USER_ID => $userId,
  5270.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  5271.                         UserConstants::APPLICANT_ID => $applicantId,
  5272.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  5273.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  5274.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  5275.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  5276.                         UserConstants::SUPPLIER_ID => $supplierId,
  5277.                         UserConstants::CLIENT_ID => $clientId,
  5278.                         UserConstants::USER_TYPE => $userType,
  5279.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  5280.                         UserConstants::IS_CONSULTANT => $isConsultant,
  5281.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  5282.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  5283.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  5284.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  5285.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  5286.                         UserConstants::USER_EMAIL => $userEmail == null "" $userEmail,
  5287.                         UserConstants::USER_IMAGE => $userImage == null "" $userImage,
  5288.                         UserConstants::USER_NAME => $userFullName,
  5289.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  5290.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  5291.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  5292.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  5293.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  5294.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  5295.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  5296.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  5297.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  5298.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  5299.                         UserConstants::USER_GOC_ID => $gocId,
  5300.                         UserConstants::USER_DB_NAME => $gocDbName,
  5301.                         UserConstants::USER_DB_USER => $gocDbUser,
  5302.                         UserConstants::USER_DB_PASS => $gocDbPass,
  5303.                         UserConstants::USER_DB_HOST => $gocDbHost,
  5304.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  5305.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  5306.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  5307.                         UserConstants::USER_LOGIN_ID => $loginID,
  5308.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  5309.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  5310.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  5311.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  5312.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  5313.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  5314.                         'IS_EMAIL_VERIFIED' => $isEmailVerified,
  5315.                         'REMEMBERME' => $remember_me,
  5316.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  5317.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  5318.                         'oAuthToken' => $oAuthToken,
  5319.                         'locale' => $locale,
  5320.                         'firebaseToken' => $firebaseToken,
  5321.                         'token' => $session->get('token'),
  5322.                         'firstLogin' => $firstLogin,
  5323.                         'oAuthImage' => $oAuthImage,
  5324.                         'appIdList' => json_encode($appIdList),
  5325.                         'branchIdList' => json_encode($branchIdList),
  5326.                         'branchId' => $branchId,
  5327.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  5328.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  5329.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  5330.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  5331.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  5332.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  5333.                     );
  5334.                     if ($systemType == '_CENTRAL_') {
  5335.                         $accessList = [];
  5336. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  5337.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  5338.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  5339.                                 if (isset($gocDataListByAppId[$thisUserAppId])) {
  5340.                                     $d = array(
  5341.                                         'userType' => $thisUserUserType,
  5342.                                         'globalId' => $globalId,
  5343.                                         'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  5344.                                         'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  5345.                                         'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  5346.                                         'systemType' => '_ERP_',
  5347.                                         'companyId' => 1,
  5348.                                         'appId' => $thisUserAppId,
  5349.                                         'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  5350.                                         'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  5351.                                         'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  5352.                                                 array(
  5353.                                                     'globalId' => $globalId,
  5354.                                                     'appId' => $thisUserAppId,
  5355.                                                     'authenticate' => 1,
  5356.                                                     'userType' => $thisUserUserType
  5357.                                                 )
  5358.                                             )
  5359.                                         ),
  5360.                                         'userCompanyList' => [
  5361.                                         ]
  5362.                                     );
  5363.                                     $accessList[] = $d;
  5364.                                 }
  5365.                             }
  5366.                         }
  5367.                         $session_data['userAccessList'] = $accessList;
  5368.                     }
  5369.                     $ultimateData System::setSessionForUser($em_goc,
  5370.                         $session,
  5371.                         $session_data,
  5372.                         $config
  5373.                     );
  5374. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  5375.                     $session_data $ultimateData['sessionData'];
  5376.                     $token $ultimateData['token'];
  5377.                     $session->set('token'$token);
  5378.                     if ($systemType == '_CENTRAL_') {
  5379.                         $session->set('csToken'$token);
  5380.                     } else {
  5381.                         $session->set('csToken'$csToken);
  5382.                     }
  5383.                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == 1) {
  5384.                         $session->set('remoteVerified'1);
  5385.                         $response = new JsonResponse(array(
  5386.                             'token' => $token,
  5387.                             'uid' => $session->get(UserConstants::USER_ID),
  5388.                             'session' => $session,
  5389.                             'success' => true,
  5390.                             'session_data' => $session_data,
  5391.                         ));
  5392.                         $response->headers->set('Access-Control-Allow-Origin''*');
  5393.                         return $response;
  5394.                     }
  5395.                     //TEMP START
  5396.                     if ($systemType == '_CENTRAL_') {
  5397.                         return $this->redirectToRoute('central_landing');
  5398.                     }
  5399.                     //TREMP END
  5400.                     if ($userForcedRoute != '')
  5401.                         return $this->redirectToRoute($userForcedRoute);
  5402.                     if ($request->request->has('referer_path')) {
  5403.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  5404.                             return $this->redirect($request->request->get('referer_path'));
  5405.                         }
  5406.                     }
  5407.                     if ($request->query->has('refRoute')) {
  5408.                         if ($request->query->get('refRoute') == '8917922')
  5409.                             $userDefaultRoute 'apply_for_consultant';
  5410.                     }
  5411.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  5412.                         $userDefaultRoute 'dashboard';
  5413.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  5414.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  5415.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  5416.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  5417.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5418.                                 return $this->redirect($red);
  5419.                             }
  5420.                         } else {
  5421.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5422.                         }
  5423.                     } else
  5424.                         return $this->redirectToRoute($userDefaultRoute);
  5425.                 }
  5426.             }
  5427.         }
  5428.         $session $request->getSession();
  5429.         if (isset($encData['appId'])) {
  5430.             if (isset($gocDataListByAppId[$encData['appId']]))
  5431.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  5432.         }
  5433.         $routeName $request->attributes->get('_route');
  5434.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  5435.             $refRoute '';
  5436.             $message '';
  5437.             $errorField '_NONE_';
  5438. //            if ($request->query->has('message')) {
  5439. //                $message = $request->query->get('message');
  5440. //
  5441. //            }
  5442. //            if ($request->query->has('errorField')) {
  5443. //                $errorField = $request->query->get('errorField');
  5444. //
  5445. //            }
  5446.             if ($refRoute != '') {
  5447.                 if ($refRoute == '8917922')
  5448.                     $redirectRoute 'apply_for_consultant';
  5449.             }
  5450.             if ($request->query->has('refRoute')) {
  5451.                 $refRoute $request->query->get('refRoute');
  5452.                 if ($refRoute == '8917922')
  5453.                     $redirectRoute 'apply_for_consultant';
  5454.             }
  5455.             $google_client = new Google_Client();
  5456. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5457. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5458.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5459.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5460.             } else {
  5461.                 $url $this->generateUrl(
  5462.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5463.                 );
  5464.             }
  5465.             $selector BuddybeeConstant::$selector;
  5466.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5467. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5468.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5469. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5470.             $google_client->setRedirectUri($url);
  5471.             $google_client->setAccessType('offline');        // offline access
  5472.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5473.             $google_client->setRedirectUri($url);
  5474.             $google_client->addScope('email');
  5475.             $google_client->addScope('profile');
  5476.             $google_client->addScope('openid');
  5477.             return $this->render(
  5478.                 '@Authentication/pages/views/applicant_login.html.twig',
  5479.                 [
  5480.                     'page_title' => 'BuddyBee Login',
  5481.                     'oAuthLink' => $google_client->createAuthUrl(),
  5482.                     'redirect_url' => $url,
  5483.                     'message' => $message,
  5484.                     'errorField' => '',
  5485.                     'systemType' => $systemType,
  5486.                     'ownServerId' => $ownServerId,
  5487.                     'refRoute' => $refRoute,
  5488.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5489.                     'selector' => $selector
  5490.                 ]
  5491.             );
  5492.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  5493.             $refRoute '';
  5494.             $message '';
  5495.             $errorField '_NONE_';
  5496. //            if ($request->query->has('message')) {
  5497. //                $message = $request->query->get('message');
  5498. //
  5499. //            }
  5500. //            if ($request->query->has('errorField')) {
  5501. //                $errorField = $request->query->get('errorField');
  5502. //
  5503. //            }
  5504.             if ($refRoute != '') {
  5505.                 if ($refRoute == '8917922')
  5506.                     $redirectRoute 'apply_for_consultant';
  5507.             }
  5508.             if ($request->query->has('refRoute')) {
  5509.                 $refRoute $request->query->get('refRoute');
  5510.                 if ($refRoute == '8917922')
  5511.                     $redirectRoute 'apply_for_consultant';
  5512.             }
  5513.             $google_client = new Google_Client();
  5514. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5515. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5516.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5517.                 $url $this->generateUrl('user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  5518.             } else {
  5519.                 $url $this->generateUrl(
  5520.                     'user_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  5521.                 );
  5522.             }
  5523.             $selector BuddybeeConstant::$selector;
  5524. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5525.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  5526. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5527.             $google_client->setRedirectUri($url);
  5528.             $google_client->setAccessType('offline');        // offline access
  5529.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5530.             $google_client->setRedirectUri($url);
  5531.             $google_client->addScope('email');
  5532.             $google_client->addScope('profile');
  5533.             $google_client->addScope('openid');
  5534.             return $this->render(
  5535.                 '@Authentication/pages/views/central_login.html.twig',
  5536.                 [
  5537.                     'page_title' => 'Central Login',
  5538.                     'oAuthLink' => $google_client->createAuthUrl(),
  5539.                     'redirect_url' => $url,
  5540.                     'message' => $message,
  5541.                     'systemType' => $systemType,
  5542.                     'ownServerId' => $ownServerId,
  5543.                     'errorField' => '',
  5544.                     'refRoute' => $refRoute,
  5545.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  5546.                     'selector' => $selector
  5547.                 ]
  5548.             );
  5549.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  5550.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER '/central_landing');
  5551.         } else
  5552.             return $this->render(
  5553.                 '@Authentication/pages/views/login_new.html.twig',
  5554.                 array(
  5555.                     "message" => $message,
  5556.                     'page_title' => 'Login',
  5557.                     'gocList' => $gocDataListForLoginWeb,
  5558.                     'gocId' => $gocId != $gocId '',
  5559.                     'systemType' => $systemType,
  5560.                     'ownServerId' => $ownServerId,
  5561.                     'encData' => $encData,
  5562.                     //                'ref'=>$request->
  5563.                 )
  5564.             );
  5565.     }
  5566.     public function initiateAdminAction(Request $request$remoteVerify 0)
  5567.     {
  5568.         $em $this->getDoctrine()->getManager();
  5569.         MiscActions::initiateAdminUser($em);
  5570.         $this->addFlash(
  5571.             'success',
  5572.             'The Action was Successful.'
  5573.         );
  5574.         return $this->redirectToRoute('user_login');
  5575.     }
  5576.     public function LogoutAction(Request $request$remoteVerify 0)
  5577.     {
  5578.         $session $request->getSession();
  5579.         $em_goc $this->getDoctrine()->getManager('company_group');
  5580.         $session $request->getSession();
  5581.         $token =    $request->headers->get('auth-token',$request->request->get('token'$request->request->get('hbeeSessionToken''')));
  5582. //        return new JsonResponse([$token]);
  5583.         if ($session->get(UserConstants::USER_ID0)==) {
  5584. //                    return new JsonResponse([$token]);
  5585.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  5586.             if ($to_set_session_data != null) {
  5587.                 foreach ($to_set_session_data as $k => $d) {
  5588.                     //check if mobile
  5589.                     $session->set($k$d);
  5590.                 }
  5591.             } else {
  5592.                 $hbeeErrorCode ApiConstants::ERROR_TOKEN_EXPIRED;
  5593.             }
  5594.         }
  5595.         $userId $session->get(UserConstants::USER_ID);
  5596.         $currentTime = new \Datetime();
  5597.         $currTs $currentTime->format('U');
  5598.         $routeName $request->attributes->get('_route');
  5599.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  5600.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5601.         if ($request->query->get('endCurrentTask'1) == 1) {
  5602.             if (
  5603.                 ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  5604.                 ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  5605.                     $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  5606.             ) {
  5607.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  5608.                 if ($gocId != && $gocId != "") {
  5609.                     $gocDbName $session->get(UserConstants::USER_DB_NAME);
  5610.                     $gocDbUser $session->get(UserConstants::USER_DB_USER);
  5611.                     $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  5612.                     $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  5613. //                $connector = $this->container->get('application_connector');
  5614.                     $connector $this->container->get('application_connector');
  5615.                     $connector->resetConnection(
  5616.                         'default',
  5617.                         $gocDbName,
  5618.                         $gocDbUser,
  5619.                         $gocDbPass,
  5620.                         $gocDbHost,
  5621.                         $reset false);
  5622.                 }
  5623.                 $em $this->getDoctrine()->getManager();
  5624.                 $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) . ' ;');
  5625.                 
  5626.                 
  5627.                 if (1) {
  5628.                     $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  5629.                     $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  5630.                     $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  5631.                     $currTime = new \DateTime();
  5632.                     $options = array(
  5633.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5634.                         'notification_server' => $this->container->getParameter('notification_server'),
  5635.                     );
  5636.                     $positionsArray = [
  5637.                         array(
  5638.                             'employeeId' => $empId,
  5639.                             'userId' => $session->get(UserConstants::USER_ID0),
  5640.                             'sysUserId' => $session->get(UserConstants::USER_ID0),
  5641.                             'timeStamp' => $currTime->format(DATE_ISO8601),
  5642.                             'lat' => 23.8623834,
  5643.                             'lng' => 90.3979294,
  5644.                             'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  5645. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  5646.                         )
  5647.                     ];
  5648.                     if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  5649.                     if ($positionsArray == null$positionsArray = [];
  5650.                     $dataByAttId = [];
  5651.                     $workPlaceType '_UNSET_';
  5652.                     foreach ($positionsArray as $findex => $d) {
  5653.                         $sysUserId 0;
  5654.                         $userId 0;
  5655.                         $empId 0;
  5656.                         $dtTs 0;
  5657.                         $timeZoneStr '+0000';
  5658.                         if (isset($d['employeeId'])) $empId $d['employeeId'];
  5659.                         if (isset($d['userId'])) $userId $d['userId'];
  5660.                         if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  5661.                         if (isset($d['tsMilSec'])) {
  5662.                             $dtTs ceil(($d['tsMilSec']) / 1000);
  5663.                         }
  5664.                         if ($dtTs == 0) {
  5665.                             $currTsTime = new \DateTime();
  5666.                             $dtTs $currTsTime->format('U');
  5667.                         } else {
  5668.                             $currTsTime = new \DateTime('@' $dtTs);
  5669.                         }
  5670.                         $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  5671.                         $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  5672.                         $EmployeeAttendance $this->getDoctrine()
  5673.                             ->getRepository(EmployeeAttendance::class)
  5674.                             ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  5675.                         if (!$EmployeeAttendance) {
  5676.                             continue;
  5677.                         } else {
  5678.                         }
  5679.                         $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  5680.                         if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  5681.                             $workPlaceType '_STATIC_';
  5682.                         }
  5683.                         if (!isset($dataByAttId[$attendanceInfo->getId()]))
  5684.                             $dataByAttId[$attendanceInfo->getId()] = array(
  5685.                                 'attendanceInfo' => $attendanceInfo,
  5686.                                 'empId' => $empId,
  5687.                                 'lat' => 0,
  5688.                                 'lng' => 0,
  5689.                                 'address' => 0,
  5690.                                 'sysUserId' => $sysUserId,
  5691.                                 'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5692.                                 'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5693.                                 'positionArray' => []
  5694.                             );
  5695.                         $posData = array(
  5696.                             'ts' => $dtTs,
  5697.                             'lat' => $d['lat'],
  5698.                             'lng' => $d['lng'],
  5699.                             'marker' => $d['markerId'],
  5700.                             'src' => 2,
  5701.                         );
  5702.                         $posDataArray = array(
  5703.                             $dtTs,
  5704.                             $d['lat'],
  5705.                             $d['lng'],
  5706.                             $d['markerId'],
  5707.                             2
  5708.                         );
  5709.                         $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  5710.                         //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  5711.                         $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  5712.                         $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  5713.                         $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  5714.                         $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  5715.                         if (isset($d['address']))
  5716.                             $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  5717. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  5718.                     }
  5719.                     $response = array(
  5720.                         'success' => true,
  5721.                     );
  5722.                     foreach ($dataByAttId as $attInfoId => $d) {
  5723.                         $response HumanResource::setAttendanceLogFlutterApp($em,
  5724.                             $d['empId'],
  5725.                             $d['sysUserId'],
  5726.                             $d['companyId'],
  5727.                             $d['appId'],
  5728.                             $request,
  5729.                             $d['attendanceInfo'],
  5730.                             $options,
  5731.                             $d['positionArray'],
  5732.                             $d['lat'],
  5733.                             $d['lng'],
  5734.                             $d['address'],
  5735.                             $d['markerId']
  5736.                         );
  5737.                     }
  5738.                 }
  5739.             }
  5740.         }
  5741.         if ($token != '')
  5742.             MiscActions::DeleteToken($em_goc$token);
  5743.         $session->clear();
  5744.         $session->set('CLEARLOGIN'1);
  5745.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  5746.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  5747.                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  5748.             }
  5749.         } else {
  5750.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  5751.         }
  5752. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  5753. //            )
  5754. //
  5755. //        );
  5756.         if ($routeName == 'app_logout_api' || $request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  5757.             if ($userId) {
  5758.                 return new JsonResponse(array(
  5759.                     "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  5760.                     "message" => "Logout Successfull!",
  5761.                     'session_data' => [],
  5762.                     'userId' => $userId
  5763.                 ));
  5764.             } else {
  5765.                 return new JsonResponse(array(
  5766.                     "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  5767.                     "message" => "Already Logout",
  5768.                     'session_data' => [],
  5769.                     'userId' => $userId
  5770.                 ));
  5771.             }
  5772.         }
  5773.         return $this->redirectToRoute("dashboard");
  5774.     }
  5775.     public function applicantLoginAction(Request $request$encData ''$remoteVerify 0)
  5776.     {
  5777.         $session $request->getSession();
  5778.         $email $request->getSession()->get('userEmail');
  5779.         $sessionUserId $request->getSession()->get('userId');
  5780.         $oAuthData = [];
  5781. //    $encData='';
  5782.         $em $this->getDoctrine()->getManager('company_group');
  5783.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  5784.         $redirectRoute 'dashboard';
  5785.         if ($encData != '') {
  5786.             if ($encData == '8917922')
  5787.                 $redirectRoute 'apply_for_consultant';
  5788.         }
  5789.         if ($request->query->has('encData')) {
  5790.             $encData $request->query->get('encData');
  5791.             if ($encData == '8917922')
  5792.                 $redirectRoute 'apply_for_consultant';
  5793.         }
  5794.         $message '';
  5795.         $errorField '_NONE_';
  5796.         if ($request->query->has('message')) {
  5797.             $message $request->query->get('message');
  5798.         }
  5799.         if ($request->query->has('errorField')) {
  5800.             $errorField $request->query->get('errorField');
  5801.         }
  5802.         if ($request->request->has('oAuthData')) {
  5803.             $oAuthData $request->request->get('oAuthData', []);
  5804.         } else {
  5805.             $oAuthData = [
  5806.                 'email' => $request->request->get('email'''),
  5807.                 'uniqueId' => $request->request->get('uniqueId'''),
  5808.                 'oAuthHash' => '_NONE_',
  5809.                 'image' => $request->request->get('image'''),
  5810.                 'emailVerified' => $request->request->get('emailVerified'''),
  5811.                 'name' => $request->request->get('name'''),
  5812.                 'firstName' => $request->request->get('firstName'''),
  5813.                 'lastName' => $request->request->get('lastName'''),
  5814.                 'type' => 1,
  5815.                 'token' => $request->request->get('oAuthtoken'''),
  5816.             ];
  5817.         }
  5818.         $isApplicantExist null;
  5819.         if ($email) {
  5820.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5821.                 $isApplicantExist $applicantRepo->findOneBy([
  5822.                     'applicantId' => $sessionUserId
  5823.                 ]);
  5824.             } else
  5825.                 return $this->redirectToRoute($redirectRoute);
  5826.         }
  5827.         $google_client = new Google_Client();
  5828. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  5829. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  5830.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  5831.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  5832.         } else {
  5833.             $url $this->generateUrl(
  5834.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  5835.             );
  5836.         }
  5837.         $selector BuddybeeConstant::$selector;
  5838.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  5839.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  5840. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  5841.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  5842. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  5843.         $google_client->setRedirectUri($url);
  5844.         $google_client->setAccessType('offline');        // offline access
  5845.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  5846.         $google_client->addScope('email');
  5847.         $google_client->addScope('profile');
  5848.         $google_client->addScope('openid');
  5849. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  5850.         //linked in 1st
  5851.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  5852.             $curl curl_init();
  5853.             curl_setopt_array($curl, array(
  5854.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  5855.                 CURLOPT_HEADER => false,  // don't return headers
  5856.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5857.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5858.                 CURLOPT_ENCODING => "",     // handle compressed
  5859.                 CURLOPT_USERAGENT => "test"// name of client
  5860.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5861.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5862.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  5863.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  5864.                 CURLOPT_USERAGENT => 'InnoPM',
  5865.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  5866.                 CURLOPT_POST => 1,
  5867.                 CURLOPT_HTTPHEADER => array(
  5868.                     'Content-Type: application/x-www-form-urlencoded'
  5869.                 )
  5870.             ));
  5871.             $content curl_exec($curl);
  5872.             $contentArray = [];
  5873.             curl_close($curl);
  5874.             $token false;
  5875. //      return new JsonResponse(array(
  5876. //          'content'=>$content,
  5877. //          'contentArray'=>json_decode($content,true),
  5878. //
  5879. //      ));
  5880.             if ($content) {
  5881.                 $contentArray json_decode($contenttrue);
  5882.                 $token $contentArray['access_token'];
  5883.             }
  5884.             if ($token) {
  5885.                 $applicantInfo = [];
  5886.                 $curl curl_init();
  5887.                 curl_setopt_array($curl, array(
  5888.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5889.                     CURLOPT_HEADER => false,  // don't return headers
  5890.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5891.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5892.                     CURLOPT_ENCODING => "",     // handle compressed
  5893.                     CURLOPT_USERAGENT => "test"// name of client
  5894.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5895.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5896.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5897.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  5898.                     CURLOPT_USERAGENT => 'InnoPM',
  5899.                     CURLOPT_HTTPGET => 1,
  5900.                     CURLOPT_HTTPHEADER => array(
  5901.                         'Authorization: Bearer ' $token,
  5902.                         'Header-Key-2: Header-Value-2'
  5903.                     )
  5904.                 ));
  5905.                 $userGeneralcontent curl_exec($curl);
  5906.                 curl_close($curl);
  5907.                 if ($userGeneralcontent) {
  5908.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  5909.                 }
  5910.                 $curl curl_init();
  5911.                 curl_setopt_array($curl, array(
  5912.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  5913.                     CURLOPT_HEADER => false,  // don't return headers
  5914.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  5915.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  5916.                     CURLOPT_ENCODING => "",     // handle compressed
  5917.                     CURLOPT_USERAGENT => "test"// name of client
  5918.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  5919.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  5920.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  5921.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  5922. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  5923.                     CURLOPT_USERAGENT => 'InnoPM',
  5924.                     CURLOPT_HTTPGET => 1,
  5925.                     CURLOPT_HTTPHEADER => array(
  5926.                         'Authorization: Bearer ' $token,
  5927.                         'Header-Key-2: Header-Value-2'
  5928.                     )
  5929.                 ));
  5930.                 $userEmailcontent curl_exec($curl);
  5931.                 curl_close($curl);
  5932.                 $token false;
  5933.                 if ($userEmailcontent) {
  5934.                     $userEmailcontent json_decode($userEmailcontenttrue);
  5935.                 }
  5936. //        $oAuthEmail = $applicantInfo['email'];
  5937. //        return new JsonResponse(array(
  5938. //          'userEmailcontent'=>$userEmailcontent,
  5939. //          'userGeneralcontent'=>$userGeneralcontent,
  5940. //        ));
  5941. //        return new response($userGeneralcontent);
  5942.                 $oAuthData = [
  5943.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  5944.                     'uniqueId' => $userGeneralcontent['id'],
  5945.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  5946.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  5947.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  5948.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  5949.                     'lastName' => $userGeneralcontent['localizedLastName'],
  5950.                     'type' => 1,
  5951.                     'token' => $token,
  5952.                 ];
  5953.             }
  5954.         } else if (isset($_GET["code"])) {
  5955.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  5956.             if (!isset($token['error'])) {
  5957.                 $google_client->setAccessToken($token['access_token']);
  5958.                 $google_service = new Google_Service_Oauth2($google_client);
  5959.                 $applicantInfo $google_service->userinfo->get();
  5960.                 $oAuthEmail $applicantInfo['email'];
  5961.                 $oAuthData = [
  5962.                     'email' => $applicantInfo['email'],
  5963.                     'uniqueId' => $applicantInfo['id'],
  5964.                     'image' => $applicantInfo['picture'],
  5965.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  5966.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  5967.                     'firstName' => $applicantInfo['givenName'],
  5968.                     'lastName' => $applicantInfo['familyName'],
  5969.                     'type' => $token['token_type'],
  5970.                     'token' => $token['access_token'],
  5971.                 ];
  5972.             }
  5973.         }
  5974.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  5975.             $isApplicantExist $applicantRepo->findOneBy([
  5976.                 'email' => $oAuthData['email']
  5977.             ]);
  5978.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  5979.                 $isApplicantExist $applicantRepo->findOneBy([
  5980.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  5981.                 ]);
  5982.             }
  5983.             if ($isApplicantExist) {
  5984.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  5985.                 } else
  5986.                     return $this->redirectToRoute("core_login", [
  5987.                         'id' => $isApplicantExist->getApplicantId(),
  5988.                         'oAuthData' => $oAuthData,
  5989.                         'encData' => $encData,
  5990.                         'locale' => $request->request->get('locale''en'),
  5991.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  5992.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  5993.                     ]);
  5994.             } else {
  5995.                 $fname $oAuthData['firstName'];
  5996.                 $lname $oAuthData['lastName'];
  5997.                 $img $oAuthData['image'];
  5998.                 $email $oAuthData['email'];
  5999.                 $oAuthEmail $oAuthData['email'];
  6000.                 $userName explode('@'$email)[0];
  6001.                 //now check if same username exists
  6002.                 $username_already_exist 1;
  6003.                 $initial_user_name $userName;
  6004.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6005.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6006.                     $isUsernameExist $applicantRepo->findOneBy([
  6007.                         'username' => $userName
  6008.                     ]);
  6009.                     if ($isUsernameExist) {
  6010.                         $username_already_exist 1;
  6011.                         $userName $initial_user_name '' rand(3009987);
  6012.                     } else {
  6013.                         $username_already_exist 0;
  6014.                     }
  6015.                     $timeoutSafeCount--;
  6016.                 }
  6017.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6018.                     $currentUnixTimeStamp '';
  6019.                     $currentUnixTime = new \DateTime();
  6020.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6021.                     $userName $userName '' $currentUnixTimeStamp;
  6022.                 }
  6023.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6024.                 $charactersLength strlen($characters);
  6025.                 $length 8;
  6026.                 $password 0;
  6027.                 for ($i 0$i $length$i++) {
  6028.                     $password .= $characters[rand(0$charactersLength 1)];
  6029.                 }
  6030.                 $newApplicant = new EntityApplicantDetails();
  6031.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6032.                 $newApplicant->setEmail($email);
  6033.                 $newApplicant->setUserName($userName);
  6034.                 $newApplicant->setFirstname($fname);
  6035.                 $newApplicant->setLastname($lname);
  6036.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6037.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6038.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6039.                 $newApplicant->setAccountStatus(1);
  6040.                 //salt will be username
  6041. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  6042.                 $salt uniqid(mt_rand());
  6043.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6044.                 $newApplicant->setPassword($encodedPassword);
  6045.                 $newApplicant->setSalt($salt);
  6046.                 $newApplicant->setTempPassword($password);
  6047. //                $newApplicant->setPassword($password);
  6048.                 $marker $userName '-' time();
  6049. //                $extension_here=$uploadedFile->guessExtension();
  6050. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6051. //                $path = $fileName;
  6052.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6053.                 if (!file_exists($upl_dir)) {
  6054.                     mkdir($upl_dir0777true);
  6055.                 }
  6056.                 $ch curl_init($img);
  6057.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6058.                 curl_setopt($chCURLOPT_FILE$fp);
  6059.                 curl_setopt($chCURLOPT_HEADER0);
  6060.                 curl_exec($ch);
  6061.                 curl_close($ch);
  6062.                 fclose($fp);
  6063.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6064. //                $newApplicant->setImage($img);
  6065.                 $newApplicant->setIsConsultant(0);
  6066.                 $newApplicant->setIsTemporaryEntry(0);
  6067.                 $newApplicant->setApplyForConsultant(0);
  6068.                 $newApplicant->setTriggerResetPassword(0);
  6069.                 $em->persist($newApplicant);
  6070.                 $em->flush();
  6071.                 $isApplicantExist $newApplicant;
  6072.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6073.                     if ($systemType == '_BUDDYBEE_') {
  6074.                         $bodyHtml '';
  6075.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6076.                         $bodyData = array(
  6077.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6078.                             'email' => $userName,
  6079.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  6080.                             'password' => $newApplicant->getTempPassword(),
  6081.                         );
  6082.                         $attachments = [];
  6083.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6084. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6085.                         $new_mail $this->get('mail_module');
  6086.                         $new_mail->sendMyMail(array(
  6087.                             'senderHash' => '_CUSTOM_',
  6088.                             //                        'senderHash'=>'_CUSTOM_',
  6089.                             'forwardToMailAddress' => $forwardToMailAddress,
  6090.                             'subject' => 'Welcome to BuddyBee ',
  6091. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6092.                             'attachments' => $attachments,
  6093.                             'toAddress' => $forwardToMailAddress,
  6094.                             'fromAddress' => 'registration@buddybee.eu',
  6095.                             'userName' => 'registration@buddybee.eu',
  6096.                             'password' => 'Y41dh8g0112',
  6097.                             'smtpServer' => 'smtp.hostinger.com',
  6098.                             'smtpPort' => 465,
  6099.                             'encryptionMethod' => 'ssl',
  6100. //                            'emailBody' => $bodyHtml,
  6101.                             'mailTemplate' => $bodyTemplate,
  6102.                             'templateData' => $bodyData,
  6103. //                        'embedCompanyImage' => 1,
  6104. //                        'companyId' => $companyId,
  6105. //                        'companyImagePath' => $company_data->getImage()
  6106.                         ));
  6107.                     } else {
  6108.                         $bodyHtml '';
  6109.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6110.                         $bodyData = array(
  6111.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6112.                             'email' => 'APP-' $userName,
  6113.                             'password' => $newApplicant->getPassword(),
  6114.                         );
  6115.                         $attachments = [];
  6116.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6117. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6118.                         $new_mail $this->get('mail_module');
  6119.                         $new_mail->sendMyMail(array(
  6120.                             'senderHash' => '_CUSTOM_',
  6121.                             //                        'senderHash'=>'_CUSTOM_',
  6122.                             'forwardToMailAddress' => $forwardToMailAddress,
  6123.                             'subject' => 'Applicant Registration on Honeybee',
  6124. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6125.                             'attachments' => $attachments,
  6126.                             'toAddress' => $forwardToMailAddress,
  6127.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6128.                             'userName' => 'accounts@ourhoneybee.eu',
  6129.                             'password' => 'Honeybee@0112',
  6130.                             'smtpServer' => 'smtp.hostinger.com',
  6131.                             'smtpPort' => 465,
  6132.                             'encryptionMethod' => 'ssl',
  6133. //                            'emailBody' => $bodyHtml,
  6134.                             'mailTemplate' => $bodyTemplate,
  6135.                             'templateData' => $bodyData,
  6136. //                        'embedCompanyImage' => 1,
  6137. //                        'companyId' => $companyId,
  6138. //                        'companyImagePath' => $company_data->getImage()
  6139.                         ));
  6140.                     }
  6141.                 }
  6142.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6143.                 } else {
  6144.                     return $this->redirectToRoute("core_login", [
  6145.                         'id' => $newApplicant->getApplicantId(),
  6146.                         'oAuthData' => $oAuthData,
  6147.                         'encData' => $encData,
  6148.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6149.                         'locale' => $request->request->get('locale''en'),
  6150.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6151.                     ]);
  6152.                 }
  6153.             }
  6154.         }
  6155.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6156.             if ($isApplicantExist) {
  6157.                 $user $isApplicantExist;
  6158.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6159.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6160.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6161.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6162.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6163.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6164.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6165.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6166.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6167.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6168.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6169.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6170.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6171.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6172.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6173.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6174.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6175.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6176.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6177.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6178.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6179.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6180.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6181.                     $session->set('userCompanyVibrantList'json_encode([]));
  6182.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6183.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6184.                     $session->set(UserConstants::USER_APP_ID0);
  6185.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6186.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6187.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6188.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6189.                     $session->set(UserConstants::USER_GOC_ID0);
  6190.                     $session->set(UserConstants::USER_DB_NAME'');
  6191.                     $session->set(UserConstants::USER_DB_USER'');
  6192.                     $session->set(UserConstants::USER_DB_PASS'');
  6193.                     $session->set(UserConstants::USER_DB_HOST'');
  6194.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6195.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6196.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6197.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6198.                     $session->set('locale'$request->request->get('locale'''));
  6199.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6200.                     $route_list_array = [];
  6201.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6202.                     $loginID 0;
  6203.                     $loginID MiscActions::addEntityUserLoginLog(
  6204.                         $em,
  6205.                         $session->get(UserConstants::USER_ID),
  6206.                         $session->get(UserConstants::USER_ID),
  6207.                         1,
  6208.                         $request->server->get("REMOTE_ADDR"),
  6209.                         0,
  6210.                         $request->request->get('deviceId'''),
  6211.                         $request->request->get('oAuthToken'''),
  6212.                         $request->request->get('oAuthType'''),
  6213.                         $request->request->get('locale'''),
  6214.                         $request->request->get('firebaseToken''')
  6215.                     );
  6216.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6217.                     $session_data = array(
  6218.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6219.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6220.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6221.                         'oAuthToken' => $session->get('oAuthToken'),
  6222.                         'locale' => $session->get('locale'),
  6223.                         'firebaseToken' => $session->get('firebaseToken'),
  6224.                         'token' => $session->get('token'),
  6225.                         'firstLogin' => 0,
  6226.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6227.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6228.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6229.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6230.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6231.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6232.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6233.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6234.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6235.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6236.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6237.                         'oAuthImage' => $session->get('oAuthImage'),
  6238.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6239.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6240.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6241.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6242.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6243.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6244.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6245.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6246.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6247.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6248.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6249.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6250.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6251.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6252.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6253.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6254.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6255.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6256.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6257.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6258.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6259.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6260.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6261.                         //new
  6262.                         'appIdList' => $session->get('appIdList'),
  6263.                         'branchIdList' => $session->get('branchIdList'null),
  6264.                         'branchId' => $session->get('branchId'null),
  6265.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6266.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6267.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6268.                     );
  6269.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6270.                     $session_data $tokenData['sessionData'];
  6271.                     $token $tokenData['token'];
  6272.                     $session->set('token'$token);
  6273.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6274.                         $session->set('remoteVerified'1);
  6275.                         $response = new JsonResponse(array(
  6276.                             'token' => $token,
  6277.                             'uid' => $session->get(UserConstants::USER_ID),
  6278.                             'session' => $session,
  6279.                             'success' => true,
  6280.                             'session_data' => $session_data,
  6281.                         ));
  6282.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6283.                         return $response;
  6284.                     }
  6285.                     if ($request->request->has('referer_path')) {
  6286.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6287.                             return $this->redirect($request->request->get('referer_path'));
  6288.                         }
  6289.                     }
  6290.                     $redirectRoute 'applicant_dashboard';
  6291.                     if ($request->query->has('encData')) {
  6292.                         if ($request->query->get('encData') == '8917922')
  6293.                             $redirectRoute 'apply_for_consultant';
  6294.                     }
  6295.                     return $this->redirectToRoute($redirectRoute);
  6296.                 }
  6297. //                    $response = new JsonResponse(array(
  6298. //                        'token' => $token,
  6299. //                        'uid' => $session->get(UserConstants::USER_ID),
  6300. //                        'session' => $session,
  6301. //
  6302. //                        'success' => true,
  6303. //                        'session_data' => $session_data,
  6304. //
  6305. //                    ));
  6306. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6307. //                    return $response;
  6308. //                    return $this->redirectToRoute("user_login", [
  6309. //                        'id' => $isApplicantExist->getApplicantId(),
  6310. //                        'oAuthData' => $oAuthData,
  6311. //                        'encData' => $encData,
  6312. //                        'locale' => $request->request->get('locale', 'en'),
  6313. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  6314. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  6315. //                    ]);
  6316.             }
  6317.         }
  6318. //        if ($request->isMethod('POST')){
  6319. //            $new = new EntityApplicantDetails();
  6320. //
  6321. //            $new-> setUsername->$request->request->get('userName');
  6322. //            $new-> setEmail()->$request->request->get('email');
  6323. //            $new-> setPassword()->$request->request->get('password');
  6324. //            $new-> setSelector()->$request->request->get('selector');
  6325. //
  6326. //
  6327. //            $em->persist($new);
  6328. //            $em->flush();
  6329. //        }
  6330.         $selector BuddybeeConstant::$selector;
  6331.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6332.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  6333.         if ($systemType == '_ERP_') {
  6334.         } else if ($systemType == '_BUDDYBEE_') {
  6335.             return $this->render(
  6336.                 '@Authentication/pages/views/applicant_login.html.twig',
  6337.                 [
  6338.                     'page_title' => 'BuddyBee Login',
  6339.                     'oAuthLink' => $google_client->createAuthUrl(),
  6340.                     'redirect_url' => $url,
  6341.                     'message' => $message,
  6342.                     'errorField' => $errorField,
  6343.                     'encData' => $encData,
  6344.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  6345.                     'selector' => $selector
  6346.                 ]
  6347.             );
  6348.         }
  6349.         return $this->render(
  6350.             '@Authentication/pages/views/applicant_login.html.twig',
  6351.             [
  6352.                 'page_title' => 'Applicant Registration',
  6353.                 'oAuthLink' => $google_client->createAuthUrl(),
  6354.                 'redirect_url' => $url,
  6355.                 'encData' => $encData,
  6356.                 'message' => $message,
  6357.                 'errorField' => $errorField,
  6358.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  6359.                 'selector' => $selector
  6360.             ]
  6361.         );
  6362.     }
  6363.     public function centralLoginAction(Request $request$encData ''$remoteVerify 0)
  6364.     {
  6365.         $session $request->getSession();
  6366.         $email $request->getSession()->get('userEmail');
  6367.         $sessionUserId $request->getSession()->get('userId');
  6368.         $oAuthData = [];
  6369. //    $encData='';
  6370.         $em $this->getDoctrine()->getManager('company_group');
  6371.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  6372.         $redirectRoute 'dashboard';
  6373.         if ($encData != '') {
  6374.             if ($encData == '8917922')
  6375.                 $redirectRoute 'apply_for_consultant';
  6376.         }
  6377.         if ($request->query->has('encData')) {
  6378.             $encData $request->query->get('encData');
  6379.             if ($encData == '8917922')
  6380.                 $redirectRoute 'apply_for_consultant';
  6381.         }
  6382.         $message '';
  6383.         $errorField '_NONE_';
  6384.         if ($request->query->has('message')) {
  6385.             $message $request->query->get('message');
  6386.         }
  6387.         if ($request->query->has('errorField')) {
  6388.             $errorField $request->query->get('errorField');
  6389.         }
  6390.         if ($request->request->has('oAuthData')) {
  6391.             $oAuthData $request->request->get('oAuthData', []);
  6392.         } else {
  6393.             $oAuthData = [
  6394.                 'email' => $request->request->get('email'''),
  6395.                 'uniqueId' => $request->request->get('uniqueId'''),
  6396.                 'oAuthHash' => '_NONE_',
  6397.                 'image' => $request->request->get('image'''),
  6398.                 'emailVerified' => $request->request->get('emailVerified'''),
  6399.                 'name' => $request->request->get('name'''),
  6400.                 'firstName' => $request->request->get('firstName'''),
  6401.                 'lastName' => $request->request->get('lastName'''),
  6402.                 'type' => 1,
  6403.                 'token' => $request->request->get('oAuthtoken'''),
  6404.             ];
  6405.         }
  6406.         $isApplicantExist null;
  6407.         if ($email) {
  6408.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6409.                 $isApplicantExist $applicantRepo->findOneBy([
  6410.                     'applicantId' => $sessionUserId
  6411.                 ]);
  6412.             } else
  6413.                 return $this->redirectToRoute($redirectRoute);
  6414.         }
  6415.         $google_client = new Google_Client();
  6416. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6417. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6418.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  6419.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  6420.         } else {
  6421.             $url $this->generateUrl(
  6422.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  6423.             );
  6424.         }
  6425.         $selector BuddybeeConstant::$selector;
  6426.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  6427.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  6428. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  6429. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  6430.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  6431. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  6432.         $google_client->setRedirectUri($url);
  6433.         $google_client->setAccessType('offline');        // offline access
  6434.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  6435.         $google_client->addScope('email');
  6436.         $google_client->addScope('profile');
  6437.         $google_client->addScope('openid');
  6438. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  6439.         //linked in 1st
  6440.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  6441.             $curl curl_init();
  6442.             curl_setopt_array($curl, array(
  6443.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  6444.                 CURLOPT_HEADER => false,  // don't return headers
  6445.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6446.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6447.                 CURLOPT_ENCODING => "",     // handle compressed
  6448.                 CURLOPT_USERAGENT => "test"// name of client
  6449.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6450.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6451.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  6452.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  6453.                 CURLOPT_USERAGENT => 'InnoPM',
  6454.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  6455.                 CURLOPT_POST => 1,
  6456.                 CURLOPT_HTTPHEADER => array(
  6457.                     'Content-Type: application/x-www-form-urlencoded'
  6458.                 )
  6459.             ));
  6460.             $content curl_exec($curl);
  6461.             $contentArray = [];
  6462.             curl_close($curl);
  6463.             $token false;
  6464. //      return new JsonResponse(array(
  6465. //          'content'=>$content,
  6466. //          'contentArray'=>json_decode($content,true),
  6467. //
  6468. //      ));
  6469.             if ($content) {
  6470.                 $contentArray json_decode($contenttrue);
  6471.                 $token $contentArray['access_token'];
  6472.             }
  6473.             if ($token) {
  6474.                 $applicantInfo = [];
  6475.                 $curl curl_init();
  6476.                 curl_setopt_array($curl, array(
  6477.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6478.                     CURLOPT_HEADER => false,  // don't return headers
  6479.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6480.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6481.                     CURLOPT_ENCODING => "",     // handle compressed
  6482.                     CURLOPT_USERAGENT => "test"// name of client
  6483.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6484.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6485.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6486.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  6487.                     CURLOPT_USERAGENT => 'InnoPM',
  6488.                     CURLOPT_HTTPGET => 1,
  6489.                     CURLOPT_HTTPHEADER => array(
  6490.                         'Authorization: Bearer ' $token,
  6491.                         'Header-Key-2: Header-Value-2'
  6492.                     )
  6493.                 ));
  6494.                 $userGeneralcontent curl_exec($curl);
  6495.                 curl_close($curl);
  6496.                 if ($userGeneralcontent) {
  6497.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  6498.                 }
  6499.                 $curl curl_init();
  6500.                 curl_setopt_array($curl, array(
  6501.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  6502.                     CURLOPT_HEADER => false,  // don't return headers
  6503.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  6504.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  6505.                     CURLOPT_ENCODING => "",     // handle compressed
  6506.                     CURLOPT_USERAGENT => "test"// name of client
  6507.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  6508.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  6509.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  6510.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  6511. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  6512.                     CURLOPT_USERAGENT => 'InnoPM',
  6513.                     CURLOPT_HTTPGET => 1,
  6514.                     CURLOPT_HTTPHEADER => array(
  6515.                         'Authorization: Bearer ' $token,
  6516.                         'Header-Key-2: Header-Value-2'
  6517.                     )
  6518.                 ));
  6519.                 $userEmailcontent curl_exec($curl);
  6520.                 curl_close($curl);
  6521.                 $token false;
  6522.                 if ($userEmailcontent) {
  6523.                     $userEmailcontent json_decode($userEmailcontenttrue);
  6524.                 }
  6525. //        $oAuthEmail = $applicantInfo['email'];
  6526. //        return new JsonResponse(array(
  6527. //          'userEmailcontent'=>$userEmailcontent,
  6528. //          'userGeneralcontent'=>$userGeneralcontent,
  6529. //        ));
  6530. //        return new response($userGeneralcontent);
  6531.                 $oAuthData = [
  6532.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6533.                     'uniqueId' => $userGeneralcontent['id'],
  6534.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  6535.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  6536.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  6537.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  6538.                     'lastName' => $userGeneralcontent['localizedLastName'],
  6539.                     'type' => 1,
  6540.                     'token' => $token,
  6541.                 ];
  6542.             }
  6543.         } else if (isset($_GET["code"])) {
  6544.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  6545.             if (!isset($token['error'])) {
  6546.                 $google_client->setAccessToken($token['access_token']);
  6547.                 $google_service = new Google_Service_Oauth2($google_client);
  6548.                 $applicantInfo $google_service->userinfo->get();
  6549.                 $oAuthEmail $applicantInfo['email'];
  6550.                 $oAuthData = [
  6551.                     'email' => $applicantInfo['email'],
  6552.                     'uniqueId' => $applicantInfo['id'],
  6553.                     'image' => $applicantInfo['picture'],
  6554.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  6555.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  6556.                     'firstName' => $applicantInfo['givenName'],
  6557.                     'lastName' => $applicantInfo['familyName'],
  6558.                     'type' => $token['token_type'],
  6559.                     'token' => $token['access_token'],
  6560.                 ];
  6561.             }
  6562.         } else if (isset($_GET["access_token"])) {
  6563.             $token $_GET["access_token"];
  6564.             $tokenType $_GET["token_type"];
  6565.             if (!isset($token['error'])) {
  6566.                 $google_client->setAccessToken($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' => $tokenType,
  6579.                     'token' => $token,
  6580.                 ];
  6581.             }
  6582.         }
  6583.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  6584.             $isApplicantExist $applicantRepo->findOneBy([
  6585.                 'email' => $oAuthData['email']
  6586.             ]);
  6587.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  6588.                 $isApplicantExist $applicantRepo->findOneBy([
  6589.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  6590.                 ]);
  6591.             }
  6592.             if (!$isApplicantExist) {
  6593.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  6594.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  6595.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  6596.                     ->getQuery()
  6597.                     ->getResult();
  6598.                 if (!empty($usersQueried))
  6599.                     $isApplicantExist $usersQueried[0];
  6600.             }
  6601.             if ($isApplicantExist) {
  6602.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6603.                 } else
  6604.                     return $this->redirectToRoute("core_login", [
  6605.                         'id' => $isApplicantExist->getApplicantId(),
  6606.                         'oAuthData' => $oAuthData,
  6607.                         'encData' => $encData,
  6608.                         'locale' => $request->request->get('locale''en'),
  6609.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6610.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6611.                     ]);
  6612.             } else {
  6613.                 $fname $oAuthData['firstName'];
  6614.                 $lname $oAuthData['lastName'];
  6615.                 $img $oAuthData['image'];
  6616.                 $email $oAuthData['email'];
  6617.                 $oAuthEmail $oAuthData['email'];
  6618.                 $userName explode('@'$email)[0];
  6619.                 //now check if same username exists
  6620.                 $username_already_exist 1;
  6621.                 $initial_user_name $userName;
  6622.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  6623.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  6624.                     $isUsernameExist $applicantRepo->findOneBy([
  6625.                         'username' => $userName
  6626.                     ]);
  6627.                     if ($isUsernameExist) {
  6628.                         $username_already_exist 1;
  6629.                         $userName $initial_user_name '' rand(3009987);
  6630.                     } else {
  6631.                         $username_already_exist 0;
  6632.                     }
  6633.                     $timeoutSafeCount--;
  6634.                 }
  6635.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  6636.                     $currentUnixTimeStamp '';
  6637.                     $currentUnixTime = new \DateTime();
  6638.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  6639.                     $userName $userName '' $currentUnixTimeStamp;
  6640.                 }
  6641.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6642.                 $charactersLength strlen($characters);
  6643.                 $length 8;
  6644.                 $password 0;
  6645.                 for ($i 0$i $length$i++) {
  6646.                     $password .= $characters[rand(0$charactersLength 1)];
  6647.                 }
  6648.                 $newApplicant = new EntityApplicantDetails();
  6649.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  6650.                 $newApplicant->setEmail($email);
  6651.                 $newApplicant->setUserName($userName);
  6652.                 $newApplicant->setFirstname($fname);
  6653.                 $newApplicant->setLastname($lname);
  6654.                 $newApplicant->setOAuthEmail($oAuthEmail);
  6655.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  6656.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  6657.                 $newApplicant->setAccountStatus(1);
  6658.                 $salt uniqid(mt_rand());
  6659.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  6660.                 $newApplicant->setPassword($encodedPassword);
  6661.                 $newApplicant->setSalt($salt);
  6662.                 $newApplicant->setTempPassword($password);;
  6663. //                $newApplicant->setPassword($password);
  6664.                 $marker $userName '-' time();
  6665. //                $extension_here=$uploadedFile->guessExtension();
  6666. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  6667. //                $path = $fileName;
  6668.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  6669.                 if (!file_exists($upl_dir)) {
  6670.                     mkdir($upl_dir0777true);
  6671.                 }
  6672.                 $ch curl_init($img);
  6673.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  6674.                 curl_setopt($chCURLOPT_FILE$fp);
  6675.                 curl_setopt($chCURLOPT_HEADER0);
  6676.                 curl_exec($ch);
  6677.                 curl_close($ch);
  6678.                 fclose($fp);
  6679.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  6680. //                $newApplicant->setImage($img);
  6681.                 $newApplicant->setIsConsultant(0);
  6682.                 $newApplicant->setIsTemporaryEntry(0);
  6683.                 $newApplicant->setApplyForConsultant(0);
  6684.                 $em->persist($newApplicant);
  6685.                 $em->flush();
  6686.                 $isApplicantExist $newApplicant;
  6687.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  6688.                     if ($systemType == '_BUDDYBEE_') {
  6689.                         $bodyHtml '';
  6690.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  6691.                         $bodyData = array(
  6692.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6693.                             'email' => $userName,
  6694.                             'password' => $newApplicant->getPassword(),
  6695.                         );
  6696.                         $attachments = [];
  6697.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6698. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6699.                         $new_mail $this->get('mail_module');
  6700.                         $new_mail->sendMyMail(array(
  6701.                             'senderHash' => '_CUSTOM_',
  6702.                             //                        'senderHash'=>'_CUSTOM_',
  6703.                             'forwardToMailAddress' => $forwardToMailAddress,
  6704.                             'subject' => 'Welcome to BuddyBee ',
  6705. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6706.                             'attachments' => $attachments,
  6707.                             'toAddress' => $forwardToMailAddress,
  6708.                             'fromAddress' => 'registration@buddybee.eu',
  6709.                             'userName' => 'registration@buddybee.eu',
  6710.                             'password' => 'Y41dh8g0112',
  6711.                             'smtpServer' => 'smtp.hostinger.com',
  6712.                             'smtpPort' => 465,
  6713.                             'encryptionMethod' => 'ssl',
  6714. //                            'emailBody' => $bodyHtml,
  6715.                             'mailTemplate' => $bodyTemplate,
  6716.                             'templateData' => $bodyData,
  6717. //                        'embedCompanyImage' => 1,
  6718. //                        'companyId' => $companyId,
  6719. //                        'companyImagePath' => $company_data->getImage()
  6720.                         ));
  6721.                     } else {
  6722.                         $bodyHtml '';
  6723.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  6724.                         $bodyData = array(
  6725.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  6726.                             'email' => 'APP-' $userName,
  6727.                             'password' => $newApplicant->getPassword(),
  6728.                         );
  6729.                         $attachments = [];
  6730.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  6731. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  6732.                         $new_mail $this->get('mail_module');
  6733.                         $new_mail->sendMyMail(array(
  6734.                             'senderHash' => '_CUSTOM_',
  6735.                             //                        'senderHash'=>'_CUSTOM_',
  6736.                             'forwardToMailAddress' => $forwardToMailAddress,
  6737.                             'subject' => 'Applicant Registration on Honeybee',
  6738. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  6739.                             'attachments' => $attachments,
  6740.                             'toAddress' => $forwardToMailAddress,
  6741.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  6742.                             'userName' => 'accounts@ourhoneybee.eu',
  6743.                             'password' => 'Honeybee@0112',
  6744.                             'smtpServer' => 'smtp.hostinger.com',
  6745.                             'smtpPort' => 465,
  6746.                             'encryptionMethod' => 'ssl',
  6747. //                            'emailBody' => $bodyHtml,
  6748.                             'mailTemplate' => $bodyTemplate,
  6749.                             'templateData' => $bodyData,
  6750. //                        'embedCompanyImage' => 1,
  6751. //                        'companyId' => $companyId,
  6752. //                        'companyImagePath' => $company_data->getImage()
  6753.                         ));
  6754.                     }
  6755.                 }
  6756.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6757.                 } else {
  6758.                     return $this->redirectToRoute("core_login", [
  6759.                         'id' => $newApplicant->getApplicantId(),
  6760.                         'oAuthData' => $oAuthData,
  6761.                         'encData' => $encData,
  6762.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  6763.                         'locale' => $request->request->get('locale''en'),
  6764.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  6765.                     ]);
  6766.                 }
  6767.             }
  6768.         }
  6769.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  6770.             if ($isApplicantExist) {
  6771.                 $user $isApplicantExist;
  6772.                 $userType UserConstants::USER_TYPE_APPLICANT;
  6773.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  6774.                 $globalId $user->getApplicantId();
  6775.                 $gocList $em
  6776.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  6777.                     ->findBy(
  6778.                         array(//                        'active' => 1
  6779.                         )
  6780.                     );
  6781.                 $gocDataList = [];
  6782.                 $gocDataListForLoginWeb = [];
  6783.                 $gocDataListByAppId = [];
  6784.                 foreach ($gocList as $entry) {
  6785.                     $d = array(
  6786.                         'name' => $entry->getName(),
  6787.                         'image' => $entry->getImage(),
  6788.                         'id' => $entry->getId(),
  6789.                         'appId' => $entry->getAppId(),
  6790.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  6791.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  6792.                         'dbName' => $entry->getDbName(),
  6793.                         'dbUser' => $entry->getDbUser(),
  6794.                         'dbPass' => $entry->getDbPass(),
  6795.                         'dbHost' => $entry->getDbHost(),
  6796.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  6797.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  6798.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  6799.                         'companyRemaining' => $entry->getCompanyRemaining(),
  6800.                         'companyAllowed' => $entry->getCompanyAllowed(),
  6801.                     );
  6802.                     $gocDataList[$entry->getId()] = $d;
  6803.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  6804.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  6805.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  6806.                 }
  6807.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  6808.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  6809.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  6810.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  6811.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  6812.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  6813.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  6814.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  6815.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  6816.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  6817.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  6818.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  6819.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  6820.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  6821.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  6822.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  6823.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  6824.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  6825.                     $session->set(UserConstants::USER_COMPANY_ID1);
  6826.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  6827.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  6828.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6829.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  6830.                     $session->set('userCompanyVibrantList'json_encode([]));
  6831.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  6832.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  6833.                     $session->set(UserConstants::USER_APP_ID0);
  6834.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  6835.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  6836.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  6837.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  6838.                     $session->set(UserConstants::USER_GOC_ID0);
  6839.                     $session->set(UserConstants::USER_DB_NAME'');
  6840.                     $session->set(UserConstants::USER_DB_USER'');
  6841.                     $session->set(UserConstants::USER_DB_PASS'');
  6842.                     $session->set(UserConstants::USER_DB_HOST'');
  6843.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  6844.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  6845.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  6846.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  6847.                     $session->set('locale'$request->request->get('locale'''));
  6848.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  6849.                     $route_list_array = [];
  6850.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  6851.                     $loginID 0;
  6852.                     $loginID MiscActions::addEntityUserLoginLog(
  6853.                         $em,
  6854.                         $session->get(UserConstants::USER_ID),
  6855.                         $session->get(UserConstants::USER_ID),
  6856.                         1,
  6857.                         $request->server->get("REMOTE_ADDR"),
  6858.                         0,
  6859.                         $request->request->get('deviceId'''),
  6860.                         $request->request->get('oAuthToken'''),
  6861.                         $request->request->get('oAuthType'''),
  6862.                         $request->request->get('locale'''),
  6863.                         $request->request->get('firebaseToken''')
  6864.                     );
  6865.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  6866.                     $session_data = array(
  6867.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  6868.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  6869.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  6870.                         'oAuthToken' => $session->get('oAuthToken'),
  6871.                         'locale' => $session->get('locale'),
  6872.                         'firebaseToken' => $session->get('firebaseToken'),
  6873.                         'token' => $session->get('token'),
  6874.                         'firstLogin' => 0,
  6875.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  6876.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  6877.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  6878.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  6879.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  6880.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  6881.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  6882.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  6883.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  6884.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  6885.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  6886.                         'oAuthImage' => $session->get('oAuthImage'),
  6887.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  6888.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  6889.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  6890.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  6891.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  6892.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  6893.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  6894.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  6895.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  6896.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  6897.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  6898.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  6899.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  6900.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  6901.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  6902.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  6903.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  6904.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  6905.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  6906.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  6907.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  6908.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  6909.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  6910.                         //new
  6911.                         'appIdList' => $session->get('appIdList'),
  6912.                         'branchIdList' => $session->get('branchIdList'null),
  6913.                         'branchId' => $session->get('branchId'null),
  6914.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  6915.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  6916.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  6917.                     );
  6918.                     $accessList = [];
  6919. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  6920.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  6921.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  6922.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  6923.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  6924.                                 $d = array(
  6925.                                     'userType' => $thisUserUserType,
  6926. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  6927.                                     'userTypeName' => $userTypeName,
  6928.                                     'globalId' => $globalId,
  6929.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  6930.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  6931.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  6932.                                     'systemType' => '_ERP_',
  6933.                                     'companyId' => 1,
  6934.                                     'appId' => $thisUserAppId,
  6935.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  6936.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  6937.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  6938.                                             array(
  6939.                                                 'globalId' => $globalId,
  6940.                                                 'appId' => $thisUserAppId,
  6941.                                                 'authenticate' => 1,
  6942.                                                 'userType' => $thisUserUserType,
  6943.                                                 'userTypeName' => $userTypeName
  6944.                                             )
  6945.                                         )
  6946.                                     ),
  6947.                                     'userCompanyList' => [
  6948.                                     ]
  6949.                                 );
  6950.                                 $accessList[] = $d;
  6951.                             }
  6952.                         }
  6953.                     }
  6954.                     $session_data['userAccessList'] = $accessList;
  6955.                     $session->set('userAccessList'json_encode($accessList));
  6956.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  6957.                     $session_data $tokenData['sessionData'];
  6958.                     $token $tokenData['token'];
  6959.                     $session->set('token'$token);
  6960.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  6961.                         $session->set('remoteVerified'1);
  6962.                         $response = new JsonResponse(array(
  6963.                             'token' => $token,
  6964.                             'uid' => $session->get(UserConstants::USER_ID),
  6965.                             'session' => $session,
  6966.                             'success' => true,
  6967.                             'session_data' => $session_data,
  6968.                         ));
  6969.                         $response->headers->set('Access-Control-Allow-Origin''*');
  6970.                         return $response;
  6971.                     }
  6972.                     if ($request->request->has('referer_path')) {
  6973.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  6974.                             return $this->redirect($request->request->get('referer_path'));
  6975.                         }
  6976.                     }
  6977.                     $redirectRoute 'applicant_dashboard';
  6978.                     if ($request->query->has('encData')) {
  6979.                         if ($request->query->get('encData') == '8917922')
  6980.                             $redirectRoute 'apply_for_consultant';
  6981.                     }
  6982.                     return $this->redirectToRoute($redirectRoute);
  6983.                 }
  6984. //                    $response = new JsonResponse(array(
  6985. //                        'token' => $token,
  6986. //                        'uid' => $session->get(UserConstants::USER_ID),
  6987. //                        'session' => $session,
  6988. //
  6989. //                        'success' => true,
  6990. //                        'session_data' => $session_data,
  6991. //
  6992. //                    ));
  6993. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  6994. //                    return $response;
  6995. //                    return $this->redirectToRoute("user_login", [
  6996. //                        'id' => $isApplicantExist->getApplicantId(),
  6997. //                        'oAuthData' => $oAuthData,
  6998. //                        'encData' => $encData,
  6999. //                        'locale' => $request->request->get('locale', 'en'),
  7000. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7001. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7002. //                    ]);
  7003.             }
  7004.         }
  7005.         $selector BuddybeeConstant::$selector;
  7006.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7007.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7008.         if ($systemType == '_ERP_') {
  7009.         } else if ($systemType == '_CENTRAL_') {
  7010.             return $this->render(
  7011.                 '@Authentication/pages/views/central_login.html.twig',
  7012.                 [
  7013.                     'page_title' => 'Central Login',
  7014.                     'oAuthLink' => $google_client->createAuthUrl(),
  7015.                     'redirect_url' => $url,
  7016.                     'message' => $message,
  7017.                     'systemType' => $systemType,
  7018.                     'ownServerId' => $ownServerId,
  7019.                     'errorField' => '',
  7020.                     'encData' => $encData,
  7021.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7022.                     'selector' => $selector,
  7023.                 ]
  7024.             );
  7025.         } else if ($systemType == '_BUDDYBEE_') {
  7026.             return $this->render(
  7027.                 '@Authentication/pages/views/applicant_login.html.twig',
  7028.                 [
  7029.                     'page_title' => 'BuddyBee Login',
  7030.                     'oAuthLink' => $google_client->createAuthUrl(),
  7031.                     'redirect_url' => $url,
  7032.                     'message' => $message,
  7033.                     'errorField' => $errorField,
  7034.                     'encData' => $encData,
  7035.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7036.                     'selector' => $selector
  7037.                 ]
  7038.             );
  7039.         }
  7040.         return $this->render(
  7041.             '@Authentication/pages/views/applicant_login.html.twig',
  7042.             [
  7043.                 'page_title' => 'Applicant Registration',
  7044.                 'oAuthLink' => $google_client->createAuthUrl(),
  7045.                 'redirect_url' => $url,
  7046.                 'encData' => $encData,
  7047.                 'message' => $message,
  7048.                 'errorField' => $errorField,
  7049.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7050.                 'selector' => $selector
  7051.             ]
  7052.         );
  7053.     }
  7054.     public function sophiaLoginAction(Request $request$encData ''$remoteVerify 0)
  7055.     {
  7056.         $session $request->getSession();
  7057.         $email $request->getSession()->get('userEmail');
  7058.         $sessionUserId $request->getSession()->get('userId');
  7059.         $oAuthData = [];
  7060. //    $encData='';
  7061.         $em $this->getDoctrine()->getManager('company_group');
  7062.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  7063.         $redirectRoute 'dashboard';
  7064.         if ($encData != '') {
  7065.             if ($encData == '8917922')
  7066.                 $redirectRoute 'apply_for_consultant';
  7067.         }
  7068.         if ($request->query->has('encData')) {
  7069.             $encData $request->query->get('encData');
  7070.             if ($encData == '8917922')
  7071.                 $redirectRoute 'apply_for_consultant';
  7072.         }
  7073.         $message '';
  7074.         $errorField '_NONE_';
  7075.         if ($request->query->has('message')) {
  7076.             $message $request->query->get('message');
  7077.         }
  7078.         if ($request->query->has('errorField')) {
  7079.             $errorField $request->query->get('errorField');
  7080.         }
  7081.         if ($request->request->has('oAuthData')) {
  7082.             $oAuthData $request->request->get('oAuthData', []);
  7083.         } else {
  7084.             $oAuthData = [
  7085.                 'email' => $request->request->get('email'''),
  7086.                 'uniqueId' => $request->request->get('uniqueId'''),
  7087.                 'oAuthHash' => '_NONE_',
  7088.                 'image' => $request->request->get('image'''),
  7089.                 'emailVerified' => $request->request->get('emailVerified'''),
  7090.                 'name' => $request->request->get('name'''),
  7091.                 'firstName' => $request->request->get('firstName'''),
  7092.                 'lastName' => $request->request->get('lastName'''),
  7093.                 'type' => 1,
  7094.                 'token' => $request->request->get('oAuthtoken'''),
  7095.             ];
  7096.         }
  7097.         $isApplicantExist null;
  7098.         if ($email) {
  7099.             if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7100.                 $isApplicantExist $applicantRepo->findOneBy([
  7101.                     'applicantId' => $sessionUserId
  7102.                 ]);
  7103.             } else
  7104.                 return $this->redirectToRoute($redirectRoute);
  7105.         }
  7106.         $google_client = new Google_Client();
  7107. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  7108. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  7109.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  7110.             $url $this->generateUrl('user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL);
  7111.         } else {
  7112.             $url $this->generateUrl(
  7113.                 'user_login', ['encData' => $encData], UrlGenerator::ABSOLUTE_URL
  7114.             );
  7115.         }
  7116.         $selector BuddybeeConstant::$selector;
  7117.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7118.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7119. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  7120. //        $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  7121.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  7122. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  7123.         $google_client->setRedirectUri($url);
  7124.         $google_client->setAccessType('offline');        // offline access
  7125.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  7126.         $google_client->addScope('email');
  7127.         $google_client->addScope('profile');
  7128.         $google_client->addScope('openid');
  7129. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  7130.         //linked in 1st
  7131.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  7132.             $curl curl_init();
  7133.             curl_setopt_array($curl, array(
  7134.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  7135.                 CURLOPT_HEADER => false,  // don't return headers
  7136.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7137.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7138.                 CURLOPT_ENCODING => "",     // handle compressed
  7139.                 CURLOPT_USERAGENT => "test"// name of client
  7140.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7141.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7142.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  7143.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  7144.                 CURLOPT_USERAGENT => 'InnoPM',
  7145.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  7146.                 CURLOPT_POST => 1,
  7147.                 CURLOPT_HTTPHEADER => array(
  7148.                     'Content-Type: application/x-www-form-urlencoded'
  7149.                 )
  7150.             ));
  7151.             $content curl_exec($curl);
  7152.             $contentArray = [];
  7153.             curl_close($curl);
  7154.             $token false;
  7155. //      return new JsonResponse(array(
  7156. //          'content'=>$content,
  7157. //          'contentArray'=>json_decode($content,true),
  7158. //
  7159. //      ));
  7160.             if ($content) {
  7161.                 $contentArray json_decode($contenttrue);
  7162.                 $token $contentArray['access_token'];
  7163.             }
  7164.             if ($token) {
  7165.                 $applicantInfo = [];
  7166.                 $curl curl_init();
  7167.                 curl_setopt_array($curl, array(
  7168.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7169.                     CURLOPT_HEADER => false,  // don't return headers
  7170.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7171.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7172.                     CURLOPT_ENCODING => "",     // handle compressed
  7173.                     CURLOPT_USERAGENT => "test"// name of client
  7174.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7175.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7176.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7177.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  7178.                     CURLOPT_USERAGENT => 'InnoPM',
  7179.                     CURLOPT_HTTPGET => 1,
  7180.                     CURLOPT_HTTPHEADER => array(
  7181.                         'Authorization: Bearer ' $token,
  7182.                         'Header-Key-2: Header-Value-2'
  7183.                     )
  7184.                 ));
  7185.                 $userGeneralcontent curl_exec($curl);
  7186.                 curl_close($curl);
  7187.                 if ($userGeneralcontent) {
  7188.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  7189.                 }
  7190.                 $curl curl_init();
  7191.                 curl_setopt_array($curl, array(
  7192.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  7193.                     CURLOPT_HEADER => false,  // don't return headers
  7194.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  7195.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  7196.                     CURLOPT_ENCODING => "",     // handle compressed
  7197.                     CURLOPT_USERAGENT => "test"// name of client
  7198.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  7199.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  7200.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  7201.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  7202. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  7203.                     CURLOPT_USERAGENT => 'InnoPM',
  7204.                     CURLOPT_HTTPGET => 1,
  7205.                     CURLOPT_HTTPHEADER => array(
  7206.                         'Authorization: Bearer ' $token,
  7207.                         'Header-Key-2: Header-Value-2'
  7208.                     )
  7209.                 ));
  7210.                 $userEmailcontent curl_exec($curl);
  7211.                 curl_close($curl);
  7212.                 $token false;
  7213.                 if ($userEmailcontent) {
  7214.                     $userEmailcontent json_decode($userEmailcontenttrue);
  7215.                 }
  7216. //        $oAuthEmail = $applicantInfo['email'];
  7217. //        return new JsonResponse(array(
  7218. //          'userEmailcontent'=>$userEmailcontent,
  7219. //          'userGeneralcontent'=>$userGeneralcontent,
  7220. //        ));
  7221. //        return new response($userGeneralcontent);
  7222.                 $oAuthData = [
  7223.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7224.                     'uniqueId' => $userGeneralcontent['id'],
  7225.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  7226.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  7227.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  7228.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  7229.                     'lastName' => $userGeneralcontent['localizedLastName'],
  7230.                     'type' => 1,
  7231.                     'token' => $token,
  7232.                 ];
  7233.             }
  7234.         } else if (isset($_GET["code"])) {
  7235.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  7236.             if (!isset($token['error'])) {
  7237.                 $google_client->setAccessToken($token['access_token']);
  7238.                 $google_service = new Google_Service_Oauth2($google_client);
  7239.                 $applicantInfo $google_service->userinfo->get();
  7240.                 $oAuthEmail $applicantInfo['email'];
  7241.                 $oAuthData = [
  7242.                     'email' => $applicantInfo['email'],
  7243.                     'uniqueId' => $applicantInfo['id'],
  7244.                     'image' => $applicantInfo['picture'],
  7245.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  7246.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  7247.                     'firstName' => $applicantInfo['givenName'],
  7248.                     'lastName' => $applicantInfo['familyName'],
  7249.                     'type' => $token['token_type'],
  7250.                     'token' => $token['access_token'],
  7251.                 ];
  7252.             }
  7253.         } else if (isset($_GET["access_token"])) {
  7254.             $token $_GET["access_token"];
  7255.             $tokenType $_GET["token_type"];
  7256.             if (!isset($token['error'])) {
  7257.                 $google_client->setAccessToken($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' => $tokenType,
  7270.                     'token' => $token,
  7271.                 ];
  7272.             }
  7273.         }
  7274.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  7275.             $isApplicantExist $applicantRepo->findOneBy([
  7276.                 'email' => $oAuthData['email']
  7277.             ]);
  7278.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  7279.                 $isApplicantExist $applicantRepo->findOneBy([
  7280.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  7281.                 ]);
  7282.             }
  7283.             if (!$isApplicantExist) {
  7284.                 $usersQueried $em->getRepository(EntityApplicantDetails::class)->createQueryBuilder('A')
  7285.                     ->where("1=1 and (A.email like '%," $oAuthData['email'] . "' or A.email like '" $oAuthData['email'] . ",%'
  7286.                                      or A.email like '%," $oAuthData['email'] . ",%' or A.email like '" $oAuthData['email'] . "' ) ")
  7287.                     ->getQuery()
  7288.                     ->getResult();
  7289.                 if (!empty($usersQueried))
  7290.                     $isApplicantExist $usersQueried[0];
  7291.             }
  7292.             if ($isApplicantExist) {
  7293.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7294.                 } else
  7295.                     return $this->redirectToRoute("core_login", [
  7296.                         'id' => $isApplicantExist->getApplicantId(),
  7297.                         'oAuthData' => $oAuthData,
  7298.                         'encData' => $encData,
  7299.                         'locale' => $request->request->get('locale''en'),
  7300.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7301.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7302.                     ]);
  7303.             } else {
  7304.                 $fname $oAuthData['firstName'];
  7305.                 $lname $oAuthData['lastName'];
  7306.                 $img $oAuthData['image'];
  7307.                 $email $oAuthData['email'];
  7308.                 $oAuthEmail $oAuthData['email'];
  7309.                 $userName explode('@'$email)[0];
  7310.                 //now check if same username exists
  7311.                 $username_already_exist 1;
  7312.                 $initial_user_name $userName;
  7313.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  7314.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  7315.                     $isUsernameExist $applicantRepo->findOneBy([
  7316.                         'username' => $userName
  7317.                     ]);
  7318.                     if ($isUsernameExist) {
  7319.                         $username_already_exist 1;
  7320.                         $userName $initial_user_name '' rand(3009987);
  7321.                     } else {
  7322.                         $username_already_exist 0;
  7323.                     }
  7324.                     $timeoutSafeCount--;
  7325.                 }
  7326.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  7327.                     $currentUnixTimeStamp '';
  7328.                     $currentUnixTime = new \DateTime();
  7329.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  7330.                     $userName $userName '' $currentUnixTimeStamp;
  7331.                 }
  7332.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  7333.                 $charactersLength strlen($characters);
  7334.                 $length 8;
  7335.                 $password 0;
  7336.                 for ($i 0$i $length$i++) {
  7337.                     $password .= $characters[rand(0$charactersLength 1)];
  7338.                 }
  7339.                 $newApplicant = new EntityApplicantDetails();
  7340.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  7341.                 $newApplicant->setEmail($email);
  7342.                 $newApplicant->setUserName($userName);
  7343.                 $newApplicant->setFirstname($fname);
  7344.                 $newApplicant->setLastname($lname);
  7345.                 $newApplicant->setOAuthEmail($oAuthEmail);
  7346.                 $newApplicant->setIsEmailVerified(isset($oAuthData['emailVerified']) ? ($oAuthData['emailVerified'] != '' 0) : 0);
  7347.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  7348.                 $newApplicant->setAccountStatus(1);
  7349.                 $salt uniqid(mt_rand());
  7350.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  7351.                 $newApplicant->setPassword($encodedPassword);
  7352.                 $newApplicant->setSalt($salt);
  7353.                 $newApplicant->setTempPassword($password);;
  7354. //                $newApplicant->setPassword($password);
  7355.                 $marker $userName '-' time();
  7356. //                $extension_here=$uploadedFile->guessExtension();
  7357. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  7358. //                $path = $fileName;
  7359.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  7360.                 if (!file_exists($upl_dir)) {
  7361.                     mkdir($upl_dir0777true);
  7362.                 }
  7363.                 $ch curl_init($img);
  7364.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  7365.                 curl_setopt($chCURLOPT_FILE$fp);
  7366.                 curl_setopt($chCURLOPT_HEADER0);
  7367.                 curl_exec($ch);
  7368.                 curl_close($ch);
  7369.                 fclose($fp);
  7370.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  7371. //                $newApplicant->setImage($img);
  7372.                 $newApplicant->setIsConsultant(0);
  7373.                 $newApplicant->setIsTemporaryEntry(0);
  7374.                 $newApplicant->setApplyForConsultant(0);
  7375.                 $em->persist($newApplicant);
  7376.                 $em->flush();
  7377.                 $isApplicantExist $newApplicant;
  7378.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  7379.                     if ($systemType == '_BUDDYBEE_') {
  7380.                         $bodyHtml '';
  7381.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  7382.                         $bodyData = array(
  7383.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7384.                             'email' => $userName,
  7385.                             'password' => $newApplicant->getPassword(),
  7386.                         );
  7387.                         $attachments = [];
  7388.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7389. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7390.                         $new_mail $this->get('mail_module');
  7391.                         $new_mail->sendMyMail(array(
  7392.                             'senderHash' => '_CUSTOM_',
  7393.                             //                        'senderHash'=>'_CUSTOM_',
  7394.                             'forwardToMailAddress' => $forwardToMailAddress,
  7395.                             'subject' => 'Welcome to BuddyBee ',
  7396. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7397.                             'attachments' => $attachments,
  7398.                             'toAddress' => $forwardToMailAddress,
  7399.                             'fromAddress' => 'registration@buddybee.eu',
  7400.                             'userName' => 'registration@buddybee.eu',
  7401.                             'password' => 'Y41dh8g0112',
  7402.                             'smtpServer' => 'smtp.hostinger.com',
  7403.                             'smtpPort' => 465,
  7404.                             'encryptionMethod' => 'ssl',
  7405. //                            'emailBody' => $bodyHtml,
  7406.                             'mailTemplate' => $bodyTemplate,
  7407.                             'templateData' => $bodyData,
  7408. //                        'embedCompanyImage' => 1,
  7409. //                        'companyId' => $companyId,
  7410. //                        'companyImagePath' => $company_data->getImage()
  7411.                         ));
  7412.                     } else {
  7413.                         $bodyHtml '';
  7414.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  7415.                         $bodyData = array(
  7416.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  7417.                             'email' => 'APP-' $userName,
  7418.                             'password' => $newApplicant->getPassword(),
  7419.                         );
  7420.                         $attachments = [];
  7421.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  7422. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  7423.                         $new_mail $this->get('mail_module');
  7424.                         $new_mail->sendMyMail(array(
  7425.                             'senderHash' => '_CUSTOM_',
  7426.                             //                        'senderHash'=>'_CUSTOM_',
  7427.                             'forwardToMailAddress' => $forwardToMailAddress,
  7428.                             'subject' => 'Applicant Registration on Honeybee',
  7429. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  7430.                             'attachments' => $attachments,
  7431.                             'toAddress' => $forwardToMailAddress,
  7432.                             'fromAddress' => 'accounts@ourhoneybee.eu',
  7433.                             'userName' => 'accounts@ourhoneybee.eu',
  7434.                             'password' => 'Honeybee@0112',
  7435.                             'smtpServer' => 'smtp.hostinger.com',
  7436.                             'smtpPort' => 465,
  7437.                             'encryptionMethod' => 'ssl',
  7438. //                            'emailBody' => $bodyHtml,
  7439.                             'mailTemplate' => $bodyTemplate,
  7440.                             'templateData' => $bodyData,
  7441. //                        'embedCompanyImage' => 1,
  7442. //                        'companyId' => $companyId,
  7443. //                        'companyImagePath' => $company_data->getImage()
  7444.                         ));
  7445.                     }
  7446.                 }
  7447.                 if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7448.                 } else {
  7449.                     return $this->redirectToRoute("core_login", [
  7450.                         'id' => $newApplicant->getApplicantId(),
  7451.                         'oAuthData' => $oAuthData,
  7452.                         'encData' => $encData,
  7453.                         'remoteVerify' => $request->request->get('remoteVerify'0),
  7454.                         'locale' => $request->request->get('locale''en'),
  7455.                         'firebaseToken' => $request->request->get('firebaseToken'''),
  7456.                     ]);
  7457.                 }
  7458.             }
  7459.         }
  7460.         if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'$remoteVerify)) == 1) {
  7461.             if ($isApplicantExist) {
  7462.                 $user $isApplicantExist;
  7463.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7464.                 $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  7465.                 $globalId $user->getApplicantId();
  7466.                 $gocList $em
  7467.                     ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  7468.                     ->findBy(
  7469.                         array(//                        'active' => 1
  7470.                         )
  7471.                     );
  7472.                 $gocDataList = [];
  7473.                 $gocDataListForLoginWeb = [];
  7474.                 $gocDataListByAppId = [];
  7475.                 foreach ($gocList as $entry) {
  7476.                     $d = array(
  7477.                         'name' => $entry->getName(),
  7478.                         'image' => $entry->getImage(),
  7479.                         'id' => $entry->getId(),
  7480.                         'appId' => $entry->getAppId(),
  7481.                         'skipInWebFlag' => $entry->getSkipInWebFlag(),
  7482.                         'skipInAppFlag' => $entry->getSkipInAppFlag(),
  7483.                         'dbName' => $entry->getDbName(),
  7484.                         'dbUser' => $entry->getDbUser(),
  7485.                         'dbPass' => $entry->getDbPass(),
  7486.                         'dbHost' => $entry->getDbHost(),
  7487.                         'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  7488.                         'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  7489.                         'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  7490.                         'companyRemaining' => $entry->getCompanyRemaining(),
  7491.                         'companyAllowed' => $entry->getCompanyAllowed(),
  7492.                     );
  7493.                     $gocDataList[$entry->getId()] = $d;
  7494.                     if (in_array($entry->getSkipInWebFlag(), [0null]))
  7495.                         $gocDataListForLoginWeb[$entry->getId()] = $d;
  7496.                     $gocDataListByAppId[$entry->getAppId()] = $d;
  7497.                 }
  7498.                 if ($userTypesByAppIds == null$userTypesByAppIds = [];
  7499.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  7500.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  7501.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TSstrval($user->getLastSettingsUpdatedTs()));
  7502.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  7503.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  7504.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  7505.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  7506.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  7507.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  7508.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  7509.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  7510.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  7511.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  7512.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  7513.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  7514.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  7515.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  7516.                     $session->set(UserConstants::USER_COMPANY_ID1);
  7517.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  7518.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  7519.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7520.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  7521.                     $session->set('userCompanyVibrantList'json_encode([]));
  7522.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  7523.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  7524.                     $session->set(UserConstants::USER_APP_ID0);
  7525.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  7526.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  7527.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  7528.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  7529.                     $session->set(UserConstants::USER_GOC_ID0);
  7530.                     $session->set(UserConstants::USER_DB_NAME'');
  7531.                     $session->set(UserConstants::USER_DB_USER'');
  7532.                     $session->set(UserConstants::USER_DB_PASS'');
  7533.                     $session->set(UserConstants::USER_DB_HOST'');
  7534.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  7535.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  7536.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  7537.                     $session->set('oAuthToken'$request->request->get('oAuthToken'''));
  7538.                     $session->set('locale'$request->request->get('locale'''));
  7539.                     $session->set('firebaseToken'$request->request->get('firebaseToken'''));
  7540.                     $route_list_array = [];
  7541.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  7542.                     $loginID 0;
  7543.                     $loginID MiscActions::addEntityUserLoginLog(
  7544.                         $em,
  7545.                         $session->get(UserConstants::USER_ID),
  7546.                         $session->get(UserConstants::USER_ID),
  7547.                         1,
  7548.                         $request->server->get("REMOTE_ADDR"),
  7549.                         0,
  7550.                         $request->request->get('deviceId'''),
  7551.                         $request->request->get('oAuthToken'''),
  7552.                         $request->request->get('oAuthType'''),
  7553.                         $request->request->get('locale'''),
  7554.                         $request->request->get('firebaseToken''')
  7555.                     );
  7556.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  7557.                     $session_data = array(
  7558.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  7559.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  7560.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  7561.                         'oAuthToken' => $session->get('oAuthToken'),
  7562.                         'locale' => $session->get('locale'),
  7563.                         'firebaseToken' => $session->get('firebaseToken'),
  7564.                         'token' => $session->get('token'),
  7565.                         'firstLogin' => 0,
  7566.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  7567.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  7568.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  7569.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  7570.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  7571.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  7572.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  7573.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  7574.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  7575.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  7576.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  7577.                         'oAuthImage' => $session->get('oAuthImage'),
  7578.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  7579.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  7580.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  7581.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  7582.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  7583.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  7584.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  7585.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  7586.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  7587.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  7588.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  7589.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  7590.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  7591.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  7592.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  7593.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  7594.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  7595.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  7596.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  7597.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  7598.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  7599.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  7600.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  7601.                         //new
  7602.                         'appIdList' => $session->get('appIdList'),
  7603.                         'branchIdList' => $session->get('branchIdList'null),
  7604.                         'branchId' => $session->get('branchId'null),
  7605.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  7606.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  7607.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  7608.                     );
  7609.                     $accessList = [];
  7610. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  7611.                     foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  7612.                         foreach ($thisUserUserTypes as $thisUserUserType) {
  7613.                             if (isset($gocDataListByAppId[$thisUserAppId])) {
  7614.                                 $userTypeName = isset(UserConstants::$userTypeName[$thisUserUserType]) ? UserConstants::$userTypeName[$thisUserUserType] : 'Unknown';
  7615.                                 $d = array(
  7616.                                     'userType' => $thisUserUserType,
  7617. //                                        'userTypeName' => UserConstants::$userTypeName[$thisUserUserType],
  7618.                                     'userTypeName' => $userTypeName,
  7619.                                     'globalId' => $globalId,
  7620.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  7621.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  7622.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  7623.                                     'systemType' => '_ERP_',
  7624.                                     'companyId' => 1,
  7625.                                     'appId' => $thisUserAppId,
  7626.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  7627.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  7628.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  7629.                                             array(
  7630.                                                 'globalId' => $globalId,
  7631.                                                 'appId' => $thisUserAppId,
  7632.                                                 'authenticate' => 1,
  7633.                                                 'userType' => $thisUserUserType,
  7634.                                                 'userTypeName' => $userTypeName
  7635.                                             )
  7636.                                         )
  7637.                                     ),
  7638.                                     'userCompanyList' => [
  7639.                                     ]
  7640.                                 );
  7641.                                 $accessList[] = $d;
  7642.                             }
  7643.                         }
  7644.                     }
  7645.                     $session_data['userAccessList'] = $accessList;
  7646.                     $session->set('userAccessList'json_encode($accessList));
  7647.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  7648.                     $session_data $tokenData['sessionData'];
  7649.                     $token $tokenData['token'];
  7650.                     $session->set('token'$token);
  7651.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  7652.                         $session->set('remoteVerified'1);
  7653.                         $response = new JsonResponse(array(
  7654.                             'token' => $token,
  7655.                             'uid' => $session->get(UserConstants::USER_ID),
  7656.                             'session' => $session,
  7657.                             'success' => true,
  7658.                             'session_data' => $session_data,
  7659.                         ));
  7660.                         $response->headers->set('Access-Control-Allow-Origin''*');
  7661.                         return $response;
  7662.                     }
  7663.                     if ($request->request->has('referer_path')) {
  7664.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  7665.                             return $this->redirect($request->request->get('referer_path'));
  7666.                         }
  7667.                     }
  7668.                     $redirectRoute 'applicant_dashboard';
  7669.                     if ($request->query->has('encData')) {
  7670.                         if ($request->query->get('encData') == '8917922')
  7671.                             $redirectRoute 'apply_for_consultant';
  7672.                     }
  7673.                     return $this->redirectToRoute($redirectRoute);
  7674.                 }
  7675. //                    $response = new JsonResponse(array(
  7676. //                        'token' => $token,
  7677. //                        'uid' => $session->get(UserConstants::USER_ID),
  7678. //                        'session' => $session,
  7679. //
  7680. //                        'success' => true,
  7681. //                        'session_data' => $session_data,
  7682. //
  7683. //                    ));
  7684. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  7685. //                    return $response;
  7686. //                    return $this->redirectToRoute("user_login", [
  7687. //                        'id' => $isApplicantExist->getApplicantId(),
  7688. //                        'oAuthData' => $oAuthData,
  7689. //                        'encData' => $encData,
  7690. //                        'locale' => $request->request->get('locale', 'en'),
  7691. //                        'remoteVerify' => $request->request->get('remoteVerify', 0),
  7692. //                        'firebaseToken' => $request->request->get('firebaseToken', ''),
  7693. //                    ]);
  7694.             }
  7695.         }
  7696.         $selector BuddybeeConstant::$selector;
  7697.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7698.         $twig_file '@Authentication/pages/views/applicant_login.html.twig';
  7699.         if ($systemType == '_ERP_') {
  7700.         } else if ($systemType == '_SOPHIA_') {
  7701.             return $this->render(
  7702.                 '@Sophia/pages/views/sofia_login.html.twig',
  7703.                 [
  7704.                     'page_title' => 'Sophia Login',
  7705.                     'oAuthLink' => $google_client->createAuthUrl(),
  7706.                     'redirect_url' => $url,
  7707.                     'message' => $message,
  7708.                     'systemType' => $systemType,
  7709.                     'ownServerId' => $ownServerId,
  7710.                     'errorField' => '',
  7711.                     'encData' => $encData,
  7712.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7713.                     'selector' => $selector,
  7714.                 ]
  7715.             );
  7716.         } else if ($systemType == '_CENTRAL_') {
  7717.             return $this->render(
  7718.                 '@Authentication/pages/views/central_login.html.twig',
  7719.                 [
  7720.                     'page_title' => 'Central Login',
  7721.                     'oAuthLink' => $google_client->createAuthUrl(),
  7722.                     'redirect_url' => $url,
  7723.                     'message' => $message,
  7724.                     'systemType' => $systemType,
  7725.                     'ownServerId' => $ownServerId,
  7726.                     'errorField' => '',
  7727.                     'encData' => $encData,
  7728.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7729.                     'selector' => $selector,
  7730.                 ]
  7731.             );
  7732.         } else if ($systemType == '_BUDDYBEE_') {
  7733.             return $this->render(
  7734.                 '@Authentication/pages/views/applicant_login.html.twig',
  7735.                 [
  7736.                     'page_title' => 'BuddyBee Login',
  7737.                     'oAuthLink' => $google_client->createAuthUrl(),
  7738.                     'redirect_url' => $url,
  7739.                     'message' => $message,
  7740.                     'errorField' => $errorField,
  7741.                     'encData' => $encData,
  7742.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  7743.                     'selector' => $selector
  7744.                 ]
  7745.             );
  7746.         }
  7747.         return $this->render(
  7748.             '@Authentication/pages/views/applicant_login.html.twig',
  7749.             [
  7750.                 'page_title' => 'Applicant Registration',
  7751.                 'oAuthLink' => $google_client->createAuthUrl(),
  7752.                 'redirect_url' => $url,
  7753.                 'encData' => $encData,
  7754.                 'message' => $message,
  7755.                 'errorField' => $errorField,
  7756.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  7757.                 'selector' => $selector
  7758.             ]
  7759.         );
  7760.     }
  7761.     public function FindAccountAction(Request $request$encData ''$remoteVerify 0)
  7762.     {
  7763. //        $userCategory=$request->request->has('userCategory');
  7764.         $encryptedData = [];
  7765.         $errorField '';
  7766.         $message '';
  7767.         $userType '';
  7768.         $otpExpireSecond 180;
  7769.         $otpExpireTs 0;
  7770.         $otp '';
  7771.         if ($encData != '')
  7772.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  7773. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  7774.         $userCategory '_BUDDYBEE_USER_';
  7775.         if (isset($encryptedData['userCategory']))
  7776.             $userCategory $encryptedData['userCategory'];
  7777.         else
  7778.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  7779.         $em $this->getDoctrine()->getManager('company_group');
  7780.         $em_goc $this->getDoctrine()->getManager('company_group');
  7781.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  7782.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  7783.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  7784.         $twigData = [];
  7785.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  7786.         $email_address $request->request->get('email''');
  7787.         $email_twig_data = [];
  7788.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  7789.         if ($request->isMethod('POST')) {
  7790.             //set an otp and its expire and send mail
  7791.             $email_address $request->request->get('email');
  7792.             $userObj null;
  7793.             $userData = [];
  7794.             if ($systemType == '_ERP_') {
  7795.                 if ($userCategory == '_APPLICANT_') {
  7796.                     $userType UserConstants::USER_TYPE_APPLICANT;
  7797.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7798.                         array(
  7799.                             'email' => $email_address
  7800.                         )
  7801.                     );
  7802.                     if ($userObj) {
  7803.                     } else {
  7804.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7805.                             array(
  7806.                                 'oAuthEmail' => $email_address
  7807.                             )
  7808.                         );
  7809.                         if ($userObj) {
  7810.                         } else {
  7811.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7812.                                 array(
  7813.                                     'username' => $email_address
  7814.                                 )
  7815.                             );
  7816.                         }
  7817.                     }
  7818.                     if ($userObj) {
  7819.                         $email_address $userObj->getEmail();
  7820.                         if ($email_address == null || $email_address == '')
  7821.                             $email_address $userObj->getOAuthEmail();
  7822.                     }
  7823. //                    triggerResetPassword:
  7824. //                    type: integer
  7825. //                          nullable: true
  7826.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7827.                     $otp $otpData['otp'];
  7828.                     $otpExpireTs $otpData['expireTs'];
  7829.                     $userObj->setOtp($otpData['otp']);
  7830.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7831.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7832.                     $em_goc->flush();
  7833.                     $userData = array(
  7834.                         'id' => $userObj->getApplicantId(),
  7835.                         'email' => $email_address,
  7836.                         'appId' => 0,
  7837. //                        'appId'=>$userObj->getUserAppId(),
  7838.                     );
  7839.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7840.                     $email_twig_data = [
  7841.                         'page_title' => 'Find Account',
  7842.                         'encryptedData' => $encryptedData,
  7843.                         'message' => $message,
  7844.                         'userType' => $userType,
  7845.                         'errorField' => $errorField,
  7846.                         'otp' => $otpData['otp'],
  7847.                         'otpExpireSecond' => $otpExpireSecond,
  7848.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7849.                         'otpExpireTs' => $otpData['expireTs'],
  7850.                         'systemType' => $systemType,
  7851.                         'userData' => $userData
  7852.                     ];
  7853.                     if ($userObj)
  7854.                         $email_twig_data['success'] = true;
  7855.                 } else {
  7856.                     $userType UserConstants::USER_TYPE_GENERAL;
  7857.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7858.                     $email_twig_data = [
  7859.                         'page_title' => 'Find Account',
  7860.                         'encryptedData' => $encryptedData,
  7861.                         'message' => $message,
  7862.                         'userType' => $userType,
  7863.                         'errorField' => $errorField,
  7864.                     ];
  7865.                 }
  7866.             } else if ($systemType == '_CENTRAL_') {
  7867.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7868.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7869.                     array(
  7870.                         'email' => $email_address
  7871.                     )
  7872.                 );
  7873.                 if ($userObj) {
  7874.                 } else {
  7875.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7876.                         array(
  7877.                             'oAuthEmail' => $email_address
  7878.                         )
  7879.                     );
  7880.                     if ($userObj) {
  7881.                     } else {
  7882.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7883.                             array(
  7884.                                 'username' => $email_address
  7885.                             )
  7886.                         );
  7887.                     }
  7888.                 }
  7889.                 if ($userObj) {
  7890.                     $email_address $userObj->getEmail();
  7891.                     if ($email_address == null || $email_address == '')
  7892.                         $email_address $userObj->getOAuthEmail();
  7893.                     //                    triggerResetPassword:
  7894. //                    type: integer
  7895. //                          nullable: true
  7896.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7897.                     $otp $otpData['otp'];
  7898.                     $otpExpireTs $otpData['expireTs'];
  7899.                     $userObj->setOtp($otpData['otp']);
  7900.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7901.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7902.                     $em_goc->flush();
  7903.                     $userData = array(
  7904.                         'id' => $userObj->getApplicantId(),
  7905.                         'email' => $email_address,
  7906.                         'appId' => 0,
  7907.                         'image' => $userObj->getImage(),
  7908.                         'firstName' => $userObj->getFirstname(),
  7909.                         'lastName' => $userObj->getLastname(),
  7910.                         'phone' => $userObj->getPhone(),
  7911. //                        'appId'=>$userObj->getUserAppId(),
  7912.                     );
  7913.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7914.                     $email_twig_data = [
  7915.                         'page_title' => 'Find Account',
  7916.                         'encryptedData' => $encryptedData,
  7917.                         'message' => $message,
  7918.                         'userType' => $userType,
  7919.                         'errorField' => $errorField,
  7920.                         'otp' => $otpData['otp'],
  7921.                         'otpExpireSecond' => $otpExpireSecond,
  7922.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7923.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  7924.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  7925.                         'otpExpireTs' => $otpData['expireTs'],
  7926.                         'systemType' => $systemType,
  7927.                         'userCategory' => $userCategory,
  7928.                         'userData' => $userData
  7929.                     ];
  7930.                     $email_twig_data['success'] = true;
  7931.                 } else {
  7932.                     $message "Oops! Could not find your account";
  7933.                     $email_twig_data['success'] = false;
  7934.                 }
  7935.             } else if ($systemType == '_BUDDYBEE_') {
  7936.                 $userType UserConstants::USER_TYPE_APPLICANT;
  7937.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7938.                     array(
  7939.                         'email' => $email_address
  7940.                     )
  7941.                 );
  7942.                 if ($userObj) {
  7943.                 } else {
  7944.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7945.                         array(
  7946.                             'oAuthEmail' => $email_address
  7947.                         )
  7948.                     );
  7949.                     if ($userObj) {
  7950.                     } else {
  7951.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  7952.                             array(
  7953.                                 'username' => $email_address
  7954.                             )
  7955.                         );
  7956.                     }
  7957.                 }
  7958.                 if ($userObj) {
  7959.                     $email_address $userObj->getEmail();
  7960.                     if ($email_address == null || $email_address == '')
  7961.                         $email_address $userObj->getOAuthEmail();
  7962.                     //                    triggerResetPassword:
  7963. //                    type: integer
  7964. //                          nullable: true
  7965.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  7966.                     $otp $otpData['otp'];
  7967.                     $otpExpireTs $otpData['expireTs'];
  7968.                     $userObj->setOtp($otpData['otp']);
  7969.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  7970.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  7971.                     $em_goc->flush();
  7972.                     $userData = array(
  7973.                         'id' => $userObj->getApplicantId(),
  7974.                         'email' => $email_address,
  7975.                         'appId' => 0,
  7976.                         'image' => $userObj->getImage(),
  7977.                         'firstName' => $userObj->getFirstname(),
  7978.                         'lastName' => $userObj->getLastname(),
  7979.                         'phone' => $userObj->getPhone(),
  7980. //                        'appId'=>$userObj->getUserAppId(),
  7981.                     );
  7982.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  7983.                     $email_twig_data = [
  7984.                         'page_title' => 'Find Account',
  7985.                         'encryptedData' => $encryptedData,
  7986.                         'message' => $message,
  7987.                         'userType' => $userType,
  7988.                         'errorField' => $errorField,
  7989.                         'otp' => $otpData['otp'],
  7990.                         'otpExpireSecond' => $otpExpireSecond,
  7991.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  7992.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  7993.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  7994.                         'otpExpireTs' => $otpData['expireTs'],
  7995.                         'systemType' => $systemType,
  7996.                         'userCategory' => $userCategory,
  7997.                         'userData' => $userData
  7998.                     ];
  7999.                     $email_twig_data['success'] = true;
  8000.                 } else {
  8001.                     $message "Oops! Could not find your account";
  8002.                     $email_twig_data['success'] = false;
  8003.                 }
  8004.             }
  8005.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8006.                 if ($systemType == '_BUDDYBEE_') {
  8007.                     $bodyHtml '';
  8008.                     $bodyTemplate $email_twig_file;
  8009.                     $bodyData $email_twig_data;
  8010.                     $attachments = [];
  8011.                     $forwardToMailAddress $email_address;
  8012. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8013.                     $new_mail $this->get('mail_module');
  8014.                     $new_mail->sendMyMail(array(
  8015.                         'senderHash' => '_CUSTOM_',
  8016.                         //                        'senderHash'=>'_CUSTOM_',
  8017.                         'forwardToMailAddress' => $forwardToMailAddress,
  8018.                         'subject' => 'Account Verification',
  8019. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8020.                         'attachments' => $attachments,
  8021.                         'toAddress' => $forwardToMailAddress,
  8022.                         'fromAddress' => 'no-reply@buddybee.eu',
  8023.                         'userName' => 'no-reply@buddybee.eu',
  8024.                         'password' => 'Honeybee@0112',
  8025.                         'smtpServer' => 'smtp.hostinger.com',
  8026.                         'smtpPort' => 465,
  8027. //                            'emailBody' => $bodyHtml,
  8028.                         'mailTemplate' => $bodyTemplate,
  8029.                         'templateData' => $bodyData,
  8030. //                        'embedCompanyImage' => 1,
  8031. //                        'companyId' => $companyId,
  8032. //                        'companyImagePath' => $company_data->getImage()
  8033.                     ));
  8034.                 } else if ($systemType == '_CENTRAL_') {
  8035.                     $bodyHtml '';
  8036.                     $bodyTemplate $email_twig_file;
  8037.                     $bodyData $email_twig_data;
  8038.                     $attachments = [];
  8039.                     $forwardToMailAddress $email_address;
  8040. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8041.                     $new_mail $this->get('mail_module');
  8042.                     $new_mail->sendMyMail(array(
  8043.                         'senderHash' => '_CUSTOM_',
  8044.                         //                        'senderHash'=>'_CUSTOM_',
  8045.                         'forwardToMailAddress' => $forwardToMailAddress,
  8046.                         'subject' => 'Account Verification',
  8047. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8048.                         'attachments' => $attachments,
  8049.                         'toAddress' => $forwardToMailAddress,
  8050.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8051.                         'userName' => 'accounts@ourhoneybee.eu',
  8052.                         'password' => 'Honeybee@0112',
  8053.                         'smtpServer' => 'smtp.hostinger.com',
  8054.                         'smtpPort' => 465,
  8055. //                            'emailBody' => $bodyHtml,
  8056.                         'mailTemplate' => $bodyTemplate,
  8057.                         'templateData' => $bodyData,
  8058. //                        'embedCompanyImage' => 1,
  8059. //                        'companyId' => $companyId,
  8060. //                        'companyImagePath' => $company_data->getImage()
  8061.                     ));
  8062.                 } else {
  8063.                     $bodyHtml '';
  8064.                     $bodyTemplate $email_twig_file;
  8065.                     $bodyData $email_twig_data;
  8066.                     $attachments = [];
  8067.                     $forwardToMailAddress $email_address;
  8068. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8069.                     $new_mail $this->get('mail_module');
  8070.                     $new_mail->sendMyMail(array(
  8071.                         'senderHash' => '_CUSTOM_',
  8072.                         //                        'senderHash'=>'_CUSTOM_',
  8073.                         'forwardToMailAddress' => $forwardToMailAddress,
  8074.                         'subject' => 'Applicant Registration on Honeybee',
  8075. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8076.                         'attachments' => $attachments,
  8077.                         'toAddress' => $forwardToMailAddress,
  8078.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8079.                         'userName' => 'accounts@ourhoneybee.eu',
  8080.                         'password' => 'Honeybee@0112',
  8081.                         'smtpServer' => 'smtp.hostinger.com',
  8082.                         'smtpPort' => 465,
  8083.                         'emailBody' => $bodyHtml,
  8084.                         'mailTemplate' => $bodyTemplate,
  8085.                         'templateData' => $bodyData,
  8086. //                        'embedCompanyImage' => 1,
  8087. //                        'companyId' => $companyId,
  8088. //                        'companyImagePath' => $company_data->getImage()
  8089.                     ));
  8090.                 }
  8091.             }
  8092.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8093.                 if ($systemType == '_BUDDYBEE_') {
  8094.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8095.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8096.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8097.                      _APPEND_CODE_';
  8098.                     $msg str_replace($searchVal$replaceVal$msg);
  8099.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8100.                     $sendType 'all';
  8101.                     $socketUserIds = [];
  8102.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8103.                 } else {
  8104.                 }
  8105.             }
  8106.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8107.                 $response = new JsonResponse(array(
  8108.                         'templateData' => $twigData,
  8109.                         'message' => $message,
  8110. //                        "otp"=>'',
  8111.                         "otp" => $otp,
  8112.                         "otpExpireTs" => $otpExpireTs,
  8113.                         'actionData' => $email_twig_data,
  8114.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8115.                     )
  8116.                 );
  8117.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8118.                 return $response;
  8119.             } else if ($email_twig_data['success'] == true) {
  8120.                 $encData = array(
  8121.                     "userType" => $userType,
  8122.                     "otp" => '',
  8123. //                "otp"=>$otp,
  8124.                     "otpExpireTs" => $otpExpireTs,
  8125.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8126.                     "userCategory" => $userCategory,
  8127.                     "userId" => $userData['id'],
  8128.                     "systemType" => $systemType,
  8129.                     "email" => $email_address,
  8130.                 );
  8131.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8132.                 $url $this->generateUrl(
  8133.                     'verify_otp'
  8134.                 );
  8135.                 return $this->redirect($url "/" $encDataStr);
  8136. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8137. ////                    'encData'
  8138. ////                'id' => $isApplicantExist->getApplicantId(),
  8139. ////                'oAuthData' => $oAuthData,
  8140. ////                'refRoute' => $refRoute,
  8141. //                ]);
  8142.             }
  8143.         }
  8144.         if ($systemType == '_ERP_') {
  8145.             if ($userCategory == '_APPLICANT_') {
  8146.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8147.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8148.                 $twigData = [
  8149.                     'page_title' => 'Find Account',
  8150.                     'encryptedData' => $encryptedData,
  8151.                     'message' => $message,
  8152.                     'systemType' => $systemType,
  8153.                     'ownServerId' => $ownServerId,
  8154.                     'userType' => $userType,
  8155.                     'errorField' => $errorField,
  8156.                 ];
  8157.             } else {
  8158.                 $userType UserConstants::USER_TYPE_GENERAL;
  8159.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8160.                 $twigData = [
  8161.                     'page_title' => 'Find Account',
  8162.                     'encryptedData' => $encryptedData,
  8163.                     'systemType' => $systemType,
  8164.                     'ownServerId' => $ownServerId,
  8165.                     'message' => $message,
  8166.                     'userType' => $userType,
  8167.                     'errorField' => $errorField,
  8168.                 ];
  8169.             }
  8170.         } else if ($systemType == '_CENTRAL_') {
  8171.             $userType UserConstants::USER_TYPE_APPLICANT;
  8172.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  8173.             $twigData = [
  8174.                 'page_title' => 'Find Account',
  8175.                 'encryptedData' => $encryptedData,
  8176.                 'systemType' => $systemType,
  8177.                 'ownServerId' => $ownServerId,
  8178.                 "otp" => '',
  8179. //                "otp"=>$otp,
  8180.                 "otpExpireTs" => $otpExpireTs,
  8181.                 'message' => $message,
  8182.                 'userType' => $userType,
  8183.                 'errorField' => $errorField,
  8184.             ];
  8185.         } else if ($systemType == '_BUDDYBEE_') {
  8186.             $userType UserConstants::USER_TYPE_APPLICANT;
  8187.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8188.             $twigData = [
  8189.                 'page_title' => 'Find Account',
  8190.                 'encryptedData' => $encryptedData,
  8191.                 "otp" => '',
  8192.                 'systemType' => $systemType,
  8193.                 'ownServerId' => $ownServerId,
  8194. //                "otp"=>$otp,
  8195.                 "otpExpireTs" => $otpExpireTs,
  8196.                 'message' => $message,
  8197.                 'userType' => $userType,
  8198.                 'errorField' => $errorField,
  8199.             ];
  8200.         }
  8201.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8202.             $response = new JsonResponse(array(
  8203.                     'templateData' => $twigData,
  8204.                     'message' => $message,
  8205.                     "otp" => '',
  8206. //                "otp"=>$otp,
  8207.                     "otpExpireTs" => $otpExpireTs,
  8208.                     'actionData' => $email_twig_data,
  8209.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8210.                 )
  8211.             );
  8212.             $response->headers->set('Access-Control-Allow-Origin''*');
  8213.             return $response;
  8214.         } else {
  8215.             return $this->render(
  8216.                 $twig_file,
  8217.                 $twigData
  8218.             );
  8219.         }
  8220.     }
  8221.     public function VerifyEmailForWebAction(Request $request$encData ''$remoteVerify 0)
  8222.     {
  8223. //        $userCategory=$request->request->has('userCategory');
  8224.         $encryptedData = [];
  8225.         $errorField '';
  8226.         $message '';
  8227.         $userType '';
  8228.         $otpExpireSecond 180;
  8229.         $otpExpireTs 0;
  8230.         $otp '';
  8231.         if ($encData != '')
  8232.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8233. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8234.         $userCategory '_BUDDYBEE_USER_';
  8235.         if (isset($encryptedData['userCategory']))
  8236.             $userCategory $encryptedData['userCategory'];
  8237.         else
  8238.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8239.         $em $this->getDoctrine()->getManager('company_group');
  8240.         $em_goc $this->getDoctrine()->getManager('company_group');
  8241.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8242.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8243.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8244.         $twigData = [];
  8245.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8246.         $email_address $request->request->get('email''');
  8247.         $email_twig_data = [];
  8248.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8249.         if ($request->isMethod('POST')) {
  8250.             //set an otp and its expire and send mail
  8251.             $email_address $request->request->get('email');
  8252.             $userObj null;
  8253.             $userData = [];
  8254.             if ($systemType == '_ERP_') {
  8255.                 if ($userCategory == '_APPLICANT_') {
  8256.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8257.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8258.                         array(
  8259.                             'email' => $email_address
  8260.                         )
  8261.                     );
  8262.                     if ($userObj) {
  8263.                     } else {
  8264.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8265.                             array(
  8266.                                 'oAuthEmail' => $email_address
  8267.                             )
  8268.                         );
  8269.                         if ($userObj) {
  8270.                         } else {
  8271.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8272.                                 array(
  8273.                                     'username' => $email_address
  8274.                                 )
  8275.                             );
  8276.                         }
  8277.                     }
  8278.                     if ($userObj) {
  8279.                         $email_address $userObj->getEmail();
  8280.                         if ($email_address == null || $email_address == '')
  8281.                             $email_address $userObj->getOAuthEmail();
  8282.                     }
  8283. //                    triggerResetPassword:
  8284. //                    type: integer
  8285. //                          nullable: true
  8286.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8287.                     $otp $otpData['otp'];
  8288.                     $otpExpireTs $otpData['expireTs'];
  8289.                     $userObj->setOtp($otpData['otp']);
  8290.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8291.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8292.                     $em_goc->flush();
  8293.                     $userData = array(
  8294.                         'id' => $userObj->getApplicantId(),
  8295.                         'email' => $email_address,
  8296.                         'appId' => 0,
  8297. //                        'appId'=>$userObj->getUserAppId(),
  8298.                     );
  8299.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8300.                     $email_twig_data = [
  8301.                         'page_title' => 'Find Account',
  8302.                         'encryptedData' => $encryptedData,
  8303.                         'message' => $message,
  8304.                         'userType' => $userType,
  8305.                         'errorField' => $errorField,
  8306.                         'otp' => $otpData['otp'],
  8307.                         'otpExpireSecond' => $otpExpireSecond,
  8308.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8309.                         'otpExpireTs' => $otpData['expireTs'],
  8310.                         'systemType' => $systemType,
  8311.                         'userData' => $userData
  8312.                     ];
  8313.                     if ($userObj)
  8314.                         $email_twig_data['success'] = true;
  8315.                 } else {
  8316.                     $userType UserConstants::USER_TYPE_GENERAL;
  8317.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8318.                     $email_twig_data = [
  8319.                         'page_title' => 'Find Account',
  8320.                         'encryptedData' => $encryptedData,
  8321.                         'message' => $message,
  8322.                         'userType' => $userType,
  8323.                         'errorField' => $errorField,
  8324.                     ];
  8325.                 }
  8326.             } else if ($systemType == '_CENTRAL_') {
  8327.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8328.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8329.                     array(
  8330.                         'email' => $email_address
  8331.                     )
  8332.                 );
  8333.                 if ($userObj) {
  8334.                 } else {
  8335.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8336.                         array(
  8337.                             'oAuthEmail' => $email_address
  8338.                         )
  8339.                     );
  8340.                     if ($userObj) {
  8341.                     } else {
  8342.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8343.                             array(
  8344.                                 'username' => $email_address
  8345.                             )
  8346.                         );
  8347.                     }
  8348.                 }
  8349.                 if ($userObj) {
  8350.                     $email_address $userObj->getEmail();
  8351.                     if ($email_address == null || $email_address == '')
  8352.                         $email_address $userObj->getOAuthEmail();
  8353.                     //                    triggerResetPassword:
  8354. //                    type: integer
  8355. //                          nullable: true
  8356.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8357.                     $otp $otpData['otp'];
  8358.                     $otpExpireTs $otpData['expireTs'];
  8359.                     $userObj->setOtp($otpData['otp']);
  8360.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_CONFIRM_EMAIL);
  8361.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8362.                     $em_goc->flush();
  8363.                     $userData = array(
  8364.                         'id' => $userObj->getApplicantId(),
  8365.                         'email' => $email_address,
  8366.                         'appId' => 0,
  8367.                         'image' => $userObj->getImage(),
  8368.                         'firstName' => $userObj->getFirstname(),
  8369.                         'lastName' => $userObj->getLastname(),
  8370.                         'phone' => $userObj->getPhone(),
  8371. //                        'appId'=>$userObj->getUserAppId(),
  8372.                     );
  8373.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8374.                     $email_twig_data = [
  8375.                         'page_title' => 'Find Account',
  8376.                         'encryptedData' => $encryptedData,
  8377.                         'message' => $message,
  8378.                         'userType' => $userType,
  8379.                         'errorField' => $errorField,
  8380.                         'otp' => $otpData['otp'],
  8381.                         'otpExpireSecond' => $otpExpireSecond,
  8382.                         'otpActionId' => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8383.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionTitle'],
  8384.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_CONFIRM_EMAIL]['actionDescForMail'],
  8385.                         'otpExpireTs' => $otpData['expireTs'],
  8386.                         'systemType' => $systemType,
  8387.                         'userCategory' => $userCategory,
  8388.                         'userData' => $userData
  8389.                     ];
  8390.                     $email_twig_data['success'] = true;
  8391.                 } else {
  8392.                     $message "Oops! Could not find your account";
  8393.                     $email_twig_data['success'] = false;
  8394.                 }
  8395.             } else if ($systemType == '_BUDDYBEE_') {
  8396.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8397.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8398.                     array(
  8399.                         'email' => $email_address
  8400.                     )
  8401.                 );
  8402.                 if ($userObj) {
  8403.                 } else {
  8404.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8405.                         array(
  8406.                             'oAuthEmail' => $email_address
  8407.                         )
  8408.                     );
  8409.                     if ($userObj) {
  8410.                     } else {
  8411.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8412.                             array(
  8413.                                 'username' => $email_address
  8414.                             )
  8415.                         );
  8416.                     }
  8417.                 }
  8418.                 if ($userObj) {
  8419.                     $email_address $userObj->getEmail();
  8420.                     if ($email_address == null || $email_address == '')
  8421.                         $email_address $userObj->getOAuthEmail();
  8422.                     //                    triggerResetPassword:
  8423. //                    type: integer
  8424. //                          nullable: true
  8425.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8426.                     $otp $otpData['otp'];
  8427.                     $otpExpireTs $otpData['expireTs'];
  8428.                     $userObj->setOtp($otpData['otp']);
  8429.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8430.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8431.                     $em_goc->flush();
  8432.                     $userData = array(
  8433.                         'id' => $userObj->getApplicantId(),
  8434.                         'email' => $email_address,
  8435.                         'appId' => 0,
  8436.                         'image' => $userObj->getImage(),
  8437.                         'firstName' => $userObj->getFirstname(),
  8438.                         'lastName' => $userObj->getLastname(),
  8439.                         'phone' => $userObj->getPhone(),
  8440. //                        'appId'=>$userObj->getUserAppId(),
  8441.                     );
  8442.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8443.                     $email_twig_data = [
  8444.                         'page_title' => 'Find Account',
  8445.                         'encryptedData' => $encryptedData,
  8446.                         'message' => $message,
  8447.                         'userType' => $userType,
  8448.                         'errorField' => $errorField,
  8449.                         'otp' => $otpData['otp'],
  8450.                         'otpExpireSecond' => $otpExpireSecond,
  8451.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8452.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8453.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8454.                         'otpExpireTs' => $otpData['expireTs'],
  8455.                         'systemType' => $systemType,
  8456.                         'userCategory' => $userCategory,
  8457.                         'userData' => $userData
  8458.                     ];
  8459.                     $email_twig_data['success'] = true;
  8460.                 } else {
  8461.                     $message "Oops! Could not find your account";
  8462.                     $email_twig_data['success'] = false;
  8463.                 }
  8464.             }
  8465.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8466.                 if ($systemType == '_BUDDYBEE_') {
  8467.                     $bodyHtml '';
  8468.                     $bodyTemplate $email_twig_file;
  8469.                     $bodyData $email_twig_data;
  8470.                     $attachments = [];
  8471.                     $forwardToMailAddress $email_address;
  8472. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8473.                     $new_mail $this->get('mail_module');
  8474.                     $new_mail->sendMyMail(array(
  8475.                         'senderHash' => '_CUSTOM_',
  8476.                         //                        'senderHash'=>'_CUSTOM_',
  8477.                         'forwardToMailAddress' => $forwardToMailAddress,
  8478.                         'subject' => 'Account Verification',
  8479. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8480.                         'attachments' => $attachments,
  8481.                         'toAddress' => $forwardToMailAddress,
  8482.                         'fromAddress' => 'no-reply@buddybee.eu',
  8483.                         'userName' => 'no-reply@buddybee.eu',
  8484.                         'password' => 'Honeybee@0112',
  8485.                         'smtpServer' => 'smtp.hostinger.com',
  8486.                         'smtpPort' => 465,
  8487. //                            'emailBody' => $bodyHtml,
  8488.                         'mailTemplate' => $bodyTemplate,
  8489.                         'templateData' => $bodyData,
  8490. //                        'embedCompanyImage' => 1,
  8491. //                        'companyId' => $companyId,
  8492. //                        'companyImagePath' => $company_data->getImage()
  8493.                     ));
  8494.                 } else if ($systemType == '_CENTRAL_') {
  8495.                     $bodyHtml '';
  8496.                     $bodyTemplate $email_twig_file;
  8497.                     $bodyData $email_twig_data;
  8498.                     $attachments = [];
  8499.                     $forwardToMailAddress $email_address;
  8500. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8501.                     $new_mail $this->get('mail_module');
  8502.                     $new_mail->sendMyMail(array(
  8503.                         'senderHash' => '_CUSTOM_',
  8504.                         //                        'senderHash'=>'_CUSTOM_',
  8505.                         'forwardToMailAddress' => $forwardToMailAddress,
  8506.                         'subject' => 'Account Verification',
  8507. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8508.                         'attachments' => $attachments,
  8509.                         'toAddress' => $forwardToMailAddress,
  8510.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8511.                         'userName' => 'accounts@ourhoneybee.eu',
  8512.                         'password' => 'Honeybee@0112',
  8513.                         'smtpServer' => 'smtp.hostinger.com',
  8514.                         'smtpPort' => 465,
  8515. //                            'emailBody' => $bodyHtml,
  8516.                         'mailTemplate' => $bodyTemplate,
  8517.                         'templateData' => $bodyData,
  8518. //                        'embedCompanyImage' => 1,
  8519. //                        'companyId' => $companyId,
  8520. //                        'companyImagePath' => $company_data->getImage()
  8521.                     ));
  8522.                 } else {
  8523.                     $bodyHtml '';
  8524.                     $bodyTemplate $email_twig_file;
  8525.                     $bodyData $email_twig_data;
  8526.                     $attachments = [];
  8527.                     $forwardToMailAddress $email_address;
  8528. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8529.                     $new_mail $this->get('mail_module');
  8530.                     $new_mail->sendMyMail(array(
  8531.                         'senderHash' => '_CUSTOM_',
  8532.                         //                        'senderHash'=>'_CUSTOM_',
  8533.                         'forwardToMailAddress' => $forwardToMailAddress,
  8534.                         'subject' => 'Applicant Registration on Honeybee',
  8535. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8536.                         'attachments' => $attachments,
  8537.                         'toAddress' => $forwardToMailAddress,
  8538.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8539.                         'userName' => 'accounts@ourhoneybee.eu',
  8540.                         'password' => 'Honeybee@0112',
  8541.                         'smtpServer' => 'smtp.hostinger.com',
  8542.                         'smtpPort' => 465,
  8543.                         'emailBody' => $bodyHtml,
  8544.                         'mailTemplate' => $bodyTemplate,
  8545.                         'templateData' => $bodyData,
  8546. //                        'embedCompanyImage' => 1,
  8547. //                        'companyId' => $companyId,
  8548. //                        'companyImagePath' => $company_data->getImage()
  8549.                     ));
  8550.                 }
  8551.             }
  8552.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8553.                 if ($systemType == '_BUDDYBEE_') {
  8554.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8555.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8556.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8557.                      _APPEND_CODE_';
  8558.                     $msg str_replace($searchVal$replaceVal$msg);
  8559.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8560.                     $sendType 'all';
  8561.                     $socketUserIds = [];
  8562.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8563.                 } else {
  8564.                 }
  8565.             }
  8566.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8567.                 $response = new JsonResponse(array(
  8568.                         'templateData' => $twigData,
  8569.                         'message' => $message,
  8570. //                        "otp"=>'',
  8571.                         "otp" => $otp,
  8572.                         "otpExpireTs" => $otpExpireTs,
  8573.                         'actionData' => $email_twig_data,
  8574.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8575.                     )
  8576.                 );
  8577.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8578.                 return $response;
  8579.             } else if ($email_twig_data['success'] == true) {
  8580.                 $encData = array(
  8581.                     "userType" => $userType,
  8582.                     "otp" => '',
  8583. //                "otp"=>$otp,
  8584.                     "otpExpireTs" => $otpExpireTs,
  8585.                     "otpActionId" => UserConstants::OTP_ACTION_CONFIRM_EMAIL,
  8586.                     "userCategory" => $userCategory,
  8587.                     "userId" => $userData['id'],
  8588.                     "systemType" => $systemType,
  8589.                     "email" => $email_address,
  8590.                 );
  8591.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8592.                 $url $this->generateUrl(
  8593.                     'verify_otp'
  8594.                 );
  8595.                 return $this->redirect($url "/" $encDataStr);
  8596. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8597. ////                    'encData'
  8598. ////                'id' => $isApplicantExist->getApplicantId(),
  8599. ////                'oAuthData' => $oAuthData,
  8600. ////                'refRoute' => $refRoute,
  8601. //                ]);
  8602.             }
  8603.         }
  8604.         if ($systemType == '_ERP_') {
  8605.             if ($userCategory == '_APPLICANT_') {
  8606.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8607.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8608.                 $twigData = [
  8609.                     'page_title' => 'Find Account',
  8610.                     'encryptedData' => $encryptedData,
  8611.                     'message' => $message,
  8612.                     'systemType' => $systemType,
  8613.                     'ownServerId' => $ownServerId,
  8614.                     'userType' => $userType,
  8615.                     'errorField' => $errorField,
  8616.                 ];
  8617.             } else {
  8618.                 $userType UserConstants::USER_TYPE_GENERAL;
  8619.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8620.                 $twigData = [
  8621.                     'page_title' => 'Find Account',
  8622.                     'encryptedData' => $encryptedData,
  8623.                     'systemType' => $systemType,
  8624.                     'ownServerId' => $ownServerId,
  8625.                     'message' => $message,
  8626.                     'userType' => $userType,
  8627.                     'errorField' => $errorField,
  8628.                 ];
  8629.             }
  8630.         } else if ($systemType == '_SOPHIA_') {
  8631.             $userType UserConstants::USER_TYPE_APPLICANT;
  8632.             $twig_file '@Sophia/pages/views/sophia_verify_email.html.twig';
  8633.             $twigData = [
  8634.                 'page_title' => 'Find Account',
  8635.                 'encryptedData' => $encryptedData,
  8636.                 'systemType' => $systemType,
  8637.                 'ownServerId' => $ownServerId,
  8638.                 "otp" => '',
  8639. //                "otp"=>$otp,
  8640.                 "otpExpireTs" => $otpExpireTs,
  8641.                 'message' => $message,
  8642.                 'userType' => $userType,
  8643.                 'errorField' => $errorField,
  8644.             ];
  8645.         } else if ($systemType == '_CENTRAL_') {
  8646.             $userType UserConstants::USER_TYPE_APPLICANT;
  8647.             $twig_file '@HoneybeeWeb/pages/verify_email.html.twig';
  8648.             $twigData = [
  8649.                 'page_title' => 'Find Account',
  8650.                 'encryptedData' => $encryptedData,
  8651.                 'systemType' => $systemType,
  8652.                 'ownServerId' => $ownServerId,
  8653.                 "otp" => '',
  8654. //                "otp"=>$otp,
  8655.                 "otpExpireTs" => $otpExpireTs,
  8656.                 'message' => $message,
  8657.                 'userType' => $userType,
  8658.                 'errorField' => $errorField,
  8659.             ];
  8660.         } else if ($systemType == '_BUDDYBEE_') {
  8661.             $userType UserConstants::USER_TYPE_APPLICANT;
  8662.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8663.             $twigData = [
  8664.                 'page_title' => 'Find Account',
  8665.                 'encryptedData' => $encryptedData,
  8666.                 "otp" => '',
  8667.                 'systemType' => $systemType,
  8668.                 'ownServerId' => $ownServerId,
  8669. //                "otp"=>$otp,
  8670.                 "otpExpireTs" => $otpExpireTs,
  8671.                 'message' => $message,
  8672.                 'userType' => $userType,
  8673.                 'errorField' => $errorField,
  8674.             ];
  8675.         }
  8676.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8677.             $response = new JsonResponse(array(
  8678.                     'templateData' => $twigData,
  8679.                     'message' => $message,
  8680.                     "otp" => '',
  8681. //                "otp"=>$otp,
  8682.                     "otpExpireTs" => $otpExpireTs,
  8683.                     'actionData' => $email_twig_data,
  8684.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8685.                 )
  8686.             );
  8687.             $response->headers->set('Access-Control-Allow-Origin''*');
  8688.             return $response;
  8689.         } else {
  8690.             return $this->render(
  8691.                 $twig_file,
  8692.                 $twigData
  8693.             );
  8694.         }
  8695.     }
  8696.     public function FindAccountForAppAction(Request $request$encData ''$remoteVerify 0)
  8697.     {
  8698. //        $userCategory=$request->request->has('userCategory');
  8699.         $encryptedData = [];
  8700.         $errorField '';
  8701.         $message '';
  8702.         $userType '';
  8703.         $otpExpireSecond 180;
  8704.         $otpExpireTs 0;
  8705.         $otp '';
  8706.         if ($encData != '')
  8707.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  8708. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  8709.         $userCategory '_BUDDYBEE_USER_';
  8710.         if (isset($encryptedData['userCategory']))
  8711.             $userCategory $encryptedData['userCategory'];
  8712.         else
  8713.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  8714.         $em $this->getDoctrine()->getManager('company_group');
  8715.         $em_goc $this->getDoctrine()->getManager('company_group');
  8716.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  8717.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  8718.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8719.         $twigData = [];
  8720.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  8721.         $email_address $request->request->get('email''');
  8722.         $email_twig_data = [];
  8723.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  8724.         if ($request->isMethod('POST')) {
  8725.             //set an otp and its expire and send mail
  8726.             $email_address $request->request->get('email');
  8727.             $userObj null;
  8728.             $userData = [];
  8729.             if ($systemType == '_ERP_') {
  8730.                 if ($userCategory == '_APPLICANT_') {
  8731.                     $userType UserConstants::USER_TYPE_APPLICANT;
  8732.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8733.                         array(
  8734.                             'email' => $email_address
  8735.                         )
  8736.                     );
  8737.                     if ($userObj) {
  8738.                     } else {
  8739.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8740.                             array(
  8741.                                 'oAuthEmail' => $email_address
  8742.                             )
  8743.                         );
  8744.                         if ($userObj) {
  8745.                         } else {
  8746.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8747.                                 array(
  8748.                                     'username' => $email_address
  8749.                                 )
  8750.                             );
  8751.                         }
  8752.                     }
  8753.                     if ($userObj) {
  8754.                         $email_address $userObj->getEmail();
  8755.                         if ($email_address == null || $email_address == '')
  8756.                             $email_address $userObj->getOAuthEmail();
  8757.                     }
  8758. //                    triggerResetPassword:
  8759. //                    type: integer
  8760. //                          nullable: true
  8761.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8762.                     $otp $otpData['otp'];
  8763.                     $otpExpireTs $otpData['expireTs'];
  8764.                     $userObj->setOtp($otpData['otp']);
  8765.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8766.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8767.                     $em_goc->flush();
  8768.                     $userData = array(
  8769.                         'id' => $userObj->getApplicantId(),
  8770.                         'email' => $email_address,
  8771.                         'appId' => 0,
  8772. //                        'appId'=>$userObj->getUserAppId(),
  8773.                     );
  8774.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8775.                     $email_twig_data = [
  8776.                         'page_title' => 'Find Account',
  8777.                         'encryptedData' => $encryptedData,
  8778.                         'message' => $message,
  8779.                         'userType' => $userType,
  8780.                         'errorField' => $errorField,
  8781.                         'otp' => $otpData['otp'],
  8782.                         'otpExpireSecond' => $otpExpireSecond,
  8783.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8784.                         'otpExpireTs' => $otpData['expireTs'],
  8785.                         'systemType' => $systemType,
  8786.                         'userData' => $userData
  8787.                     ];
  8788.                     if ($userObj)
  8789.                         $email_twig_data['success'] = true;
  8790.                 } else {
  8791.                     $userType UserConstants::USER_TYPE_GENERAL;
  8792.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8793.                     $email_twig_data = [
  8794.                         'page_title' => 'Find Account',
  8795.                         'encryptedData' => $encryptedData,
  8796.                         'message' => $message,
  8797.                         'userType' => $userType,
  8798.                         'errorField' => $errorField,
  8799.                     ];
  8800.                 }
  8801.             } else if ($systemType == '_CENTRAL_') {
  8802.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8803.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8804.                     array(
  8805.                         'email' => $email_address
  8806.                     )
  8807.                 );
  8808.                 if ($userObj) {
  8809.                 } else {
  8810.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8811.                         array(
  8812.                             'oAuthEmail' => $email_address
  8813.                         )
  8814.                     );
  8815.                     if ($userObj) {
  8816.                     } else {
  8817.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  8818.                             array(
  8819.                                 'username' => $email_address
  8820.                             )
  8821.                         );
  8822.                     }
  8823.                 }
  8824.                 if ($userObj) {
  8825.                     $email_address $userObj->getEmail();
  8826.                     if ($email_address == null || $email_address == '')
  8827.                         $email_address $userObj->getOAuthEmail();
  8828.                     //                    triggerResetPassword:
  8829. //                    type: integer
  8830. //                          nullable: true
  8831.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  8832.                     $otp $otpData['otp'];
  8833.                     $otpExpireTs $otpData['expireTs'];
  8834.                     $userObj->setOtp($otpData['otp']);
  8835.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  8836.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  8837.                     $em_goc->flush();
  8838.                     $userData = array(
  8839.                         'id' => $userObj->getApplicantId(),
  8840.                         'email' => $email_address,
  8841.                         'appId' => 0,
  8842.                         'image' => $userObj->getImage(),
  8843.                         'firstName' => $userObj->getFirstname(),
  8844.                         'lastName' => $userObj->getLastname(),
  8845.                         'phone' => $userObj->getPhone(),
  8846. //                        'appId'=>$userObj->getUserAppId(),
  8847.                     );
  8848.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  8849.                     $email_twig_data = [
  8850.                         'page_title' => 'Find Account',
  8851.                         'encryptedData' => $encryptedData,
  8852.                         'message' => $message,
  8853.                         'userType' => $userType,
  8854.                         'errorField' => $errorField,
  8855.                         'otp' => $otpData['otp'],
  8856.                         'otpExpireSecond' => $otpExpireSecond,
  8857.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8858.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  8859.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  8860.                         'otpExpireTs' => $otpData['expireTs'],
  8861.                         'systemType' => $systemType,
  8862.                         'userCategory' => $userCategory,
  8863.                         'userData' => $userData
  8864.                     ];
  8865.                     $email_twig_data['success'] = true;
  8866.                 } else {
  8867.                     $message "Oops! Could not find your account";
  8868.                     $email_twig_data['success'] = false;
  8869.                 }
  8870.             }
  8871.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  8872.                 if ($systemType == '_CENTRAL_') {
  8873.                     $bodyHtml '';
  8874.                     $bodyTemplate $email_twig_file;
  8875.                     $bodyData $email_twig_data;
  8876.                     $attachments = [];
  8877.                     $forwardToMailAddress $email_address;
  8878. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8879.                     $new_mail $this->get('mail_module');
  8880.                     $new_mail->sendMyMail(array(
  8881.                         'senderHash' => '_CUSTOM_',
  8882.                         //                        'senderHash'=>'_CUSTOM_',
  8883.                         'forwardToMailAddress' => $forwardToMailAddress,
  8884.                         'subject' => 'Account Verification',
  8885. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8886.                         'attachments' => $attachments,
  8887.                         'toAddress' => $forwardToMailAddress,
  8888.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8889.                         'userName' => 'accounts@ourhoneybee.eu',
  8890.                         'password' => 'Honeybee@0112',
  8891.                         'smtpServer' => 'smtp.hostinger.com',
  8892.                         'smtpPort' => 465,
  8893. //                            'emailBody' => $bodyHtml,
  8894.                         'mailTemplate' => $bodyTemplate,
  8895.                         'templateData' => $bodyData,
  8896. //                        'embedCompanyImage' => 1,
  8897. //                        'companyId' => $companyId,
  8898. //                        'companyImagePath' => $company_data->getImage()
  8899.                     ));
  8900.                 } else {
  8901.                     $bodyHtml '';
  8902.                     $bodyTemplate $email_twig_file;
  8903.                     $bodyData $email_twig_data;
  8904.                     $attachments = [];
  8905.                     $forwardToMailAddress $email_address;
  8906. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  8907.                     $new_mail $this->get('mail_module');
  8908.                     $new_mail->sendMyMail(array(
  8909.                         'senderHash' => '_CUSTOM_',
  8910.                         //                        'senderHash'=>'_CUSTOM_',
  8911.                         'forwardToMailAddress' => $forwardToMailAddress,
  8912.                         'subject' => 'Applicant Registration on Honeybee',
  8913. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  8914.                         'attachments' => $attachments,
  8915.                         'toAddress' => $forwardToMailAddress,
  8916.                         'fromAddress' => 'accounts@ourhoneybee.eu',
  8917.                         'userName' => 'accounts@ourhoneybee.eu',
  8918.                         'password' => 'Honeybee@0112',
  8919.                         'smtpServer' => 'smtp.hostinger.com',
  8920.                         'smtpPort' => 465,
  8921.                         'emailBody' => $bodyHtml,
  8922.                         'mailTemplate' => $bodyTemplate,
  8923.                         'templateData' => $bodyData,
  8924. //                        'embedCompanyImage' => 1,
  8925. //                        'companyId' => $companyId,
  8926. //                        'companyImagePath' => $company_data->getImage()
  8927.                     ));
  8928.                 }
  8929.             }
  8930.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  8931.                 if ($systemType == '_BUDDYBEE_') {
  8932.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  8933.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  8934.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  8935.                      _APPEND_CODE_';
  8936.                     $msg str_replace($searchVal$replaceVal$msg);
  8937.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  8938.                     $sendType 'all';
  8939.                     $socketUserIds = [];
  8940.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  8941.                 } else {
  8942.                 }
  8943.             }
  8944.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  8945.                 $response = new JsonResponse(array(
  8946.                         'templateData' => $twigData,
  8947.                         'message' => $message,
  8948. //                        "otp"=>'',
  8949.                         "otp" => $otp,
  8950.                         "otpExpireTs" => $otpExpireTs,
  8951.                         'actionData' => $email_twig_data,
  8952.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  8953.                     )
  8954.                 );
  8955.                 $response->headers->set('Access-Control-Allow-Origin''*');
  8956.                 return $response;
  8957.             } else if ($email_twig_data['success'] == true) {
  8958.                 $encData = array(
  8959.                     "userType" => $userType,
  8960.                     "otp" => '',
  8961. //                "otp"=>$otp,
  8962.                     "otpExpireTs" => $otpExpireTs,
  8963.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  8964.                     "userCategory" => $userCategory,
  8965.                     "userId" => $userData['id'],
  8966.                     "systemType" => $systemType,
  8967.                     "email" => $email_address,
  8968.                 );
  8969.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  8970.                 $url $this->generateUrl(
  8971.                     'verify_otp'
  8972.                 );
  8973.                 return $this->redirect($url "/" $encDataStr);
  8974. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  8975. ////                    'encData'
  8976. ////                'id' => $isApplicantExist->getApplicantId(),
  8977. ////                'oAuthData' => $oAuthData,
  8978. ////                'refRoute' => $refRoute,
  8979. //                ]);
  8980.             }
  8981.         }
  8982.         if ($systemType == '_ERP_') {
  8983.             if ($userCategory == '_APPLICANT_') {
  8984.                 $userType UserConstants::USER_TYPE_APPLICANT;
  8985.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8986.                 $twigData = [
  8987.                     'page_title' => 'Find Account',
  8988.                     'encryptedData' => $encryptedData,
  8989.                     'message' => $message,
  8990.                     'systemType' => $systemType,
  8991.                     'ownServerId' => $ownServerId,
  8992.                     'userType' => $userType,
  8993.                     'errorField' => $errorField,
  8994.                 ];
  8995.             } else {
  8996.                 $userType UserConstants::USER_TYPE_GENERAL;
  8997.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  8998.                 $twigData = [
  8999.                     'page_title' => 'Find Account',
  9000.                     'encryptedData' => $encryptedData,
  9001.                     'systemType' => $systemType,
  9002.                     'ownServerId' => $ownServerId,
  9003.                     'message' => $message,
  9004.                     'userType' => $userType,
  9005.                     'errorField' => $errorField,
  9006.                 ];
  9007.             }
  9008.         } else if ($systemType == '_CENTRAL_') {
  9009.             $userType UserConstants::USER_TYPE_APPLICANT;
  9010.             $twig_file '@HoneybeeWeb/pages/find_account.html.twig';
  9011.             $twigData = [
  9012.                 'page_title' => 'Find Account',
  9013.                 'encryptedData' => $encryptedData,
  9014.                 'systemType' => $systemType,
  9015.                 'ownServerId' => $ownServerId,
  9016.                 "otp" => '',
  9017. //                "otp"=>$otp,
  9018.                 "otpExpireTs" => $otpExpireTs,
  9019.                 'message' => $message,
  9020.                 'userType' => $userType,
  9021.                 'errorField' => $errorField,
  9022.             ];
  9023.         } else if ($systemType == '_BUDDYBEE_') {
  9024.             $userType UserConstants::USER_TYPE_APPLICANT;
  9025.             $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9026.             $twigData = [
  9027.                 'page_title' => 'Find Account',
  9028.                 'encryptedData' => $encryptedData,
  9029.                 "otp" => '',
  9030.                 'systemType' => $systemType,
  9031.                 'ownServerId' => $ownServerId,
  9032. //                "otp"=>$otp,
  9033.                 "otpExpireTs" => $otpExpireTs,
  9034.                 'message' => $message,
  9035.                 'userType' => $userType,
  9036.                 'errorField' => $errorField,
  9037.             ];
  9038.         }
  9039.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9040.             $response = new JsonResponse(array(
  9041.                     'templateData' => $twigData,
  9042.                     'message' => $message,
  9043.                     "otp" => '',
  9044. //                "otp"=>$otp,
  9045.                     "otpExpireTs" => $otpExpireTs,
  9046.                     'actionData' => $email_twig_data,
  9047.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9048.                 )
  9049.             );
  9050.             $response->headers->set('Access-Control-Allow-Origin''*');
  9051.             return $response;
  9052.         } else {
  9053.             return $this->render(
  9054.                 $twig_file,
  9055.                 $twigData
  9056.             );
  9057.         }
  9058.     }
  9059.     public function VerifyOtpAction(Request $request$encData ''$remoteVerify 0)
  9060.     {
  9061. //        $userCategory=$request->request->has('userCategory');
  9062.         $encryptedData = [];
  9063.         $errorField '';
  9064.         $message '';
  9065.         $userType '';
  9066.         $otpExpireSecond 180;
  9067.         $otpExpireTs 0;
  9068.         if ($encData != '')
  9069.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  9070. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  9071.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  9072.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  9073.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  9074.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  9075.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  9076.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  9077.         $em $this->getDoctrine()->getManager('company_group');
  9078.         $em_goc $this->getDoctrine()->getManager('company_group');
  9079.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  9080.         $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9081.         $twigData = [];
  9082.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  9083.         $email_twig_data = [];
  9084.         $userData = [];
  9085.         if ($request->isMethod('POST') || $otp != '') {
  9086.             $otp $request->request->get('otp'$otp);
  9087.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  9088.             $userId $request->request->get('userId'$userId);
  9089.             $userCategory $request->request->get('userCategory'$userCategory);
  9090.             $email_address $request->request->get('email'$email);
  9091.             if ($systemType == '_ERP_') {
  9092.                 if ($userCategory == '_APPLICANT_') {
  9093.                     $userType UserConstants::USER_TYPE_APPLICANT;
  9094.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9095.                         array(
  9096.                             'email' => $email_address
  9097.                         )
  9098.                     );
  9099.                     if ($userObj) {
  9100.                     } else {
  9101.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9102.                             array(
  9103.                                 'oAuthEmail' => $email_address
  9104.                             )
  9105.                         );
  9106.                         if ($userObj) {
  9107.                         } else {
  9108.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9109.                                 array(
  9110.                                     'userName' => $email_address
  9111.                                 )
  9112.                             );
  9113.                         }
  9114.                     }
  9115.                     if ($userObj) {
  9116.                         $email_address $userObj->getEmail();
  9117.                         if ($email_address == null || $email_address == '')
  9118.                             $email_address $userObj->getOAuthEmail();
  9119.                     }
  9120. //                    triggerResetPassword:
  9121. //                    type: integer
  9122. //                          nullable: true
  9123.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  9124.                     $userObj->setOtp($otpData['otp']);
  9125.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  9126.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  9127.                     $em_goc->flush();
  9128.                     $userData = array(
  9129.                         'id' => $userObj->getApplicantId(),
  9130.                         'email' => $email_address,
  9131.                         'appId' => 0,
  9132. //                        'appId'=>$userObj->getUserAppId(),
  9133.                     );
  9134.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9135.                     $email_twig_data = [
  9136.                         'page_title' => 'Find Account',
  9137.                         'encryptedData' => $encryptedData,
  9138.                         'message' => $message,
  9139.                         'userType' => $userType,
  9140.                         'errorField' => $errorField,
  9141.                         'otp' => $otpData['otp'],
  9142.                         'otpExpireSecond' => $otpExpireSecond,
  9143.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9144.                         'otpExpireTs' => $otpData['expireTs'],
  9145.                         'systemType' => $systemType,
  9146.                         'userData' => $userData
  9147.                     ];
  9148.                     if ($userObj)
  9149.                         $email_twig_data['success'] = true;
  9150.                 } else {
  9151.                     $userType UserConstants::USER_TYPE_GENERAL;
  9152.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  9153.                     $email_twig_data = [
  9154.                         'page_title' => 'Find Account',
  9155.                         'encryptedData' => $encryptedData,
  9156.                         'message' => $message,
  9157.                         'userType' => $userType,
  9158.                         'errorField' => $errorField,
  9159.                     ];
  9160.                 }
  9161.             } else if ($systemType == '_BUDDYBEE_') {
  9162.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9163.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  9164.                     array(
  9165.                         'applicantId' => $userId
  9166.                     )
  9167.                 );
  9168.                 if ($userObj) {
  9169.                     $userOtp $userObj->getOtp();
  9170.                     $userOtpActionId $userObj->getOtpActionId();
  9171.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  9172.                     $otpExpireTs $userObj->getOtpExpireTs();
  9173.                     $currentTime = new \DateTime();
  9174.                     $currentTimeTs $currentTime->format('U');
  9175.                     if ($userOtp != $otp) {
  9176.                         $message "Invalid OTP!";
  9177.                         $email_twig_data['success'] = false;
  9178.                     } else if ($userOtpActionId != $otpActionId) {
  9179.                         $message "Invalid OTP Action!";
  9180.                         $email_twig_data['success'] = false;
  9181.                     } else if ($currentTimeTs $userOtpExpireTs) {
  9182.                         $message "OTP Expired!";
  9183.                         $email_twig_data['success'] = false;
  9184.                     } else {
  9185.                         $userObj->setOtp(0);
  9186.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  9187.                         $userObj->setOtpExpireTs(0);
  9188.                         $userObj->setTriggerResetPassword(1);
  9189.                         $em_goc->flush();
  9190.                         $email_twig_data['success'] = true;
  9191.                         $message "";
  9192.                     }
  9193.                     $userData = array(
  9194.                         'id' => $userObj->getApplicantId(),
  9195.                         'email' => $email_address,
  9196.                         'appId' => 0,
  9197.                         'image' => $userObj->getImage(),
  9198.                         'firstName' => $userObj->getFirstname(),
  9199.                         'lastName' => $userObj->getLastname(),
  9200. //                        'appId'=>$userObj->getUserAppId(),
  9201.                     );
  9202.                     $email_twig_data['userData'] = $userData;
  9203.                 } else {
  9204.                     $message "Account not found!";
  9205.                     $email_twig_data['success'] = false;
  9206.                 }
  9207.             }
  9208.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9209.                 $response = new JsonResponse(array(
  9210.                         'templateData' => $twigData,
  9211.                         'message' => $message,
  9212.                         'actionData' => $email_twig_data,
  9213.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9214.                     )
  9215.                 );
  9216.                 $response->headers->set('Access-Control-Allow-Origin''*');
  9217.                 return $response;
  9218.             } else if ($email_twig_data['success'] == true) {
  9219.                 $encData = array(
  9220.                     "userType" => $userType,
  9221.                     "otp" => '',
  9222.                     "otpExpireTs" => $otpExpireTs,
  9223.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  9224.                     "userCategory" => $userCategory,
  9225.                     "userId" => $userData['id'],
  9226.                     "systemType" => $systemType,
  9227.                 );
  9228.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  9229.                 $url $this->generateUrl(
  9230.                     'reset_password_new_password'
  9231.                 );
  9232.                 return $this->redirect($url "/" $encDataStr);
  9233. //                return $this->redirectToRoute("reset_password_new_password", [
  9234. ////                'id' => $isApplicantExist->getApplicantId(),
  9235. ////                'oAuthData' => $oAuthData,
  9236. ////                'refRoute' => $refRoute,
  9237. //                ]);
  9238.             }
  9239.         }
  9240.         if ($systemType == '_ERP_') {
  9241.             if ($userCategory == '_APPLICANT_') {
  9242.                 $userType UserConstants::USER_TYPE_APPLICANT;
  9243.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9244.                 $twigData = [
  9245.                     'page_title' => 'Find Account',
  9246.                     'encryptedData' => $encryptedData,
  9247.                     'message' => $message,
  9248.                     'userType' => $userType,
  9249.                     'errorField' => $errorField,
  9250.                 ];
  9251.             } else {
  9252.                 $userType UserConstants::USER_TYPE_GENERAL;
  9253.                 $twig_file '@Authentication/pages/views/find_account_buddybee.html.twig';
  9254.                 $twigData = [
  9255.                     'page_title' => 'Find Account',
  9256.                     'encryptedData' => $encryptedData,
  9257.                     'message' => $message,
  9258.                     'userType' => $userType,
  9259.                     'errorField' => $errorField,
  9260.                 ];
  9261.             }
  9262.         } else if ($systemType == '_BUDDYBEE_') {
  9263.             $userType UserConstants::USER_TYPE_APPLICANT;
  9264.             $twig_file '@Authentication/pages/views/verify_otp_buddybee.html.twig';
  9265.             $twigData = [
  9266.                 'page_title' => 'Verify Otp',
  9267.                 'encryptedData' => $encryptedData,
  9268.                 'message' => $message,
  9269.                 'email' => $email,
  9270.                 "otp" => '',
  9271. //                "otp"=>$otp,
  9272.                 "otpExpireTs" => $otpExpireTs,
  9273.                 'userType' => $userType,
  9274.                 'userCategory' => $userCategory,
  9275.                 'errorField' => $errorField,
  9276.             ];
  9277.         }
  9278.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  9279.             $response = new JsonResponse(array(
  9280.                     'templateData' => $twigData,
  9281.                     'message' => $message,
  9282.                     'actionData' => $email_twig_data,
  9283.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  9284.                 )
  9285.             );
  9286.             $response->headers->set('Access-Control-Allow-Origin''*');
  9287.             return $response;
  9288.         } else {
  9289.             return $this->render(
  9290.                 $twig_file,
  9291.                 $twigData
  9292.             );
  9293.         }
  9294.     }
  9295. //    public function getCompanyByUser(Request $request){
  9296. //        $em = $this->getDoctrine()->getManager();
  9297. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  9298. //        $session = $request->getSession();
  9299. //        $userId = $session->get(UserConstants::USER_ID);
  9300. //        $applicantDetails = $em->getRepository("ApplicationBundle\\Entity\\SysUser")->createQueryBuilder('U')
  9301. //            ->select('U.userAppIdList')
  9302. //            ->where('U.userId = :userId')
  9303. //            ->setParameter('userId', $userId)
  9304. //            ->getQuery()
  9305. //            ->getResult();
  9306. //
  9307. //        $compnayDetails = $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")->createQueryBuilder('C')
  9308. //            ->select('C.name','C.appId')
  9309. //            ->getQuery()
  9310. //            ->getResult();
  9311. //
  9312. //        return new JsonResponse(
  9313. //            [
  9314. //                'applicantCompnayId' => $applicantDetails,
  9315. //                'copanyData' => $compnayDetails
  9316. //            ]
  9317. //        );
  9318.     public function getCompanyByUser(Request $request)
  9319.     {
  9320.         $em_goc $this->getDoctrine()->getManager('company_group');
  9321.         $em_goc->getConnection()->connect();
  9322.         $session $request->getSession();
  9323.         $appIds $session->get(UserConstants::USER_APP_ID_LIST);
  9324.         $userAppIdList json_decode($appIdstrue);
  9325.         if (!is_array($userAppIdList)) {
  9326.             return new JsonResponse([]);
  9327.         }
  9328.         $companyData $em_goc->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  9329.             ->createQueryBuilder('C')
  9330.             ->select('C.name, C.appId')
  9331.             ->where('C.appId IN (:appIds)')
  9332.             ->setParameter('appIds'$userAppIdList)
  9333.             ->getQuery()
  9334.             ->getResult();
  9335.         return new JsonResponse($companyData);
  9336.     }
  9337.     public function applicantList(Request $request)
  9338.     {
  9339.         $em_goc $this->getDoctrine()->getManager('company_group');
  9340.         $em_goc->getConnection()->connect();
  9341.         $applicantList $em_goc->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  9342.             ->createQueryBuilder('C')
  9343.             ->select('C.applicantId, C.firstname, C.lastname,C.email')
  9344.             ->getQuery()
  9345.             ->getResult();
  9346.         return new JsonResponse($applicantList);
  9347.     }
  9348.     public function getUserType()
  9349.     {
  9350.         $userType HumanResourceConstant::$userTypeForApp;
  9351.         return new JsonResponse($userType);
  9352.     }
  9353.     public function updatepasswordAction(Request $request)
  9354.     {
  9355.         $em_goc $this->getDoctrine()->getManager('company_group');
  9356.         $session $request->getSession();
  9357.         $userId $session->get(UserConstants::USER_ID);
  9358.         if ($request->isMethod('POST')) {
  9359.             $user $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->find($userId);
  9360.             $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($request->request->get('password'), $user->getSalt());
  9361.             $user->setPassword($encodedPassword);
  9362.             $em_goc->persist($user);
  9363.             $em_goc->flush();
  9364.             return new JsonResponse(['status' => 'success''message' => 'Password updated successfully.']);
  9365.         }
  9366.     }
  9367. }